diff --git a/core/src/main/java/com/google/bitcoin/protocols/channels/PaymentChannelServerState.java b/core/src/main/java/com/google/bitcoin/protocols/channels/PaymentChannelServerState.java index 68e01485..df1996e2 100644 --- a/core/src/main/java/com/google/bitcoin/protocols/channels/PaymentChannelServerState.java +++ b/core/src/main/java/com/google/bitcoin/protocols/channels/PaymentChannelServerState.java @@ -376,13 +376,16 @@ public class PaymentChannelServerState { closedFuture.set(this); return closedFuture; } - if (state != State.READY) // We are already closing/closed/in an error state + if (state != State.READY) { + log.warn("Failed attempt to close a channel in state " + state); return closedFuture; + } if (bestValueToMe.equals(BigInteger.ZERO)) { // TODO: This is bogus. We shouldn't allow the client to get into this state (where they open and close // a channel without sending us any money). We should either send an error at this point, or require // the submission of an initial zero-valued payment during the open phase. + log.warn("Closing channel that never received any payments."); state = State.CLOSED; closedFuture.set(this); return closedFuture; diff --git a/core/src/main/java/com/google/bitcoin/protocols/channels/StoredPaymentChannelServerStates.java b/core/src/main/java/com/google/bitcoin/protocols/channels/StoredPaymentChannelServerStates.java index 1184dfd6..7199ebaf 100644 --- a/core/src/main/java/com/google/bitcoin/protocols/channels/StoredPaymentChannelServerStates.java +++ b/core/src/main/java/com/google/bitcoin/protocols/channels/StoredPaymentChannelServerStates.java @@ -21,6 +21,7 @@ import com.google.bitcoin.utils.Threading; import com.google.common.annotations.VisibleForTesting; import com.google.protobuf.ByteString; import net.jcip.annotations.GuardedBy; +import org.slf4j.LoggerFactory; import java.math.BigInteger; import java.util.*; @@ -33,6 +34,8 @@ import static com.google.common.base.Preconditions.*; * unlock. */ public class StoredPaymentChannelServerStates implements WalletExtension { + private static final org.slf4j.Logger log = LoggerFactory.getLogger(StoredPaymentChannelServerStates.class); + static final String EXTENSION_ID = StoredPaymentChannelServerStates.class.getName(); @GuardedBy("lock") @VisibleForTesting final Map mapChannels = new HashMap(); @@ -115,14 +118,17 @@ public class StoredPaymentChannelServerStates implements WalletExtension { lock.lock(); try { checkArgument(mapChannels.put(channel.contract.getHash(), checkNotNull(channel)) == null); + // Add the difference between real time and Utils.now() so that test-cases can use a mock clock. + Date autocloseTime = new Date((channel.refundTransactionUnlockTimeSecs + CHANNEL_EXPIRE_OFFSET) * 1000L + + (System.currentTimeMillis() - Utils.now().getTime())); + log.info("Scheduling channel for automatic closure at {}: {}", autocloseTime, channel); channelTimeoutHandler.schedule(new TimerTask() { @Override public void run() { + log.info("Auto-closing channel: {}", channel); closeChannel(channel); } - // Add the difference between real time and Utils.now() so that test-cases can use a mock clock. - }, new Date((channel.refundTransactionUnlockTimeSecs + CHANNEL_EXPIRE_OFFSET)*1000L - + (System.currentTimeMillis() - Utils.now().getTime()))); + }, autocloseTime); } finally { lock.unlock(); } diff --git a/core/src/main/java/com/google/bitcoin/protocols/niowrapper/ProtobufParser.java b/core/src/main/java/com/google/bitcoin/protocols/niowrapper/ProtobufParser.java index 892bb4b9..fd500b59 100644 --- a/core/src/main/java/com/google/bitcoin/protocols/niowrapper/ProtobufParser.java +++ b/core/src/main/java/com/google/bitcoin/protocols/niowrapper/ProtobufParser.java @@ -19,6 +19,8 @@ package com.google.bitcoin.protocols.niowrapper; import com.google.bitcoin.core.Utils; import com.google.protobuf.ByteString; import com.google.protobuf.MessageLite; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.IOException; import java.nio.ByteBuffer; @@ -35,6 +37,8 @@ import static com.google.common.base.Preconditions.checkState; * serialized protobuf

*/ public class ProtobufParser extends AbstractTimeoutHandler implements StreamParser { + private static final Logger log = LoggerFactory.getLogger(ProtobufParser.class); + /** * An interface which can be implemented to handle callbacks as new messages are generated and socket events occur. * @param The protobuf type which is used on this socket. @@ -106,6 +110,7 @@ public class ProtobufParser extends AbstractTim @Override protected void timeoutOccurred() { + log.warn("Timeout occurred for " + handler); closeConnection(); }