Fix snapshot handling

- Fix wrong start height
- Improve logging
This commit is contained in:
Manfred Karrer 2018-09-26 22:41:41 -05:00
parent 97479e295c
commit 8eabd665c7
No known key found for this signature in database
GPG Key ID: 401250966A6B2C46
7 changed files with 26 additions and 14 deletions

View File

@ -67,4 +67,10 @@ public abstract class NetworkEnvelope implements Envelope {
return messageVersion; return messageVersion;
} }
@Override
public String toString() {
return "NetworkEnvelope{" +
"\n messageVersion=" + messageVersion +
"\n}";
}
} }

View File

@ -155,7 +155,11 @@ public abstract class BsqNode implements DaoSetupService {
@SuppressWarnings("WeakerAccess") @SuppressWarnings("WeakerAccess")
protected int getStartBlockHeight() { protected int getStartBlockHeight() {
final int startBlockHeight = Math.max(genesisBlockHeight, bsqStateService.getChainHeight()); int chainHeight = bsqStateService.getChainHeight();
int startBlockHeight = chainHeight;
if (chainHeight > genesisBlockHeight)
startBlockHeight = chainHeight + 1;
log.info("Start parse blocks:\n" + log.info("Start parse blocks:\n" +
" Start block height={}\n" + " Start block height={}\n" +
" Genesis txId={}\n" + " Genesis txId={}\n" +
@ -164,7 +168,7 @@ public abstract class BsqNode implements DaoSetupService {
startBlockHeight, startBlockHeight,
genesisTxId, genesisTxId,
genesisBlockHeight, genesisBlockHeight,
bsqStateService.getChainHeight()); chainHeight);
return startBlockHeight; return startBlockHeight;
} }

View File

@ -40,7 +40,7 @@ import lombok.extern.slf4j.Slf4j;
/** /**
* Main class for a full node which have Bitcoin Core with rpc running and does the blockchain lookup itself. * Main class for a full node which have Bitcoin Core with rpc running and does the blockchain lookup itself.
* It also provides the BSQ transactions to lite nodes on request and broadcasts new BSQ blocks. * It also provides the BSQ transactions to lite nodes on request and broadcasts new BSQ blocks.
* * <p>
* TODO request p2p network data again after parsing is complete to be sure that in case we missed data during parsing * TODO request p2p network data again after parsing is complete to be sure that in case we missed data during parsing
* we get it added. * we get it added.
*/ */
@ -188,8 +188,8 @@ public class FullNode extends BsqNode {
parseBlocksIfNewBlockAvailable(chainHeadHeight); parseBlocksIfNewBlockAvailable(chainHeadHeight);
}, throwable -> { }, throwable -> {
if (throwable instanceof BlockNotConnectingException) { if (throwable instanceof BlockNotConnectingException) {
int blockHeightOfLastBlock = bsqStateService.getBlockHeightOfLastBlock(); int startHeight = bsqStateService.getBlockHeightOfLastBlock() + 1;
requestChainHeadHeightAndParseBlocks(blockHeightOfLastBlock); requestChainHeadHeightAndParseBlocks(startHeight);
} else { } else {
handleError(throwable); handleError(throwable);
} }
@ -232,6 +232,8 @@ public class FullNode extends BsqNode {
} catch (BlockNotConnectingException e) { } catch (BlockNotConnectingException e) {
errorHandler.accept(e); errorHandler.accept(e);
} }
} else {
log.info("Block was already added height=", rawBlock.getHeight());
} }
}, },
errorHandler); errorHandler);

View File

