@@ -507,8 +507,9 @@ impl ChainSync {
507
507
self . peers . clear ( ) ;
508
508
}
509
509
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 > ) {
512
513
self . new_blocks . reset ( ) ;
513
514
let chain_info = io. chain ( ) . chain_info ( ) ;
514
515
for ( _, ref mut p) in & mut self . peers {
@@ -520,7 +521,7 @@ impl ChainSync {
520
521
}
521
522
}
522
523
}
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 ( ) ) ) ;
524
525
// Reactivate peers only if some progress has been made
525
526
// since the last sync round of if starting fresh.
526
527
self . active_peers = self . peers . keys ( ) . cloned ( ) . collect ( ) ;
@@ -534,7 +535,7 @@ impl ChainSync {
534
535
io. snapshot_service ( ) . abort_restore ( ) ;
535
536
}
536
537
self . snapshot . clear ( ) ;
537
- self . reset ( io) ;
538
+ self . reset ( io, None ) ;
538
539
self . continue_sync ( io) ;
539
540
}
540
541
@@ -699,8 +700,7 @@ impl ChainSync {
699
700
/// Called after all blocks have been downloaded
700
701
fn complete_sync ( & mut self , io : & mut SyncIo ) {
701
702
trace ! ( target: "sync" , "Sync complete" ) ;
702
- self . reset ( io) ;
703
- self . state = SyncState :: Idle ;
703
+ self . reset ( io, Some ( SyncState :: Idle ) ) ;
704
704
}
705
705
706
706
/// Enter waiting state
0 commit comments