If the chain goes out of sync auto catch up to the sync state
This commit is contained in:
parent
d3ae5c9419
commit
549882bc03
|
@ -259,7 +259,7 @@ public class BlockchainImpl implements Blockchain {
|
||||||
this.setLastBlock(block);
|
this.setLastBlock(block);
|
||||||
|
|
||||||
if (logger.isDebugEnabled())
|
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)
|
if (block.getNumber() % 100 == 0)
|
||||||
logger.info("*** Last block added [ #{} ]", block.getNumber());
|
logger.info("*** Last block added [ #{} ]", block.getNumber());
|
||||||
}
|
}
|
||||||
|
|
|
@ -276,9 +276,19 @@ public class EthHandler extends SimpleChannelInboundHandler<EthMessage> {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// here is post sync process
|
// here is post sync process
|
||||||
logger.info("New block received: block.index [{}]", newBlockMessage.getBlock().getNumber());
|
logger.info("New block received: block.index [{}]", newBlockMessage.getBlock().getNumber());
|
||||||
WorldManager.getInstance().clearPendingTransactions(newBlockMessage.getBlock().getTransactionsList());
|
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().addBlock(newBlockMessage.getBlock());
|
||||||
blockchain.getQueue().logHashQueueSize();
|
blockchain.getQueue().logHashQueueSize();
|
||||||
}
|
}
|
||||||
|
@ -373,6 +383,7 @@ public class EthHandler extends SimpleChannelInboundHandler<EthMessage> {
|
||||||
|
|
||||||
public void startGetBlockTimer() {
|
public void startGetBlockTimer() {
|
||||||
syncStatus = SyncSatus.BLOCK_RETRIEVING;
|
syncStatus = SyncSatus.BLOCK_RETRIEVING;
|
||||||
|
getBlocksTimer = new Timer("GetBlocksTimer");
|
||||||
getBlocksTimer.scheduleAtFixedRate(new TimerTask() {
|
getBlocksTimer.scheduleAtFixedRate(new TimerTask() {
|
||||||
public void run() {
|
public void run() {
|
||||||
BlockQueue blockQueue = WorldManager.getInstance().getBlockchain().getQueue();
|
BlockQueue blockQueue = WorldManager.getInstance().getBlockchain().getQueue();
|
||||||
|
|
Loading…
Reference in New Issue