Skip to content

Commit 1c5be34

Browse files
authored
Write range sync tests in external event-driven form (#6618)
* Write range sync tests in external event-driven form * Fix remaining test * Drop unused generics * Merge branch 'unstable' into range-sync-tests * Add reference to test author * Use async await * Fix failing test. Not sure how it was passing before without an EL.
1 parent 75d9079 commit 1c5be34

File tree

8 files changed

+328
-512
lines changed

8 files changed

+328
-512
lines changed

beacon_node/network/src/sync/manager.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,16 @@ impl<T: BeaconChainTypes> SyncManager<T> {
362362
self.sampling.get_request_status(block_root, index)
363363
}
364364

365+
#[cfg(test)]
366+
pub(crate) fn range_sync_state(&self) -> super::range_sync::SyncChainStatus {
367+
self.range_sync.state()
368+
}
369+
370+
#[cfg(test)]
371+
pub(crate) fn update_execution_engine_state(&mut self, state: EngineState) {
372+
self.handle_new_execution_engine_state(state);
373+
}
374+
365375
fn network_globals(&self) -> &NetworkGlobals<T::EthSpec> {
366376
self.network.network_globals()
367377
}

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

Lines changed: 0 additions & 13 deletions
This file was deleted.

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

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33
//! Each chain type is stored in it's own map. A variety of helper functions are given along with
44
//! this struct to simplify the logic of the other layers of sync.
55
6-
use super::block_storage::BlockStorage;
76
use super::chain::{ChainId, ProcessingResult, RemoveChain, SyncingChain};
87
use super::sync_type::RangeSyncType;
98
use crate::metrics;
109
use crate::sync::network_context::SyncNetworkContext;
11-
use beacon_chain::BeaconChainTypes;
10+
use beacon_chain::{BeaconChain, BeaconChainTypes};
1211
use fnv::FnvHashMap;
1312
use lighthouse_network::PeerId;
1413
use lighthouse_network::SyncInfo;
@@ -37,10 +36,13 @@ pub enum RangeSyncState {
3736
Idle,
3837
}
3938

39+
pub type SyncChainStatus =
40+
Result<Option<(RangeSyncType, Slot /* from */, Slot /* to */)>, &'static str>;
41+
4042
/// A collection of finalized and head chains currently being processed.
41-
pub struct ChainCollection<T: BeaconChainTypes, C> {
43+
pub struct ChainCollection<T: BeaconChainTypes> {
4244
/// The beacon chain for processing.
43-
beacon_chain: Arc<C>,
45+
beacon_chain: Arc<BeaconChain<T>>,
4446
/// The set of finalized chains being synced.
4547
finalized_chains: FnvHashMap<ChainId, SyncingChain<T>>,
4648
/// The set of head chains being synced.
@@ -51,8 +53,8 @@ pub struct ChainCollection<T: BeaconChainTypes, C> {
5153
log: slog::Logger,
5254
}
5355

54-
impl<T: BeaconChainTypes, C: BlockStorage> ChainCollection<T, C> {
55-
pub fn new(beacon_chain: Arc<C>, log: slog::Logger) -> Self {
56+
impl<T: BeaconChainTypes> ChainCollection<T> {
57+
pub fn new(beacon_chain: Arc<BeaconChain<T>>, log: slog::Logger) -> Self {
5658
ChainCollection {
5759
beacon_chain,
5860
finalized_chains: FnvHashMap::default(),
@@ -213,9 +215,7 @@ impl<T: BeaconChainTypes, C: BlockStorage> ChainCollection<T, C> {
213215
}
214216
}
215217

216-
pub fn state(
217-
&self,
218-
) -> Result<Option<(RangeSyncType, Slot /* from */, Slot /* to */)>, &'static str> {
218+
pub fn state(&self) -> SyncChainStatus {
219219
match self.state {
220220
RangeSyncState::Finalized(ref syncing_id) => {
221221
let chain = self
@@ -409,7 +409,8 @@ impl<T: BeaconChainTypes, C: BlockStorage> ChainCollection<T, C> {
409409
let log_ref = &self.log;
410410

411411
let is_outdated = |target_slot: &Slot, target_root: &Hash256| {
412-
target_slot <= &local_finalized_slot || beacon_chain.is_block_known(target_root)
412+
target_slot <= &local_finalized_slot
413+
|| beacon_chain.block_is_known_to_fork_choice(target_root)
413414
};
414415

415416
// Retain only head peers that remain relevant

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
//! peers.
33
44
mod batch;
5-
mod block_storage;
65
mod chain;
76
mod chain_collection;
87
mod range;
@@ -13,5 +12,7 @@ pub use batch::{
1312
ByRangeRequestType,
1413
};
1514
pub use chain::{BatchId, ChainId, EPOCHS_PER_BATCH};
15+
#[cfg(test)]
16+
pub use chain_collection::SyncChainStatus;
1617
pub use range::RangeSync;
1718
pub use sync_type::RangeSyncType;

0 commit comments

Comments
 (0)