From 3e192ab4861e3891da040ca8b0d1a47c59c24d87 Mon Sep 17 00:00:00 2001 From: arkpar Date: Sat, 26 Mar 2016 12:00:05 +0100 Subject: [PATCH] Full restart on bad block --- sync/src/chain.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/sync/src/chain.rs b/sync/src/chain.rs index 41afbea1c..f84f91f77 100644 --- a/sync/src/chain.rs +++ b/sync/src/chain.rs @@ -277,7 +277,6 @@ impl ChainSync { self.peers.clear(); } - #[cfg_attr(feature="dev", allow(for_kv_map))] // Because it's not possible to get `values_mut()` /// Rest sync. Clear all downloaded data but keep the queue fn reset(&mut self) { @@ -304,6 +303,13 @@ impl ChainSync { self.state = SyncState::NotSynced; } + /// Restart sync after bad block has been detected. May end up re-downloading up to QUEUE_SIZE blocks + pub fn restart_on_bad_block(&mut self, io: &mut SyncIo) { + self.restart(io); + // Do not assume that the block queue/chain still has our last_imported_block + self.last_imported_block = None; + self.last_imported_hash = None; + } /// Called by peer to report status fn on_peer_status(&mut self, io: &mut SyncIo, peer_id: PeerId, r: &UntrustedRlp) -> Result<(), PacketDecodeError> { let peer = PeerInfo { @@ -841,7 +847,7 @@ impl ChainSync { } if restart { - self.restart(io); + self.restart_on_bad_block(io); return; }