Skip to content

Commit 8188e03

Browse files
authored
Generalize sync block lookup tests (#6498)
* Generalize sync block lookup tests
1 parent 9d069a9 commit 8188e03

File tree

5 files changed

+102
-81
lines changed

5 files changed

+102
-81
lines changed

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ use types::{BlobSidecar, DataColumnSidecar, EthSpec, SignedBeaconBlock};
5050
pub mod common;
5151
pub mod parent_chain;
5252
mod single_block_lookup;
53-
#[cfg(test)]
54-
mod tests;
5553

5654
/// The maximum depth we will search for a parent block. In principle we should have sync'd any
5755
/// canonical chain to its head once the peer connects. A chain should not appear where it's depth

beacon_node/network/src/sync/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ mod network_context;
99
mod peer_sampling;
1010
mod peer_sync_info;
1111
mod range_sync;
12+
#[cfg(test)]
13+
mod tests;
1214

1315
pub use lighthouse_network::service::api_types::SamplingId;
1416
pub use manager::{BatchProcessResult, SyncMessage};

beacon_node/network/src/sync/block_lookups/tests.rs renamed to beacon_node/network/src/sync/tests/lookups.rs

Lines changed: 32 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,97 +1,50 @@
11
use crate::network_beacon_processor::NetworkBeaconProcessor;
2-
use crate::sync::manager::{BlockProcessType, SyncManager};
3-
use crate::sync::peer_sampling::SamplingConfig;
4-
use crate::sync::range_sync::RangeSyncType;
5-
use crate::sync::{SamplingId, SyncMessage};
2+
use crate::sync::block_lookups::{
3+
BlockLookupSummary, PARENT_DEPTH_TOLERANCE, SINGLE_BLOCK_LOOKUP_MAX_ATTEMPTS,
4+
};
5+
use crate::sync::{
6+
manager::{BlockProcessType, BlockProcessingResult, SyncManager},
7+
peer_sampling::SamplingConfig,
8+
SamplingId, SyncMessage,
9+
};
610
use crate::NetworkMessage;
711
use std::sync::Arc;
12+
use std::time::Duration;
813

914
use super::*;
1015

1116
use crate::sync::block_lookups::common::ResponseType;
12-
use beacon_chain::blob_verification::GossipVerifiedBlob;
13-
use beacon_chain::block_verification_types::BlockImportData;
14-
use beacon_chain::builder::Witness;
15-
use beacon_chain::data_availability_checker::Availability;
16-
use beacon_chain::eth1_chain::CachingEth1Backend;
17-
use beacon_chain::test_utils::{
18-
build_log, generate_rand_block_and_blobs, generate_rand_block_and_data_columns, test_spec,
19-
BeaconChainHarness, EphemeralHarnessType, LoggerType, NumBlobs,
20-
};
21-
use beacon_chain::validator_monitor::timestamp_now;
2217
use beacon_chain::{
23-
AvailabilityPendingExecutedBlock, PayloadVerificationOutcome, PayloadVerificationStatus,
18+
blob_verification::GossipVerifiedBlob,
19+
block_verification_types::{AsBlock, BlockImportData},
20+
data_availability_checker::Availability,
21+
test_utils::{
22+
build_log, generate_rand_block_and_blobs, generate_rand_block_and_data_columns, test_spec,
23+
BeaconChainHarness, EphemeralHarnessType, LoggerType, NumBlobs,
24+
},
25+
validator_monitor::timestamp_now,
26+
AvailabilityPendingExecutedBlock, AvailabilityProcessingStatus, BlockError,
27+
PayloadVerificationOutcome, PayloadVerificationStatus,
2428
};
2529
use beacon_processor::WorkEvent;
26-
use lighthouse_network::rpc::{RPCError, RequestType, RpcErrorResponse};
27-
use lighthouse_network::service::api_types::{
28-
AppRequestId, DataColumnsByRootRequestId, DataColumnsByRootRequester, Id, SamplingRequester,
29-
SingleLookupReqId, SyncRequestId,
30+
use lighthouse_network::{
31+
rpc::{RPCError, RequestType, RpcErrorResponse},
32+
service::api_types::{
33+
AppRequestId, DataColumnsByRootRequestId, DataColumnsByRootRequester, Id,
34+
SamplingRequester, SingleLookupReqId, SyncRequestId,
35+
},
36+
types::SyncState,
37+
NetworkConfig, NetworkGlobals, PeerId,
3038
};
31-
use lighthouse_network::types::SyncState;
32-
use lighthouse_network::NetworkConfig;
33-
use lighthouse_network::NetworkGlobals;
3439
use slog::info;
35-
use slot_clock::{ManualSlotClock, SlotClock, TestingSlotClock};
36-
use store::MemoryStore;
40+
use slot_clock::{SlotClock, TestingSlotClock};
3741
use tokio::sync::mpsc;
38-
use types::data_column_sidecar::ColumnIndex;
39-
use types::test_utils::TestRandom;
4042
use types::{
41-
test_utils::{SeedableRng, XorShiftRng},
42-
BlobSidecar, ForkName, MinimalEthSpec as E, SignedBeaconBlock, Slot,
43+
data_column_sidecar::ColumnIndex,
44+
test_utils::{SeedableRng, TestRandom, XorShiftRng},
45+
BeaconState, BeaconStateBase, BlobSidecar, DataColumnSidecar, Epoch, EthSpec, ForkName,
46+
Hash256, MinimalEthSpec as E, SignedBeaconBlock, Slot,
4347
};
44-
use types::{BeaconState, BeaconStateBase};
45-
use types::{DataColumnSidecar, Epoch};
46-
47-
type T = Witness<ManualSlotClock, CachingEth1Backend<E>, E, MemoryStore<E>, MemoryStore<E>>;
48-
49-
/// This test utility enables integration testing of Lighthouse sync components.
50-
///
51-
/// It covers the following:
52-
/// 1. Sending `SyncMessage` to `SyncManager` to trigger `RangeSync`, `BackFillSync` and `BlockLookups` behaviours.
53-
/// 2. Making assertions on `WorkEvent`s received from sync
54-
/// 3. Making assertion on `NetworkMessage` received from sync (Outgoing RPC requests).
55-
///
56-
/// The test utility covers testing the interactions from and to `SyncManager`. In diagram form:
57-
/// +-----------------+
58-
/// | BeaconProcessor |
59-
/// +---------+-------+
60-
/// ^ |
61-
/// | |
62-
/// WorkEvent | | SyncMsg
63-
/// | | (Result)
64-
/// | v
65-
/// +--------+ +-----+-----------+ +----------------+
66-
/// | Router +----------->| SyncManager +------------>| NetworkService |
67-
/// +--------+ SyncMsg +-----------------+ NetworkMsg +----------------+
68-
/// (RPC resp) | - RangeSync | (RPC req)
69-
/// +-----------------+
70-
/// | - BackFillSync |
71-
/// +-----------------+
72-
/// | - BlockLookups |
73-
/// +-----------------+
74-
struct TestRig {
75-
/// Receiver for `BeaconProcessor` events (e.g. block processing results).
76-
beacon_processor_rx: mpsc::Receiver<WorkEvent<E>>,
77-
beacon_processor_rx_queue: Vec<WorkEvent<E>>,
78-
/// Receiver for `NetworkMessage` (e.g. outgoing RPC requests from sync)
79-
network_rx: mpsc::UnboundedReceiver<NetworkMessage<E>>,
80-
/// Stores all `NetworkMessage`s received from `network_recv`. (e.g. outgoing RPC requests)
81-
network_rx_queue: Vec<NetworkMessage<E>>,
82-
/// Receiver for `SyncMessage` from the network
83-
sync_rx: mpsc::UnboundedReceiver<SyncMessage<E>>,
84-
/// To send `SyncMessage`. For sending RPC responses or block processing results to sync.
85-
sync_manager: SyncManager<T>,
86-
/// To manipulate sync state and peer connection status
87-
network_globals: Arc<NetworkGlobals<E>>,
88-
/// Beacon chain harness
89-
harness: BeaconChainHarness<EphemeralHarnessType<E>>,
90-
/// `rng` for generating test blocks and blobs.
91-
rng: XorShiftRng,
92-
fork_name: ForkName,
93-
log: Logger,
94-
}
9548

9649
const D: Duration = Duration::new(0, 0);
9750
const PARENT_FAIL_TOLERANCE: u8 = SINGLE_BLOCK_LOOKUP_MAX_ATTEMPTS;
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
use crate::sync::manager::SyncManager;
2+
use crate::sync::range_sync::RangeSyncType;
3+
use crate::sync::SyncMessage;
4+
use crate::NetworkMessage;
5+
use beacon_chain::builder::Witness;
6+
use beacon_chain::eth1_chain::CachingEth1Backend;
7+
use beacon_chain::test_utils::{BeaconChainHarness, EphemeralHarnessType};
8+
use beacon_processor::WorkEvent;
9+
use lighthouse_network::NetworkGlobals;
10+
use slog::Logger;
11+
use slot_clock::ManualSlotClock;
12+
use std::sync::Arc;
13+
use store::MemoryStore;
14+
use tokio::sync::mpsc;
15+
use types::{test_utils::XorShiftRng, ForkName, MinimalEthSpec as E};
16+
17+
mod lookups;
18+
mod range;
19+
20+
type T = Witness<ManualSlotClock, CachingEth1Backend<E>, E, MemoryStore<E>, MemoryStore<E>>;
21+
22+
/// This test utility enables integration testing of Lighthouse sync components.
23+
///
24+
/// It covers the following:
25+
/// 1. Sending `SyncMessage` to `SyncManager` to trigger `RangeSync`, `BackFillSync` and `BlockLookups` behaviours.
26+
/// 2. Making assertions on `WorkEvent`s received from sync
27+
/// 3. Making assertion on `NetworkMessage` received from sync (Outgoing RPC requests).
28+
///
29+
/// The test utility covers testing the interactions from and to `SyncManager`. In diagram form:
30+
/// +-----------------+
31+
/// | BeaconProcessor |
32+
/// +---------+-------+
33+
/// ^ |
34+
/// | |
35+
/// WorkEvent | | SyncMsg
36+
/// | | (Result)
37+
/// | v
38+
/// +--------+ +-----+-----------+ +----------------+
39+
/// | Router +----------->| SyncManager +------------>| NetworkService |
40+
/// +--------+ SyncMsg +-----------------+ NetworkMsg +----------------+
41+
/// (RPC resp) | - RangeSync | (RPC req)
42+
/// +-----------------+
43+
/// | - BackFillSync |
44+
/// +-----------------+
45+
/// | - BlockLookups |
46+
/// +-----------------+
47+
struct TestRig {
48+
/// Receiver for `BeaconProcessor` events (e.g. block processing results).
49+
beacon_processor_rx: mpsc::Receiver<WorkEvent<E>>,
50+
beacon_processor_rx_queue: Vec<WorkEvent<E>>,
51+
/// Receiver for `NetworkMessage` (e.g. outgoing RPC requests from sync)
52+
network_rx: mpsc::UnboundedReceiver<NetworkMessage<E>>,
53+
/// Stores all `NetworkMessage`s received from `network_recv`. (e.g. outgoing RPC requests)
54+
network_rx_queue: Vec<NetworkMessage<E>>,
55+
/// Receiver for `SyncMessage` from the network
56+
sync_rx: mpsc::UnboundedReceiver<SyncMessage<E>>,
57+
/// To send `SyncMessage`. For sending RPC responses or block processing results to sync.
58+
sync_manager: SyncManager<T>,
59+
/// To manipulate sync state and peer connection status
60+
network_globals: Arc<NetworkGlobals<E>>,
61+
/// Beacon chain harness
62+
harness: BeaconChainHarness<EphemeralHarnessType<E>>,
63+
/// `rng` for generating test blocks and blobs.
64+
rng: XorShiftRng,
65+
fork_name: ForkName,
66+
log: Logger,
67+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

0 commit comments

Comments
 (0)