3
0
mirror of https://github.com/Qortal/altcoinj.git synced 2025-01-31 15:22:16 +00:00

Payment channels: more logging.

This commit is contained in:
Mike Hearn 2013-09-16 11:39:38 +02:00
parent 26f2d13581
commit 81d76a76c3
3 changed files with 18 additions and 4 deletions

View File

@ -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;

View File

@ -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<Sha256Hash, StoredServerChannel> mapChannels = new HashMap<Sha256Hash, StoredServerChannel>();
@ -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();
}

View File

@ -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</p>
*/
public class ProtobufParser<MessageType extends MessageLite> 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 <MessageType> The protobuf type which is used on this socket.
@ -106,6 +110,7 @@ public class ProtobufParser<MessageType extends MessageLite> extends AbstractTim
@Override
protected void timeoutOccurred() {
log.warn("Timeout occurred for " + handler);
closeConnection();
}