mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-15 02:42:38 +00:00
Add more range sync tests (#6872)
Currently we have very poor coverage of range sync with unit tests. With the event driven test framework we could cover much more ground and be confident when modifying the code.
Add two basic cases:
- Happy path, complete a finalized sync for 2 epochs
- Post-PeerDAS case where we start without enough custody peers and later we find enough
⚠️ If you have ideas for more test cases, please let me know! I'll write them
This commit is contained in:
@@ -27,6 +27,7 @@ use beacon_chain::{
|
||||
PayloadVerificationOutcome, PayloadVerificationStatus,
|
||||
};
|
||||
use beacon_processor::WorkEvent;
|
||||
use lighthouse_network::discovery::CombinedKey;
|
||||
use lighthouse_network::{
|
||||
rpc::{RPCError, RequestType, RpcErrorResponse},
|
||||
service::api_types::{
|
||||
@@ -39,18 +40,16 @@ use lighthouse_network::{
|
||||
use slog::info;
|
||||
use slot_clock::{SlotClock, TestingSlotClock};
|
||||
use tokio::sync::mpsc;
|
||||
use types::ForkContext;
|
||||
use types::{
|
||||
data_column_sidecar::ColumnIndex,
|
||||
test_utils::{SeedableRng, TestRandom, XorShiftRng},
|
||||
BeaconState, BeaconStateBase, BlobSidecar, DataColumnSidecar, EthSpec, ForkName, Hash256,
|
||||
MinimalEthSpec as E, SignedBeaconBlock, Slot,
|
||||
BeaconState, BeaconStateBase, BlobSidecar, DataColumnSidecar, EthSpec, ForkContext, ForkName,
|
||||
Hash256, MinimalEthSpec as E, SignedBeaconBlock, Slot,
|
||||
};
|
||||
|
||||
const D: Duration = Duration::new(0, 0);
|
||||
const PARENT_FAIL_TOLERANCE: u8 = SINGLE_BLOCK_LOOKUP_MAX_ATTEMPTS;
|
||||
const SAMPLING_REQUIRED_SUCCESSES: usize = 2;
|
||||
|
||||
type DCByRootIds = Vec<DCByRootId>;
|
||||
type DCByRootId = (SyncRequestId, Vec<ColumnIndex>);
|
||||
|
||||
@@ -117,7 +116,9 @@ impl TestRig {
|
||||
|
||||
let spec = chain.spec.clone();
|
||||
|
||||
let rng = XorShiftRng::from_seed([42; 16]);
|
||||
// deterministic seed
|
||||
let rng = ChaCha20Rng::from_seed([0u8; 32]);
|
||||
|
||||
TestRig {
|
||||
beacon_processor_rx,
|
||||
beacon_processor_rx_queue: vec![],
|
||||
@@ -154,7 +155,7 @@ impl TestRig {
|
||||
}
|
||||
}
|
||||
|
||||
fn test_setup_after_fulu() -> Option<Self> {
|
||||
pub fn test_setup_after_fulu() -> Option<Self> {
|
||||
let r = Self::test_setup();
|
||||
if r.fork_name.fulu_enabled() {
|
||||
Some(r)
|
||||
@@ -369,20 +370,26 @@ impl TestRig {
|
||||
}
|
||||
|
||||
pub fn new_connected_peer(&mut self) -> PeerId {
|
||||
let key = self.determinstic_key();
|
||||
self.network_globals
|
||||
.peers
|
||||
.write()
|
||||
.__add_connected_peer_testing_only(false, &self.harness.spec)
|
||||
.__add_connected_peer_testing_only(false, &self.harness.spec, key)
|
||||
}
|
||||
|
||||
pub fn new_connected_supernode_peer(&mut self) -> PeerId {
|
||||
let key = self.determinstic_key();
|
||||
self.network_globals
|
||||
.peers
|
||||
.write()
|
||||
.__add_connected_peer_testing_only(true, &self.harness.spec)
|
||||
.__add_connected_peer_testing_only(true, &self.harness.spec, key)
|
||||
}
|
||||
|
||||
fn new_connected_peers_for_peerdas(&mut self) {
|
||||
fn determinstic_key(&mut self) -> CombinedKey {
|
||||
k256::ecdsa::SigningKey::random(&mut self.rng).into()
|
||||
}
|
||||
|
||||
pub fn new_connected_peers_for_peerdas(&mut self) {
|
||||
// Enough sampling peers with few columns
|
||||
for _ in 0..100 {
|
||||
self.new_connected_peer();
|
||||
@@ -1113,7 +1120,7 @@ impl TestRig {
|
||||
}
|
||||
|
||||
#[track_caller]
|
||||
fn expect_empty_network(&mut self) {
|
||||
pub fn expect_empty_network(&mut self) {
|
||||
self.drain_network_rx();
|
||||
if !self.network_rx_queue.is_empty() {
|
||||
let n = self.network_rx_queue.len();
|
||||
|
||||
Reference in New Issue
Block a user