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

Commit e040a97

Browse files
committed
sync: refactor sync reset
1 parent f88509b commit e040a97

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

ethcore/sync/src/chain/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -507,8 +507,9 @@ impl ChainSync {
507507
self.peers.clear();
508508
}
509509

510-
/// Reset sync. Clear all downloaded data but keep the queue
511-
fn reset(&mut self, io: &mut SyncIo) {
510+
/// Reset sync. Clear all downloaded data but keep the queue.
511+
/// Set sync state to the given state or to the initial state if `None` is provided.
512+
fn reset(&mut self, io: &mut SyncIo, state: Option<SyncState>) {
512513
self.new_blocks.reset();
513514
let chain_info = io.chain().chain_info();
514515
for (_, ref mut p) in &mut self.peers {
@@ -520,7 +521,7 @@ impl ChainSync {
520521
}
521522
}
522523
}
523-
self.state = ChainSync::get_init_state(self.warp_sync, io.chain());
524+
self.state = state.unwrap_or_else(|| ChainSync::get_init_state(self.warp_sync, io.chain()));
524525
// Reactivate peers only if some progress has been made
525526
// since the last sync round of if starting fresh.
526527
self.active_peers = self.peers.keys().cloned().collect();
@@ -534,7 +535,7 @@ impl ChainSync {
534535
io.snapshot_service().abort_restore();
535536
}
536537
self.snapshot.clear();
537-
self.reset(io);
538+
self.reset(io, None);
538539
self.continue_sync(io);
539540
}
540541

@@ -699,8 +700,7 @@ impl ChainSync {
699700
/// Called after all blocks have been downloaded
700701
fn complete_sync(&mut self, io: &mut SyncIo) {
701702
trace!(target: "sync", "Sync complete");
702-
self.reset(io);
703-
self.state = SyncState::Idle;
703+
self.reset(io, Some(SyncState::Idle));
704704
}
705705

706706
/// Enter waiting state

0 commit comments

Comments
 (0)