Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Full restart on bad block
Browse files Browse the repository at this point in the history
  • Loading branch information
arkpar committed Mar 28, 2016
1 parent dad4bfe commit 3e192ab
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions sync/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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 {
Expand Down Expand Up @@ -841,7 +847,7 @@ impl ChainSync {
}

if restart {
self.restart(io);
self.restart_on_bad_block(io);
return;
}

Expand Down

0 comments on commit 3e192ab

Please sign in to comment.