diff --git a/src/main/java/org/qortal/controller/Synchronizer.java b/src/main/java/org/qortal/controller/Synchronizer.java index fd95006c..1609979e 100644 --- a/src/main/java/org/qortal/controller/Synchronizer.java +++ b/src/main/java/org/qortal/controller/Synchronizer.java @@ -759,11 +759,17 @@ public class Synchronizer { LOGGER.info(String.format("Peer %s failed to respond with more block signatures after height %d, sig %.8s", peer, height, Base58.encode(latestPeerSignature))); - // If we have already received blocks from this peer, go ahead and apply them + // If we have already received RECENT blocks from this peer, go ahead and apply them if (peerBlocks.size() > 0) { - break; + final Block peerLatestBlock = peerBlocks.get(peerBlocks.size() - 1); + final Long minLatestBlockTimestamp = Controller.getMinimumLatestBlockTimestamp(); + if (peerLatestBlock != null && minLatestBlockTimestamp != null + && peerLatestBlock.getBlockData().getTimestamp() > minLatestBlockTimestamp) { + LOGGER.debug("Newly received blocks are recent, so we will apply them"); + break; + } } - // Otherwise, give up and move on to the next peer + // Otherwise, give up and move on to the next peer, to avoid putting our chain into an outdated state return SynchronizationResult.NO_REPLY; } @@ -788,11 +794,17 @@ public class Synchronizer { if (retryCount >= MAXIMUM_RETRIES) { - // If we have already received blocks from this peer, go ahead and apply them + // If we have already received RECENT blocks from this peer, go ahead and apply them if (peerBlocks.size() > 0) { - break; + final Block peerLatestBlock = peerBlocks.get(peerBlocks.size() - 1); + final Long minLatestBlockTimestamp = Controller.getMinimumLatestBlockTimestamp(); + if (peerLatestBlock != null && minLatestBlockTimestamp != null + && peerLatestBlock.getBlockData().getTimestamp() > minLatestBlockTimestamp) { + LOGGER.debug("Newly received blocks are recent, so we will apply them"); + break; + } } - // Otherwise, give up and move on to the next peer + // Otherwise, give up and move on to the next peer, to avoid putting our chain into an outdated state return SynchronizationResult.NO_REPLY; } else {