From f88509bafb67c5592e79c05c573c4d5e31fcbc1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Silva?= Date: Wed, 12 Sep 2018 23:50:35 +0100 Subject: [PATCH 1/2] sync: set state to idle after sync is completed --- ethcore/sync/src/chain/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/ethcore/sync/src/chain/mod.rs b/ethcore/sync/src/chain/mod.rs index 06bd3febab6..63b3b6b836b 100644 --- a/ethcore/sync/src/chain/mod.rs +++ b/ethcore/sync/src/chain/mod.rs @@ -700,6 +700,7 @@ impl ChainSync { fn complete_sync(&mut self, io: &mut SyncIo) { trace!(target: "sync", "Sync complete"); self.reset(io); + self.state = SyncState::Idle; } /// Enter waiting state From e040a971dba412c9a4a120013d3d761354465e59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Silva?= Date: Wed, 3 Oct 2018 14:23:01 +0100 Subject: [PATCH 2/2] sync: refactor sync reset --- ethcore/sync/src/chain/mod.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ethcore/sync/src/chain/mod.rs b/ethcore/sync/src/chain/mod.rs index 63b3b6b836b..8941437b705 100644 --- a/ethcore/sync/src/chain/mod.rs +++ b/ethcore/sync/src/chain/mod.rs @@ -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) { self.new_blocks.reset(); let chain_info = io.chain().chain_info(); for (_, ref mut p) in &mut self.peers { @@ -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(); @@ -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); } @@ -699,8 +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.state = SyncState::Idle; + self.reset(io, Some(SyncState::Idle)); } /// Enter waiting state