mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-02 16:21:42 +00:00
Generalize sync block lookup tests (#6498)
* Generalize sync block lookup tests
This commit is contained in:
@@ -50,8 +50,6 @@ use types::{BlobSidecar, DataColumnSidecar, EthSpec, SignedBeaconBlock};
|
||||
pub mod common;
|
||||
pub mod parent_chain;
|
||||
mod single_block_lookup;
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
/// The maximum depth we will search for a parent block. In principle we should have sync'd any
|
||||
/// canonical chain to its head once the peer connects. A chain should not appear where it's depth
|
||||
|
||||
@@ -9,6 +9,8 @@ mod network_context;
|
||||
mod peer_sampling;
|
||||
mod peer_sync_info;
|
||||
mod range_sync;
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
pub use lighthouse_network::service::api_types::SamplingId;
|
||||
pub use manager::{BatchProcessResult, SyncMessage};
|
||||
|
||||
@@ -1,97 +1,50 @@
|
||||
use crate::network_beacon_processor::NetworkBeaconProcessor;
|
||||
use crate::sync::manager::{BlockProcessType, SyncManager};
|
||||
use crate::sync::peer_sampling::SamplingConfig;
|
||||
use crate::sync::range_sync::RangeSyncType;
|
||||
use crate::sync::{SamplingId, SyncMessage};
|
||||
use crate::sync::block_lookups::{
|
||||
BlockLookupSummary, PARENT_DEPTH_TOLERANCE, SINGLE_BLOCK_LOOKUP_MAX_ATTEMPTS,
|
||||
};
|
||||
use crate::sync::{
|
||||
manager::{BlockProcessType, BlockProcessingResult, SyncManager},
|
||||
peer_sampling::SamplingConfig,
|
||||
SamplingId, SyncMessage,
|
||||
};
|
||||
use crate::NetworkMessage;
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
|
||||
use super::*;
|
||||
|
||||
use crate::sync::block_lookups::common::ResponseType;
|
||||
use beacon_chain::blob_verification::GossipVerifiedBlob;
|
||||
use beacon_chain::block_verification_types::BlockImportData;
|
||||
use beacon_chain::builder::Witness;
|
||||
use beacon_chain::data_availability_checker::Availability;
|
||||
use beacon_chain::eth1_chain::CachingEth1Backend;
|
||||
use beacon_chain::test_utils::{
|
||||
build_log, generate_rand_block_and_blobs, generate_rand_block_and_data_columns, test_spec,
|
||||
BeaconChainHarness, EphemeralHarnessType, LoggerType, NumBlobs,
|
||||
};
|
||||
use beacon_chain::validator_monitor::timestamp_now;
|
||||
use beacon_chain::{
|
||||
AvailabilityPendingExecutedBlock, PayloadVerificationOutcome, PayloadVerificationStatus,
|
||||
blob_verification::GossipVerifiedBlob,
|
||||
block_verification_types::{AsBlock, BlockImportData},
|
||||
data_availability_checker::Availability,
|
||||
test_utils::{
|
||||
build_log, generate_rand_block_and_blobs, generate_rand_block_and_data_columns, test_spec,
|
||||
BeaconChainHarness, EphemeralHarnessType, LoggerType, NumBlobs,
|
||||
},
|
||||
validator_monitor::timestamp_now,
|
||||
AvailabilityPendingExecutedBlock, AvailabilityProcessingStatus, BlockError,
|
||||
PayloadVerificationOutcome, PayloadVerificationStatus,
|
||||
};
|
||||
use beacon_processor::WorkEvent;
|
||||
use lighthouse_network::rpc::{RPCError, RequestType, RpcErrorResponse};
|
||||
use lighthouse_network::service::api_types::{
|
||||
AppRequestId, DataColumnsByRootRequestId, DataColumnsByRootRequester, Id, SamplingRequester,
|
||||
SingleLookupReqId, SyncRequestId,
|
||||
use lighthouse_network::{
|
||||
rpc::{RPCError, RequestType, RpcErrorResponse},
|
||||
service::api_types::{
|
||||
AppRequestId, DataColumnsByRootRequestId, DataColumnsByRootRequester, Id,
|
||||
SamplingRequester, SingleLookupReqId, SyncRequestId,
|
||||
},
|
||||
types::SyncState,
|
||||
NetworkConfig, NetworkGlobals, PeerId,
|
||||
};
|
||||
use lighthouse_network::types::SyncState;
|
||||
use lighthouse_network::NetworkConfig;
|
||||
use lighthouse_network::NetworkGlobals;
|
||||
use slog::info;
|
||||
use slot_clock::{ManualSlotClock, SlotClock, TestingSlotClock};
|
||||
use store::MemoryStore;
|
||||
use slot_clock::{SlotClock, TestingSlotClock};
|
||||
use tokio::sync::mpsc;
|
||||
use types::data_column_sidecar::ColumnIndex;
|
||||
use types::test_utils::TestRandom;
|
||||
use types::{
|
||||
test_utils::{SeedableRng, XorShiftRng},
|
||||
BlobSidecar, ForkName, MinimalEthSpec as E, SignedBeaconBlock, Slot,
|
||||
data_column_sidecar::ColumnIndex,
|
||||
test_utils::{SeedableRng, TestRandom, XorShiftRng},
|
||||
BeaconState, BeaconStateBase, BlobSidecar, DataColumnSidecar, Epoch, EthSpec, ForkName,
|
||||
Hash256, MinimalEthSpec as E, SignedBeaconBlock, Slot,
|
||||
};
|
||||
use types::{BeaconState, BeaconStateBase};
|
||||
use types::{DataColumnSidecar, Epoch};
|
||||
|
||||
type T = Witness<ManualSlotClock, CachingEth1Backend<E>, E, MemoryStore<E>, MemoryStore<E>>;
|
||||
|
||||
/// This test utility enables integration testing of Lighthouse sync components.
|
||||
///
|
||||
/// It covers the following:
|
||||
/// 1. Sending `SyncMessage` to `SyncManager` to trigger `RangeSync`, `BackFillSync` and `BlockLookups` behaviours.
|
||||
/// 2. Making assertions on `WorkEvent`s received from sync
|
||||
/// 3. Making assertion on `NetworkMessage` received from sync (Outgoing RPC requests).
|
||||
///
|
||||
/// The test utility covers testing the interactions from and to `SyncManager`. In diagram form:
|
||||
/// +-----------------+
|
||||
/// | BeaconProcessor |
|
||||
/// +---------+-------+
|
||||
/// ^ |
|
||||
/// | |
|
||||
/// WorkEvent | | SyncMsg
|
||||
/// | | (Result)
|
||||
/// | v
|
||||
/// +--------+ +-----+-----------+ +----------------+
|
||||
/// | Router +----------->| SyncManager +------------>| NetworkService |
|
||||
/// +--------+ SyncMsg +-----------------+ NetworkMsg +----------------+
|
||||
/// (RPC resp) | - RangeSync | (RPC req)
|
||||
/// +-----------------+
|
||||
/// | - BackFillSync |
|
||||
/// +-----------------+
|
||||
/// | - BlockLookups |
|
||||
/// +-----------------+
|
||||
struct TestRig {
|
||||
/// Receiver for `BeaconProcessor` events (e.g. block processing results).
|
||||
beacon_processor_rx: mpsc::Receiver<WorkEvent<E>>,
|
||||
beacon_processor_rx_queue: Vec<WorkEvent<E>>,
|
||||
/// Receiver for `NetworkMessage` (e.g. outgoing RPC requests from sync)
|
||||
network_rx: mpsc::UnboundedReceiver<NetworkMessage<E>>,
|
||||
/// Stores all `NetworkMessage`s received from `network_recv`. (e.g. outgoing RPC requests)
|
||||
network_rx_queue: Vec<NetworkMessage<E>>,
|
||||
/// Receiver for `SyncMessage` from the network
|
||||
sync_rx: mpsc::UnboundedReceiver<SyncMessage<E>>,
|
||||
/// To send `SyncMessage`. For sending RPC responses or block processing results to sync.
|
||||
sync_manager: SyncManager<T>,
|
||||
/// To manipulate sync state and peer connection status
|
||||
network_globals: Arc<NetworkGlobals<E>>,
|
||||
/// Beacon chain harness
|
||||
harness: BeaconChainHarness<EphemeralHarnessType<E>>,
|
||||
/// `rng` for generating test blocks and blobs.
|
||||
rng: XorShiftRng,
|
||||
fork_name: ForkName,
|
||||
log: Logger,
|
||||
}
|
||||
|
||||
const D: Duration = Duration::new(0, 0);
|
||||
const PARENT_FAIL_TOLERANCE: u8 = SINGLE_BLOCK_LOOKUP_MAX_ATTEMPTS;
|
||||
67
beacon_node/network/src/sync/tests/mod.rs
Normal file
67
beacon_node/network/src/sync/tests/mod.rs
Normal file
@@ -0,0 +1,67 @@
|
||||
use crate::sync::manager::SyncManager;
|
||||
use crate::sync::range_sync::RangeSyncType;
|
||||
use crate::sync::SyncMessage;
|
||||
use crate::NetworkMessage;
|
||||
use beacon_chain::builder::Witness;
|
||||
use beacon_chain::eth1_chain::CachingEth1Backend;
|
||||
use beacon_chain::test_utils::{BeaconChainHarness, EphemeralHarnessType};
|
||||
use beacon_processor::WorkEvent;
|
||||
use lighthouse_network::NetworkGlobals;
|
||||
use slog::Logger;
|
||||
use slot_clock::ManualSlotClock;
|
||||
use std::sync::Arc;
|
||||
use store::MemoryStore;
|
||||
use tokio::sync::mpsc;
|
||||
use types::{test_utils::XorShiftRng, ForkName, MinimalEthSpec as E};
|
||||
|
||||
mod lookups;
|
||||
mod range;
|
||||
|
||||
type T = Witness<ManualSlotClock, CachingEth1Backend<E>, E, MemoryStore<E>, MemoryStore<E>>;
|
||||
|
||||
/// This test utility enables integration testing of Lighthouse sync components.
|
||||
///
|
||||
/// It covers the following:
|
||||
/// 1. Sending `SyncMessage` to `SyncManager` to trigger `RangeSync`, `BackFillSync` and `BlockLookups` behaviours.
|
||||
/// 2. Making assertions on `WorkEvent`s received from sync
|
||||
/// 3. Making assertion on `NetworkMessage` received from sync (Outgoing RPC requests).
|
||||
///
|
||||
/// The test utility covers testing the interactions from and to `SyncManager`. In diagram form:
|
||||
/// +-----------------+
|
||||
/// | BeaconProcessor |
|
||||
/// +---------+-------+
|
||||
/// ^ |
|
||||
/// | |
|
||||
/// WorkEvent | | SyncMsg
|
||||
/// | | (Result)
|
||||
/// | v
|
||||
/// +--------+ +-----+-----------+ +----------------+
|
||||
/// | Router +----------->| SyncManager +------------>| NetworkService |
|
||||
/// +--------+ SyncMsg +-----------------+ NetworkMsg +----------------+
|
||||
/// (RPC resp) | - RangeSync | (RPC req)
|
||||
/// +-----------------+
|
||||
/// | - BackFillSync |
|
||||
/// +-----------------+
|
||||
/// | - BlockLookups |
|
||||
/// +-----------------+
|
||||
struct TestRig {
|
||||
/// Receiver for `BeaconProcessor` events (e.g. block processing results).
|
||||
beacon_processor_rx: mpsc::Receiver<WorkEvent<E>>,
|
||||
beacon_processor_rx_queue: Vec<WorkEvent<E>>,
|
||||
/// Receiver for `NetworkMessage` (e.g. outgoing RPC requests from sync)
|
||||
network_rx: mpsc::UnboundedReceiver<NetworkMessage<E>>,
|
||||
/// Stores all `NetworkMessage`s received from `network_recv`. (e.g. outgoing RPC requests)
|
||||
network_rx_queue: Vec<NetworkMessage<E>>,
|
||||
/// Receiver for `SyncMessage` from the network
|
||||
sync_rx: mpsc::UnboundedReceiver<SyncMessage<E>>,
|
||||
/// To send `SyncMessage`. For sending RPC responses or block processing results to sync.
|
||||
sync_manager: SyncManager<T>,
|
||||
/// To manipulate sync state and peer connection status
|
||||
network_globals: Arc<NetworkGlobals<E>>,
|
||||
/// Beacon chain harness
|
||||
harness: BeaconChainHarness<EphemeralHarnessType<E>>,
|
||||
/// `rng` for generating test blocks and blobs.
|
||||
rng: XorShiftRng,
|
||||
fork_name: ForkName,
|
||||
log: Logger,
|
||||
}
|
||||
1
beacon_node/network/src/sync/tests/range.rs
Normal file
1
beacon_node/network/src/sync/tests/range.rs
Normal file
@@ -0,0 +1 @@
|
||||
|
||||
Reference in New Issue
Block a user