Skip to content

Commit e3ce7fc

Browse files
committed
Add BeaconBlocksByRange v3
1 parent cb1e8dc commit e3ce7fc

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

beacon_node/network/src/sync/block_lookups/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ mod tests;
5353
/// The maximum depth we will search for a parent block. In principle we should have sync'd any
5454
/// canonical chain to its head once the peer connects. A chain should not appear where it's depth
5555
/// is further back than the most recent head slot.
56-
pub(crate) const PARENT_DEPTH_TOLERANCE: usize = SLOT_IMPORT_TOLERANCE * 2;
56+
pub(crate) const PARENT_DEPTH_TOLERANCE: usize = SLOT_IMPORT_TOLERANCE + 1;
5757

5858
const FAILED_CHAINS_CACHE_EXPIRY_SECONDS: u64 = 60;
5959
pub const SINGLE_BLOCK_LOOKUP_MAX_ATTEMPTS: u8 = 4;

beacon_node/network/src/sync/range_sync/chain.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use rand::{seq::SliceRandom, Rng};
1111
use slog::{crit, debug, o, warn};
1212
use std::collections::{btree_map::Entry, BTreeMap, HashSet};
1313
use std::hash::{Hash, Hasher};
14+
use std::time::Instant;
1415
use 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> {
109110
pub 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

Comments
 (0)