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

Commit

Permalink
ethcore: fix detection of major import (#9552)
Browse files Browse the repository at this point in the history
* sync: set state to idle after sync is completed

* sync: refactor sync reset
  • Loading branch information
andresilva authored and 5chdn committed Oct 8, 2018
1 parent 4f278ba commit dc14cce
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions ethcore/sync/src/chain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -507,8 +507,9 @@ impl ChainSync {
self.peers.clear();
}

/// Reset sync. Clear all downloaded data but keep the queue
fn reset(&mut self, io: &mut SyncIo) {
/// Reset sync. Clear all downloaded data but keep the queue.
/// Set sync state to the given state or to the initial state if `None` is provided.
fn reset(&mut self, io: &mut SyncIo, state: Option<SyncState>) {
self.new_blocks.reset();
let chain_info = io.chain().chain_info();
for (_, ref mut p) in &mut self.peers {
Expand All @@ -520,7 +521,7 @@ impl ChainSync {
}
}
}
self.state = ChainSync::get_init_state(self.warp_sync, io.chain());
self.state = state.unwrap_or_else(|| ChainSync::get_init_state(self.warp_sync, io.chain()));
// Reactivate peers only if some progress has been made
// since the last sync round of if starting fresh.
self.active_peers = self.peers.keys().cloned().collect();
Expand All @@ -534,7 +535,7 @@ impl ChainSync {
io.snapshot_service().abort_restore();
}
self.snapshot.clear();
self.reset(io);
self.reset(io, None);
self.continue_sync(io);
}

Expand Down Expand Up @@ -699,7 +700,7 @@ impl ChainSync {
/// Called after all blocks have been downloaded
fn complete_sync(&mut self, io: &mut SyncIo) {
trace!(target: "sync", "Sync complete");
self.reset(io);
self.reset(io, Some(SyncState::Idle));
}

/// Enter waiting state
Expand Down

0 comments on commit dc14cce

Please sign in to comment.