Fix range sync tests
This commit is contained in:
parent
e9e198a2b6
commit
6beca6defc
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -596,6 +596,8 @@ dependencies = [
|
||||
"serde_json",
|
||||
"slasher",
|
||||
"slog",
|
||||
"slog-async",
|
||||
"slog-term",
|
||||
"sloggers",
|
||||
"slot_clock",
|
||||
"smallvec",
|
||||
|
@ -68,6 +68,8 @@ hex = "0.4.2"
|
||||
exit-future = "0.2.0"
|
||||
unused_port = {path = "../../common/unused_port"}
|
||||
oneshot_broadcast = { path = "../../common/oneshot_broadcast" }
|
||||
slog-term = "2.6.0"
|
||||
slog-async = "2.5.0"
|
||||
|
||||
[[test]]
|
||||
name = "beacon_chain_tests"
|
||||
|
@ -34,7 +34,9 @@ use rand::Rng;
|
||||
use rand::SeedableRng;
|
||||
use rayon::prelude::*;
|
||||
use sensitive_url::SensitiveUrl;
|
||||
use slog::Logger;
|
||||
use slog::{o, Drain, Logger};
|
||||
use slog_async::Async;
|
||||
use slog_term::{FullFormat, TermDecorator};
|
||||
use slot_clock::{SlotClock, SystemTimeSlotClock, TestingSlotClock};
|
||||
use state_processing::per_block_processing::compute_timestamp_at_slot;
|
||||
use state_processing::{
|
||||
@ -72,7 +74,6 @@ pub type DiskHarnessType<E, TSlotClock> = BaseHarnessType<E, LevelDB<E>, LevelDB
|
||||
|
||||
pub type EphemeralHarnessType<E, TSlotClock> =
|
||||
BaseHarnessType<E, MemoryStore<E>, MemoryStore<E>, TSlotClock>;
|
||||
|
||||
pub type EphemeralTestingSlotClockHarnessType<E> =
|
||||
BaseHarnessType<E, MemoryStore<E>, MemoryStore<E>, TestingSlotClock>;
|
||||
pub type EphemeralSystemTimeSlotClockHarnessType<E> =
|
||||
@ -2129,3 +2130,15 @@ impl<T: BeaconChainTypes> fmt::Debug for BeaconChainHarness<T> {
|
||||
write!(f, "BeaconChainHarness")
|
||||
}
|
||||
}
|
||||
|
||||
pub fn build_log(level: slog::Level, enabled: bool) -> Logger {
|
||||
let decorator = TermDecorator::new().build();
|
||||
let drain = FullFormat::new(decorator).build().fuse();
|
||||
let drain = Async::new(drain).build().fuse();
|
||||
|
||||
if enabled {
|
||||
Logger::root(drain.filter_level(level).fuse(), o!())
|
||||
} else {
|
||||
Logger::root(drain.filter(|_| false).fuse(), o!())
|
||||
}
|
||||
}
|
||||
|
@ -377,25 +377,26 @@ mod tests {
|
||||
use crate::beacon_processor::WorkEvent as BeaconWorkEvent;
|
||||
use crate::service::RequestId;
|
||||
use crate::NetworkMessage;
|
||||
use beacon_chain::{builder::BeaconChainBuilder, test_utils::test_spec};
|
||||
use beacon_chain::{
|
||||
builder::Witness, eth1_chain::CachingEth1Backend, parking_lot::RwLock, EngineState,
|
||||
builder::Witness,
|
||||
eth1_chain::CachingEth1Backend,
|
||||
parking_lot::RwLock,
|
||||
test_utils::{
|
||||
build_log, BeaconChainHarness, EphemeralSystemTimeSlotClockHarnessType as HarnessType,
|
||||
},
|
||||
EngineState,
|
||||
};
|
||||
use lighthouse_network::{
|
||||
rpc::{BlocksByRangeRequest, StatusMessage},
|
||||
NetworkGlobals, Request,
|
||||
};
|
||||
use slog::{o, Drain};
|
||||
use sloggers::{null::NullLoggerBuilder, Build};
|
||||
use slot_clock::{SlotClock, SystemTimeSlotClock};
|
||||
use std::time::{Duration, SystemTime};
|
||||
use slog::o;
|
||||
use slot_clock::SystemTimeSlotClock;
|
||||
use std::{collections::HashSet, sync::Arc};
|
||||
use store::MemoryStore;
|
||||
use tokio::sync::mpsc;
|
||||
use types::{Hash256, MinimalEthSpec as E};
|
||||
|
||||
const SLOT_DURATION_MILLIS: u64 = 400;
|
||||
|
||||
#[derive(Debug)]
|
||||
struct FakeStorage {
|
||||
known_blocks: RwLock<HashSet<Hash256>>,
|
||||
@ -443,18 +444,6 @@ mod tests {
|
||||
type TestBeaconChainType =
|
||||
Witness<SystemTimeSlotClock, CachingEth1Backend<E>, E, MemoryStore<E>, MemoryStore<E>>;
|
||||
|
||||
fn build_log(level: slog::Level, enabled: bool) -> slog::Logger {
|
||||
let decorator = slog_term::TermDecorator::new().build();
|
||||
let drain = slog_term::FullFormat::new(decorator).build().fuse();
|
||||
let drain = slog_async::Async::new(drain).build().fuse();
|
||||
|
||||
if enabled {
|
||||
slog::Logger::root(drain.filter_level(level).fuse(), o!())
|
||||
} else {
|
||||
slog::Logger::root(drain.filter(|_| false).fuse(), o!())
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
struct TestRig {
|
||||
log: slog::Logger,
|
||||
@ -595,37 +584,16 @@ mod tests {
|
||||
}
|
||||
|
||||
fn range(log_enabled: bool) -> (TestRig, RangeSync<TestBeaconChainType, FakeStorage>) {
|
||||
let builder = NullLoggerBuilder;
|
||||
let db_log = builder.build().expect("should build logger");
|
||||
let store = store::HotColdDB::open_ephemeral(
|
||||
store::StoreConfig::default(),
|
||||
E::default_spec(),
|
||||
db_log,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
// Initialise a new beacon chain
|
||||
let chain = Arc::new(
|
||||
BeaconChainBuilder::new(E)
|
||||
.custom_spec(test_spec::<E>())
|
||||
.store(Arc::new(store))
|
||||
.dummy_eth1_backend()
|
||||
.expect("should build dummy backend")
|
||||
.slot_clock(SystemTimeSlotClock::new(
|
||||
types::Slot::new(0),
|
||||
Duration::from_secs(
|
||||
SystemTime::now()
|
||||
.duration_since(SystemTime::UNIX_EPOCH)
|
||||
.unwrap()
|
||||
.as_secs(),
|
||||
),
|
||||
Duration::from_millis(SLOT_DURATION_MILLIS),
|
||||
))
|
||||
.build()
|
||||
.expect("should build"),
|
||||
);
|
||||
|
||||
let log = build_log(slog::Level::Trace, log_enabled);
|
||||
// Initialise a new beacon chain
|
||||
let harness = BeaconChainHarness::<HarnessType<E>>::builder(E::default())
|
||||
.default_spec()
|
||||
.logger(log.clone())
|
||||
.deterministic_keypairs(1)
|
||||
.fresh_ephemeral_store()
|
||||
.build();
|
||||
let chain = harness.chain;
|
||||
|
||||
let fake_store = Arc::new(FakeStorage::default());
|
||||
let (beacon_processor_tx, beacon_processor_rx) = mpsc::channel(10);
|
||||
let range_sync = RangeSync::<TestBeaconChainType, FakeStorage>::new(
|
||||
|
Loading…
Reference in New Issue
Block a user