diff --git a/ethereumj-core/src/main/java/org/ethereum/core/BlockchainImpl.java b/ethereumj-core/src/main/java/org/ethereum/core/BlockchainImpl.java index b15c2f70..506db0e7 100644 --- a/ethereumj-core/src/main/java/org/ethereum/core/BlockchainImpl.java +++ b/ethereumj-core/src/main/java/org/ethereum/core/BlockchainImpl.java @@ -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()); } diff --git a/ethereumj-core/src/main/java/org/ethereum/net/eth/EthHandler.java b/ethereumj-core/src/main/java/org/ethereum/net/eth/EthHandler.java index 680b94ad..77387123 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/eth/EthHandler.java +++ b/ethereumj-core/src/main/java/org/ethereum/net/eth/EthHandler.java @@ -276,9 +276,19 @@ public class EthHandler extends SimpleChannelInboundHandler { 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 { public void startGetBlockTimer() { syncStatus = SyncSatus.BLOCK_RETRIEVING; + getBlocksTimer = new Timer("GetBlocksTimer"); getBlocksTimer.scheduleAtFixedRate(new TimerTask() { public void run() { BlockQueue blockQueue = WorldManager.getInstance().getBlockchain().getQueue();