If the chain goes out of sync auto catch up to the sync state

This commit is contained in:
romanman 2014-11-01 23:53:27 -05:00
parent d3ae5c9419
commit 549882bc03
2 changed files with 12 additions and 1 deletions

View File

@ -259,7 +259,7 @@ public class BlockchainImpl implements Blockchain {
this.setLastBlock(block);
if (logger.isDebugEnabled())
logger.debug("block added to the blockChain {}", block.toFlatString());
logger.debug("block added to the blockChain: index: [{}]", block.getNumber());
if (block.getNumber() % 100 == 0)
logger.info("*** Last block added [ #{} ]", block.getNumber());
}

View File

@ -276,9 +276,19 @@ public class EthHandler extends SimpleChannelInboundHandler<EthMessage> {
return;
}
// here is post sync process
logger.info("New block received: block.index [{}]", newBlockMessage.getBlock().getNumber());
WorldManager.getInstance().clearPendingTransactions(newBlockMessage.getBlock().getTransactionsList());
long gap = newBlockMessage.getBlock().getNumber() - blockchain.getQueue().getLastBlock().getNumber();
if (gap > 1){
logger.error("Gap in the chain, go out of sync");
this.syncStatus = SyncSatus.HASH_RETRIEVING;
blockchain.getQueue().addHash(newBlock.getHash());
sendGetBlockHashes();
}
blockchain.getQueue().addBlock(newBlockMessage.getBlock());
blockchain.getQueue().logHashQueueSize();
}
@ -373,6 +383,7 @@ public class EthHandler extends SimpleChannelInboundHandler<EthMessage> {
public void startGetBlockTimer() {
syncStatus = SyncSatus.BLOCK_RETRIEVING;
getBlocksTimer = new Timer("GetBlocksTimer");
getBlocksTimer.scheduleAtFixedRate(new TimerTask() {
public void run() {
BlockQueue blockQueue = WorldManager.getInstance().getBlockchain().getQueue();