From 20ca56490e9c07adc783d7b4588452ef4fa0be76 Mon Sep 17 00:00:00 2001 From: Arkadiy Paronyan Date: Wed, 9 Nov 2016 19:40:36 +0100 Subject: [PATCH] Additional snapshot sync checks (#3318) * Additional snapshot sync checks * Proper checks * Proper highset block check Former-commit-id: 402a6ca55670f9c197b3d673e91528b853b1b7d6 --- sync/src/chain.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/sync/src/chain.rs b/sync/src/chain.rs index 063d60e6b..2f810e754 100644 --- a/sync/src/chain.rs +++ b/sync/src/chain.rs @@ -457,12 +457,19 @@ impl ChainSync { if self.state != SyncState::WaitingPeers { return; } - let best_block = io.chain().chain_info().best_block_number; + // Make sure the snapshot block is not too far away from best block and network best block and + // that it is higher than fork detection block + let our_best_block = io.chain().chain_info().best_block_number; + let fork_block = self.fork_block.as_ref().map(|&(n, _)| n).unwrap_or(0); let (best_hash, max_peers, snapshot_peers) = { //collect snapshot infos from peers let snapshots = self.peers.iter() - .filter(|&(_, p)| p.is_allowed() && p.snapshot_number.map_or(false, |sn| best_block < sn && (sn - best_block) > SNAPSHOT_RESTORE_THRESHOLD)) + .filter(|&(_, p)| p.is_allowed() && p.snapshot_number.map_or(false, |sn| + our_best_block < sn && (sn - our_best_block) > SNAPSHOT_RESTORE_THRESHOLD && + sn > fork_block && + self.highest_block.map_or(true, |highest| highest >= sn && (highest - sn) <= SNAPSHOT_RESTORE_THRESHOLD) + )) .filter_map(|(p, peer)| peer.snapshot_hash.map(|hash| (p, hash.clone()))); let mut snapshot_peers = HashMap::new();