@@ -11,6 +11,7 @@ use rand::{seq::SliceRandom, Rng};
1111use slog:: { crit, debug, o, warn} ;
1212use std:: collections:: { btree_map:: Entry , BTreeMap , HashSet } ;
1313use std:: hash:: { Hash , Hasher } ;
14+ use std:: time:: Instant ;
1415use types:: { Epoch , EthSpec , Hash256 , Slot } ;
1516
1617/// Blocks are downloaded in batches from peers. This constant specifies how many epochs worth of
@@ -109,6 +110,9 @@ pub struct SyncingChain<T: BeaconChainTypes> {
109110pub enum ChainSyncingState {
110111 /// The chain is not being synced.
111112 Stopped ,
113+ /// The chain should not download any more batches, but should attempt to processing everything
114+ /// that is already downloaded.
115+ Stopping ( Instant ) ,
112116 /// The chain is undergoing syncing.
113117 Syncing ,
114118}
@@ -866,6 +870,11 @@ impl<T: BeaconChainTypes> SyncingChain<T> {
866870 network : & mut SyncNetworkContext < T > ,
867871 batch_id : BatchId ,
868872 ) -> ProcessingResult {
873+ // If chain is stopping do not request any more batches.
874+ if matches ! ( self . state, ChainSyncingState :: Stopping ) {
875+ return Ok ( KeepChain ) ;
876+ }
877+
869878 let Some ( batch) = self . batches . get_mut ( & batch_id) else {
870879 return Ok ( KeepChain ) ;
871880 } ;
@@ -972,7 +981,7 @@ impl<T: BeaconChainTypes> SyncingChain<T> {
972981 pub fn is_syncing ( & self ) -> bool {
973982 match self . state {
974983 ChainSyncingState :: Syncing => true ,
975- ChainSyncingState :: Stopped => false ,
984+ ChainSyncingState :: Stopped | ChainSyncingState :: Stopping { .. } => false ,
976985 }
977986 }
978987
@@ -991,6 +1000,7 @@ impl<T: BeaconChainTypes> SyncingChain<T> {
9911000 /// Attempts to request the next required batches from the peer pool if the chain is syncing. It will exhaust the peer
9921001 /// pool and left over batches until the batch buffer is reached or all peers are exhausted.
9931002 fn request_batches ( & mut self , network : & mut SyncNetworkContext < T > ) -> ProcessingResult {
1003+ // If chain is stopped or stopping do not request any more batches.
9941004 if !matches ! ( self . state, ChainSyncingState :: Syncing ) {
9951005 return Ok ( KeepChain ) ;
9961006 }
0 commit comments