@ -126,14 +126,14 @@ public class RequestBlocksHandler implements MessageListener {
TIMEOUT); TIMEOUT);
} }
log.info("We send a {} to peer {}. ", getBlocksRequest.getClass().getSimpleName(), nodeAddress); log.info("We send to peer {} a {}.", nodeAddress, getBlocksRequest);
networkNode.addMessageListener(this); networkNode.addMessageListener(this);
SettableFuture<Connection> future = networkNode.sendMessage(nodeAddress, getBlocksRequest); SettableFuture<Connection> future = networkNode.sendMessage(nodeAddress, getBlocksRequest);
Futures.addCallback(future, new FutureCallback<Connection>() { Futures.addCallback(future, new FutureCallback<Connection>() {
@Override @Override
public void onSuccess(Connection connection) { public void onSuccess(Connection connection) {
if (!stopped) { if (!stopped) {
log.info("Send " + getBlocksRequest + " to " + nodeAddress + " succeeded."); log.info("Sending of GetBlocksRequest message to peer {} succeeded.", nodeAddress.getHostName());
} else { } else {
log.trace("We have stopped already. We ignore that networkNode.sendMessage.onSuccess call." + log.trace("We have stopped already. We ignore that networkNode.sendMessage.onSuccess call." +
"Might be caused by an previous timeout."); "Might be caused by an previous timeout.");
@ -178,7 +178,7 @@ public class RequestBlocksHandler implements MessageListener {
"RequestDataHandler.onMessage: connection.getPeersNodeAddressOptional() must be present " + "RequestDataHandler.onMessage: connection.getPeersNodeAddressOptional() must be present " +
"at that moment"); "at that moment");
cleanup(); cleanup();
log.info("We received a GetBlocksResponse from peer ={}", nodeAddress.getFullAddress()); log.info("We received from peer {} a {}", nodeAddress.getFullAddress(), getBlocksResponse);
listener.onComplete(getBlocksResponse); listener.onComplete(getBlocksResponse);
} else { } else {
log.warn("Nonce not matching. That can happen rarely if we get a response after a canceled " + log.warn("Nonce not matching. That can happen rarely if we get a response after a canceled " +

View File

@ -32,11 +32,9 @@ import java.util.List;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.Getter; import lombok.Getter;
import lombok.ToString;
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
@Getter @Getter
@ToString
public final class GetBlocksRequest extends NetworkEnvelope implements DirectMessage, CapabilityRequiringPayload { public final class GetBlocksRequest extends NetworkEnvelope implements DirectMessage, CapabilityRequiringPayload {
private final int fromBlockHeight; private final int fromBlockHeight;
private final int nonce; private final int nonce;

View File

@ -37,11 +37,10 @@ import static com.google.common.base.Preconditions.checkNotNull;
/** /**
* Manages snapshots of BsqState. * Manages snapshots of BsqState.
* // FIXME not working correctly anymore
*/ */
@Slf4j @Slf4j
public class SnapshotManager implements BsqStateListener { public class SnapshotManager implements BsqStateListener {
private static final int SNAPSHOT_GRID = 110000000; private static final int SNAPSHOT_GRID = 100;
private final BsqState bsqState; private final BsqState bsqState;
private final BsqStateService bsqStateService; private final BsqStateService bsqStateService;
@ -90,7 +89,7 @@ public class SnapshotManager implements BsqStateListener {
// Now we clone and keep it in memory for the next trigger // Now we clone and keep it in memory for the next trigger
snapshotCandidate = bsqState.getClone(); snapshotCandidate = bsqState.getClone();
// don't access cloned anymore with methods as locks are transient! // don't access cloned anymore with methods as locks are transient!
log.debug("Cloned new snapshotCandidate at height " + chainHeadHeight); log.info("Cloned new snapshotCandidate at height " + chainHeadHeight);
} }
} }

View File

@ -2,7 +2,7 @@
<configuration> <configuration>
<appender name="CONSOLE_APPENDER" class="ch.qos.logback.core.ConsoleAppender"> <appender name="CONSOLE_APPENDER" class="ch.qos.logback.core.ConsoleAppender">
<encoder> <encoder>
<pattern>%highlight(%d{MMM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{15}: %msg %xEx%n)</pattern> <pattern>%highlight(%d{MMM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{30}: %msg %xEx%n)</pattern>
</encoder> </encoder>
</appender> </appender>
@ -11,4 +11,7 @@
</root> </root>
<logger name="com.neemre.btcdcli4j" level="WARN"/> <logger name="com.neemre.btcdcli4j" level="WARN"/>
<!-- <logger name="bisq.core.provider" level="WARN"/>
<logger name="bisq.network" level="WARN"/>-->
</configuration> </configuration>