mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2025-02-26 07:23:53 +01:00
Payment channels: Add more logging on the server resume path.
This commit is contained in:
parent
7d75e747e0
commit
a7dbe7cd03
1 changed files with 12 additions and 7 deletions
|
@ -1,16 +1,16 @@
|
||||||
package com.google.bitcoin.protocols.channels;
|
package com.google.bitcoin.protocols.channels;
|
||||||
|
|
||||||
import java.math.BigInteger;
|
|
||||||
import java.util.concurrent.locks.ReentrantLock;
|
|
||||||
|
|
||||||
import com.google.bitcoin.core.*;
|
import com.google.bitcoin.core.*;
|
||||||
|
import com.google.bitcoin.protocols.channels.PaymentChannelCloseException.CloseReason;
|
||||||
import com.google.bitcoin.utils.Threading;
|
import com.google.bitcoin.utils.Threading;
|
||||||
import com.google.protobuf.ByteString;
|
import com.google.protobuf.ByteString;
|
||||||
import net.jcip.annotations.GuardedBy;
|
import net.jcip.annotations.GuardedBy;
|
||||||
import org.bitcoin.paymentchannel.Protos;
|
import org.bitcoin.paymentchannel.Protos;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import com.google.bitcoin.protocols.channels.PaymentChannelCloseException.CloseReason;
|
import java.math.BigInteger;
|
||||||
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
import static com.google.common.base.Preconditions.checkState;
|
import static com.google.common.base.Preconditions.checkState;
|
||||||
|
|
||||||
|
@ -147,18 +147,17 @@ public class PaymentChannelServer {
|
||||||
.setType(Protos.TwoWayChannelMessage.MessageType.SERVER_VERSION)
|
.setType(Protos.TwoWayChannelMessage.MessageType.SERVER_VERSION)
|
||||||
.setServerVersion(versionNegotiationBuilder)
|
.setServerVersion(versionNegotiationBuilder)
|
||||||
.build());
|
.build());
|
||||||
|
|
||||||
ByteString reopenChannelContractHash = msg.getClientVersion().getPreviousChannelContractHash();
|
ByteString reopenChannelContractHash = msg.getClientVersion().getPreviousChannelContractHash();
|
||||||
if (reopenChannelContractHash != null && reopenChannelContractHash.size() == 32) {
|
if (reopenChannelContractHash != null && reopenChannelContractHash.size() == 32) {
|
||||||
|
Sha256Hash contractHash = new Sha256Hash(reopenChannelContractHash.toByteArray());
|
||||||
|
log.info("New client that wants to resume {}", contractHash);
|
||||||
StoredPaymentChannelServerStates channels = (StoredPaymentChannelServerStates)
|
StoredPaymentChannelServerStates channels = (StoredPaymentChannelServerStates)
|
||||||
wallet.getExtensions().get(StoredPaymentChannelServerStates.EXTENSION_ID);
|
wallet.getExtensions().get(StoredPaymentChannelServerStates.EXTENSION_ID);
|
||||||
if (channels != null) {
|
if (channels != null) {
|
||||||
Sha256Hash contractHash = new Sha256Hash(reopenChannelContractHash.toByteArray());
|
|
||||||
StoredServerChannel storedServerChannel = channels.getChannel(contractHash);
|
StoredServerChannel storedServerChannel = channels.getChannel(contractHash);
|
||||||
if (storedServerChannel != null) {
|
if (storedServerChannel != null) {
|
||||||
if (storedServerChannel.setConnectedHandler(this)) {
|
if (storedServerChannel.setConnectedHandler(this)) {
|
||||||
log.info("Got resume version message, responding with VERSIONS and CHANNEL_OPEN");
|
log.info("Got resume version message, responding with VERSIONS and CHANNEL_OPEN");
|
||||||
|
|
||||||
state = storedServerChannel.getState(wallet, broadcaster);
|
state = storedServerChannel.getState(wallet, broadcaster);
|
||||||
step = InitStep.CHANNEL_OPEN;
|
step = InitStep.CHANNEL_OPEN;
|
||||||
conn.sendToClient(Protos.TwoWayChannelMessage.newBuilder()
|
conn.sendToClient(Protos.TwoWayChannelMessage.newBuilder()
|
||||||
|
@ -166,8 +165,14 @@ public class PaymentChannelServer {
|
||||||
.build());
|
.build());
|
||||||
conn.channelOpen(contractHash);
|
conn.channelOpen(contractHash);
|
||||||
return;
|
return;
|
||||||
|
} else {
|
||||||
|
log.error(" ... but that contract is already in use.");
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
log.error(" ... but we do not have any record of that contract! Resume failed.");
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
log.error(" ... but we do not have any stored channels! Resume failed.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log.info("Got initial version message, responding with VERSIONS and INITIATE");
|
log.info("Got initial version message, responding with VERSIONS and INITIATE");
|
||||||
|
|
Loading…
Add table
Reference in a new issue