Add BeaconChainHarness::builder (#2707)

## Issue Addressed

NA

## Proposed Changes

This PR is near-identical to https://github.com/sigp/lighthouse/pull/2652, however it is to be merged into `unstable` instead of `merge-f2f`. Please see that PR for reasoning.

I'm making this duplicate PR to merge to `unstable` in an effort to shrink the diff between `unstable` and `merge-f2f` by doing smaller, lead-up PRs.

## Additional Info

NA
This commit is contained in:
Paul Hauner 2021-10-14 02:58:10 +00:00
parent 0a77d783a4
commit e2d09bb8ac
23 changed files with 449 additions and 438 deletions

View File

@ -280,19 +280,17 @@ impl<T: EthSpec> SnapshotCache<T> {
mod test { mod test {
use super::*; use super::*;
use crate::test_utils::{BeaconChainHarness, EphemeralHarnessType}; use crate::test_utils::{BeaconChainHarness, EphemeralHarnessType};
use store::StoreConfig;
use types::{ use types::{
test_utils::generate_deterministic_keypair, BeaconBlock, Epoch, MainnetEthSpec, test_utils::generate_deterministic_keypair, BeaconBlock, Epoch, MainnetEthSpec,
SignedBeaconBlock, Slot, SignedBeaconBlock, Slot,
}; };
fn get_harness() -> BeaconChainHarness<EphemeralHarnessType<MainnetEthSpec>> { fn get_harness() -> BeaconChainHarness<EphemeralHarnessType<MainnetEthSpec>> {
let harness = BeaconChainHarness::new_with_store_config( let harness = BeaconChainHarness::builder(MainnetEthSpec)
MainnetEthSpec, .default_spec()
None, .deterministic_keypairs(1)
types::test_utils::generate_deterministic_keypairs(1), .fresh_ephemeral_store()
StoreConfig::default(), .build();
);
harness.advance_slot(); harness.advance_slot();

View File

@ -21,6 +21,7 @@ use rand::rngs::StdRng;
use rand::Rng; use rand::Rng;
use rand::SeedableRng; use rand::SeedableRng;
use rayon::prelude::*; use rayon::prelude::*;
use slog::Logger;
use slot_clock::TestingSlotClock; use slot_clock::TestingSlotClock;
use state_processing::state_advance::complete_state_advance; use state_processing::state_advance::complete_state_advance;
use std::borrow::Cow; use std::borrow::Cow;
@ -61,6 +62,12 @@ pub type BaseHarnessType<TEthSpec, THotStore, TColdStore> =
pub type DiskHarnessType<E> = BaseHarnessType<E, LevelDB<E>, LevelDB<E>>; pub type DiskHarnessType<E> = BaseHarnessType<E, LevelDB<E>, LevelDB<E>>;
pub type EphemeralHarnessType<E> = BaseHarnessType<E, MemoryStore<E>, MemoryStore<E>>; pub type EphemeralHarnessType<E> = BaseHarnessType<E, MemoryStore<E>, MemoryStore<E>>;
type BoxedMutator<E, Hot, Cold> = Box<
dyn FnOnce(
BeaconChainBuilder<BaseHarnessType<E, Hot, Cold>>,
) -> BeaconChainBuilder<BaseHarnessType<E, Hot, Cold>>,
>;
pub type AddBlocksResult<E> = ( pub type AddBlocksResult<E> = (
HashMap<Slot, SignedBeaconBlockHash>, HashMap<Slot, SignedBeaconBlockHash>,
HashMap<Slot, BeaconStateHash>, HashMap<Slot, BeaconStateHash>,
@ -134,6 +141,216 @@ pub fn test_spec<E: EthSpec>() -> ChainSpec {
spec spec
} }
pub struct Builder<T: BeaconChainTypes> {
eth_spec_instance: T::EthSpec,
spec: Option<ChainSpec>,
validator_keypairs: Option<Vec<Keypair>>,
chain_config: Option<ChainConfig>,
store_config: Option<StoreConfig>,
#[allow(clippy::type_complexity)]
store: Option<Arc<HotColdDB<T::EthSpec, T::HotStore, T::ColdStore>>>,
initial_mutator: Option<BoxedMutator<T::EthSpec, T::HotStore, T::ColdStore>>,
store_mutator: Option<BoxedMutator<T::EthSpec, T::HotStore, T::ColdStore>>,
log: Logger,
}
impl<E: EthSpec> Builder<EphemeralHarnessType<E>> {
pub fn fresh_ephemeral_store(mut self) -> Self {
let spec = self.spec.as_ref().expect("cannot build without spec");
let validator_keypairs = self
.validator_keypairs
.clone()
.expect("cannot build without validator keypairs");
let store = Arc::new(
HotColdDB::open_ephemeral(
self.store_config.clone().unwrap_or_default(),
spec.clone(),
self.log.clone(),
)
.unwrap(),
);
let mutator = move |builder: BeaconChainBuilder<_>| {
let genesis_state = interop_genesis_state::<E>(
&validator_keypairs,
HARNESS_GENESIS_TIME,
builder.get_spec(),
)
.expect("should generate interop state");
builder
.genesis_state(genesis_state)
.expect("should build state using recent genesis")
};
self.store = Some(store);
self.store_mutator(Box::new(mutator))
}
}
impl<E: EthSpec> Builder<DiskHarnessType<E>> {
/// Disk store, start from genesis.
pub fn fresh_disk_store(mut self, store: Arc<HotColdDB<E, LevelDB<E>, LevelDB<E>>>) -> Self {
let validator_keypairs = self
.validator_keypairs
.clone()
.expect("cannot build without validator keypairs");
let mutator = move |builder: BeaconChainBuilder<_>| {
let genesis_state = interop_genesis_state::<E>(
&validator_keypairs,
HARNESS_GENESIS_TIME,
builder.get_spec(),
)
.expect("should generate interop state");
builder
.genesis_state(genesis_state)
.expect("should build state using recent genesis")
};
self.store = Some(store);
self.store_mutator(Box::new(mutator))
}
/// Disk store, resume.
pub fn resumed_disk_store(mut self, store: Arc<HotColdDB<E, LevelDB<E>, LevelDB<E>>>) -> Self {
let mutator = move |builder: BeaconChainBuilder<_>| {
builder
.resume_from_db()
.expect("should resume from database")
};
self.store = Some(store);
self.store_mutator(Box::new(mutator))
}
}
impl<E, Hot, Cold> Builder<BaseHarnessType<E, Hot, Cold>>
where
E: EthSpec,
Hot: ItemStore<E>,
Cold: ItemStore<E>,
{
pub fn new(eth_spec_instance: E) -> Self {
Self {
eth_spec_instance,
spec: None,
validator_keypairs: None,
chain_config: None,
store_config: None,
store: None,
initial_mutator: None,
store_mutator: None,
log: test_logger(),
}
}
pub fn deterministic_keypairs(self, num_keypairs: usize) -> Self {
self.keypairs(types::test_utils::generate_deterministic_keypairs(
num_keypairs,
))
}
pub fn keypairs(mut self, validator_keypairs: Vec<Keypair>) -> Self {
self.validator_keypairs = Some(validator_keypairs);
self
}
pub fn default_spec(self) -> Self {
self.spec_or_default(None)
}
pub fn spec(self, spec: ChainSpec) -> Self {
self.spec_or_default(Some(spec))
}
pub fn spec_or_default(mut self, spec: Option<ChainSpec>) -> Self {
self.spec = Some(spec.unwrap_or_else(test_spec::<E>));
self
}
/// This mutator will be run before the `store_mutator`.
pub fn initial_mutator(mut self, mutator: BoxedMutator<E, Hot, Cold>) -> Self {
assert!(
self.initial_mutator.is_none(),
"initial mutator already set"
);
self.initial_mutator = Some(mutator);
self
}
/// This mutator will be run after the `initial_mutator`.
pub fn store_mutator(mut self, mutator: BoxedMutator<E, Hot, Cold>) -> Self {
assert!(self.store_mutator.is_none(), "store mutator already set");
self.store_mutator = Some(mutator);
self
}
/// Purposefully replace the `store_mutator`.
pub fn override_store_mutator(mut self, mutator: BoxedMutator<E, Hot, Cold>) -> Self {
assert!(self.store_mutator.is_some(), "store mutator not set");
self.store_mutator = Some(mutator);
self
}
pub fn chain_config(mut self, chain_config: ChainConfig) -> Self {
self.chain_config = Some(chain_config);
self
}
pub fn build(self) -> BeaconChainHarness<BaseHarnessType<E, Hot, Cold>> {
let (shutdown_tx, shutdown_receiver) = futures::channel::mpsc::channel(1);
let log = test_logger();
let spec = self.spec.expect("cannot build without spec");
let validator_keypairs = self
.validator_keypairs
.expect("cannot build without validator keypairs");
let mut builder = BeaconChainBuilder::new(self.eth_spec_instance)
.logger(log.clone())
.custom_spec(spec)
.store(self.store.expect("cannot build without store"))
.store_migrator_config(MigratorConfig::default().blocking())
.dummy_eth1_backend()
.expect("should build dummy backend")
.shutdown_sender(shutdown_tx)
.chain_config(self.chain_config.unwrap_or_default())
.event_handler(Some(ServerSentEventHandler::new_with_capacity(
log.clone(),
5,
)))
.monitor_validators(true, vec![], log);
builder = if let Some(mutator) = self.initial_mutator {
mutator(builder)
} else {
builder
};
builder = if let Some(mutator) = self.store_mutator {
mutator(builder)
} else {
builder
};
// Initialize the slot clock only if it hasn't already been initialized.
builder = if builder.get_slot_clock().is_none() {
builder
.testing_slot_clock(HARNESS_SLOT_TIME)
.expect("should configure testing slot clock")
} else {
builder
};
let chain = builder.build().expect("should build");
BeaconChainHarness {
spec: chain.spec.clone(),
chain: Arc::new(chain),
validator_keypairs,
shutdown_receiver,
rng: make_rng(),
}
}
}
/// A testing harness which can instantiate a `BeaconChain` and populate it with blocks and /// A testing harness which can instantiate a `BeaconChain` and populate it with blocks and
/// attestations. /// attestations.
/// ///
@ -158,205 +375,14 @@ pub type HarnessSyncContributions<E> = Vec<(
Option<SignedContributionAndProof<E>>, Option<SignedContributionAndProof<E>>,
)>; )>;
impl<E: EthSpec> BeaconChainHarness<EphemeralHarnessType<E>> {
pub fn new(
eth_spec_instance: E,
spec: Option<ChainSpec>,
validator_keypairs: Vec<Keypair>,
) -> Self {
Self::new_with_store_config(
eth_spec_instance,
spec,
validator_keypairs,
StoreConfig::default(),
)
}
pub fn new_with_store_config(
eth_spec_instance: E,
spec: Option<ChainSpec>,
validator_keypairs: Vec<Keypair>,
config: StoreConfig,
) -> Self {
Self::new_with_chain_config(
eth_spec_instance,
spec,
validator_keypairs,
config,
ChainConfig::default(),
)
}
pub fn new_with_chain_config(
eth_spec_instance: E,
spec: Option<ChainSpec>,
validator_keypairs: Vec<Keypair>,
store_config: StoreConfig,
chain_config: ChainConfig,
) -> Self {
Self::ephemeral_with_mutator(
eth_spec_instance,
spec,
validator_keypairs,
store_config,
chain_config,
|x| x,
)
}
pub fn ephemeral_with_mutator(
eth_spec_instance: E,
spec: Option<ChainSpec>,
validator_keypairs: Vec<Keypair>,
store_config: StoreConfig,
chain_config: ChainConfig,
mutator: impl FnOnce(
BeaconChainBuilder<EphemeralHarnessType<E>>,
) -> BeaconChainBuilder<EphemeralHarnessType<E>>,
) -> Self {
let spec = spec.unwrap_or_else(test_spec::<E>);
let log = test_logger();
let store = Arc::new(HotColdDB::open_ephemeral(store_config, spec.clone(), log).unwrap());
Self::new_with_mutator(
eth_spec_instance,
spec,
store,
validator_keypairs.clone(),
chain_config,
|mut builder| {
builder = mutator(builder);
let genesis_state = interop_genesis_state::<E>(
&validator_keypairs,
HARNESS_GENESIS_TIME,
builder.get_spec(),
)
.expect("should generate interop state");
builder
.genesis_state(genesis_state)
.expect("should build state using recent genesis")
},
)
}
}
impl<E: EthSpec> BeaconChainHarness<DiskHarnessType<E>> {
/// Disk store, start from genesis.
pub fn new_with_disk_store(
eth_spec_instance: E,
spec: Option<ChainSpec>,
store: Arc<HotColdDB<E, LevelDB<E>, LevelDB<E>>>,
validator_keypairs: Vec<Keypair>,
) -> Self {
let spec = spec.unwrap_or_else(test_spec::<E>);
let chain_config = ChainConfig::default();
Self::new_with_mutator(
eth_spec_instance,
spec,
store,
validator_keypairs.clone(),
chain_config,
|builder| {
let genesis_state = interop_genesis_state::<E>(
&validator_keypairs,
HARNESS_GENESIS_TIME,
builder.get_spec(),
)
.expect("should generate interop state");
builder
.genesis_state(genesis_state)
.expect("should build state using recent genesis")
},
)
}
/// Disk store, resume.
pub fn resume_from_disk_store(
eth_spec_instance: E,
spec: Option<ChainSpec>,
store: Arc<HotColdDB<E, LevelDB<E>, LevelDB<E>>>,
validator_keypairs: Vec<Keypair>,
) -> Self {
let spec = spec.unwrap_or_else(test_spec::<E>);
let chain_config = ChainConfig::default();
Self::new_with_mutator(
eth_spec_instance,
spec,
store,
validator_keypairs,
chain_config,
|builder| {
builder
.resume_from_db()
.expect("should resume from database")
},
)
}
}
impl<E, Hot, Cold> BeaconChainHarness<BaseHarnessType<E, Hot, Cold>> impl<E, Hot, Cold> BeaconChainHarness<BaseHarnessType<E, Hot, Cold>>
where where
E: EthSpec, E: EthSpec,
Hot: ItemStore<E>, Hot: ItemStore<E>,
Cold: ItemStore<E>, Cold: ItemStore<E>,
{ {
/// Generic initializer. pub fn builder(eth_spec_instance: E) -> Builder<BaseHarnessType<E, Hot, Cold>> {
/// Builder::new(eth_spec_instance)
/// This initializer should be able to handle almost any configuration via arguments and the
/// provided `mutator` function. Please do not copy and paste this function.
pub fn new_with_mutator(
eth_spec_instance: E,
spec: ChainSpec,
store: Arc<HotColdDB<E, Hot, Cold>>,
validator_keypairs: Vec<Keypair>,
chain_config: ChainConfig,
mutator: impl FnOnce(
BeaconChainBuilder<BaseHarnessType<E, Hot, Cold>>,
) -> BeaconChainBuilder<BaseHarnessType<E, Hot, Cold>>,
) -> Self {
let (shutdown_tx, shutdown_receiver) = futures::channel::mpsc::channel(1);
let log = test_logger();
let mut builder = BeaconChainBuilder::new(eth_spec_instance)
.logger(log.clone())
.custom_spec(spec)
.store(store)
.store_migrator_config(MigratorConfig::default().blocking())
.dummy_eth1_backend()
.expect("should build dummy backend")
.shutdown_sender(shutdown_tx)
.chain_config(chain_config)
.event_handler(Some(ServerSentEventHandler::new_with_capacity(
log.clone(),
5,
)))
.monitor_validators(true, vec![], log);
// Caller must initialize genesis state.
builder = mutator(builder);
// Initialize the slot clock only if it hasn't already been initialized.
builder = if builder.get_slot_clock().is_none() {
builder
.testing_slot_clock(HARNESS_SLOT_TIME)
.expect("should configure testing slot clock")
} else {
builder
};
let chain = builder.build().expect("should build");
Self {
spec: chain.spec.clone(),
chain: Arc::new(chain),
validator_keypairs,
shutdown_receiver,
rng: make_rng(),
}
} }
pub fn logger(&self) -> &slog::Logger { pub fn logger(&self) -> &slog::Logger {

View File

@ -326,7 +326,7 @@ mod test {
use crate::test_utils::{BeaconChainHarness, EphemeralHarnessType}; use crate::test_utils::{BeaconChainHarness, EphemeralHarnessType};
use logging::test_logger; use logging::test_logger;
use std::sync::Arc; use std::sync::Arc;
use store::{HotColdDB, StoreConfig}; use store::HotColdDB;
use tempfile::tempdir; use tempfile::tempdir;
use types::{ use types::{
test_utils::generate_deterministic_keypair, BeaconState, EthSpec, Keypair, MainnetEthSpec, test_utils::generate_deterministic_keypair, BeaconState, EthSpec, Keypair, MainnetEthSpec,
@ -336,12 +336,11 @@ mod test {
type T = EphemeralHarnessType<E>; type T = EphemeralHarnessType<E>;
fn get_state(validator_count: usize) -> (BeaconState<E>, Vec<Keypair>) { fn get_state(validator_count: usize) -> (BeaconState<E>, Vec<Keypair>) {
let harness = BeaconChainHarness::new_with_store_config( let harness = BeaconChainHarness::builder(MainnetEthSpec)
MainnetEthSpec, .default_spec()
None, .deterministic_keypairs(validator_count)
types::test_utils::generate_deterministic_keypairs(validator_count), .fresh_ephemeral_store()
StoreConfig::default(), .build();
);
harness.advance_slot(); harness.advance_slot();

View File

@ -5,7 +5,6 @@ extern crate lazy_static;
use beacon_chain::test_utils::{AttestationStrategy, BeaconChainHarness, BlockStrategy}; use beacon_chain::test_utils::{AttestationStrategy, BeaconChainHarness, BlockStrategy};
use beacon_chain::{StateSkipConfig, WhenSlotSkipped}; use beacon_chain::{StateSkipConfig, WhenSlotSkipped};
use store::config::StoreConfig;
use tree_hash::TreeHash; use tree_hash::TreeHash;
use types::{AggregateSignature, EthSpec, Keypair, MainnetEthSpec, RelativeEpoch, Slot}; use types::{AggregateSignature, EthSpec, Keypair, MainnetEthSpec, RelativeEpoch, Slot};
@ -25,12 +24,11 @@ fn produces_attestations() {
let num_blocks_produced = MainnetEthSpec::slots_per_epoch() * 4; let num_blocks_produced = MainnetEthSpec::slots_per_epoch() * 4;
let additional_slots_tested = MainnetEthSpec::slots_per_epoch() * 3; let additional_slots_tested = MainnetEthSpec::slots_per_epoch() * 3;
let harness = BeaconChainHarness::new_with_store_config( let harness = BeaconChainHarness::builder(MainnetEthSpec)
MainnetEthSpec, .default_spec()
None, .keypairs(KEYPAIRS[..].to_vec())
KEYPAIRS[..].to_vec(), .fresh_ephemeral_store()
StoreConfig::default(), .build();
);
let chain = &harness.chain; let chain = &harness.chain;

View File

@ -14,7 +14,6 @@ use int_to_bytes::int_to_bytes32;
use state_processing::{ use state_processing::{
per_block_processing::errors::AttestationValidationError, per_slot_processing, per_block_processing::errors::AttestationValidationError, per_slot_processing,
}; };
use store::config::StoreConfig;
use tree_hash::TreeHash; use tree_hash::TreeHash;
use types::{ use types::{
test_utils::generate_deterministic_keypair, AggregateSignature, Attestation, BeaconStateError, test_utils::generate_deterministic_keypair, AggregateSignature, Attestation, BeaconStateError,
@ -41,12 +40,11 @@ fn get_harness(validator_count: usize) -> BeaconChainHarness<EphemeralHarnessTyp
// not all. // not all.
spec.target_aggregators_per_committee = 4; spec.target_aggregators_per_committee = 4;
let harness = BeaconChainHarness::new_with_store_config( let harness = BeaconChainHarness::builder(MainnetEthSpec)
MainnetEthSpec, .spec(spec)
Some(spec), .keypairs(KEYPAIRS[0..validator_count].to_vec())
KEYPAIRS[0..validator_count].to_vec(), .fresh_ephemeral_store()
StoreConfig::default(), .build();
);
harness.advance_slot(); harness.advance_slot();

View File

@ -6,7 +6,7 @@ extern crate lazy_static;
use beacon_chain::test_utils::{ use beacon_chain::test_utils::{
AttestationStrategy, BeaconChainHarness, BlockStrategy, EphemeralHarnessType, AttestationStrategy, BeaconChainHarness, BlockStrategy, EphemeralHarnessType,
}; };
use beacon_chain::{BeaconSnapshot, BlockError, ChainConfig, ChainSegmentResult}; use beacon_chain::{BeaconSnapshot, BlockError, ChainSegmentResult};
use logging::test_logger; use logging::test_logger;
use slasher::{Config as SlasherConfig, Slasher}; use slasher::{Config as SlasherConfig, Slasher};
use state_processing::{ use state_processing::{
@ -15,7 +15,6 @@ use state_processing::{
per_slot_processing, BlockProcessingError, per_slot_processing, BlockProcessingError,
}; };
use std::sync::Arc; use std::sync::Arc;
use store::config::StoreConfig;
use tempfile::tempdir; use tempfile::tempdir;
use types::{test_utils::generate_deterministic_keypair, *}; use types::{test_utils::generate_deterministic_keypair, *};
@ -53,12 +52,11 @@ fn get_chain_segment() -> Vec<BeaconSnapshot<E>> {
} }
fn get_harness(validator_count: usize) -> BeaconChainHarness<EphemeralHarnessType<E>> { fn get_harness(validator_count: usize) -> BeaconChainHarness<EphemeralHarnessType<E>> {
let harness = BeaconChainHarness::new_with_store_config( let harness = BeaconChainHarness::builder(MainnetEthSpec)
MainnetEthSpec, .default_spec()
None, .keypairs(KEYPAIRS[0..validator_count].to_vec())
KEYPAIRS[0..validator_count].to_vec(), .fresh_ephemeral_store()
StoreConfig::default(), .build();
);
harness.advance_slot(); harness.advance_slot();
@ -841,14 +839,13 @@ fn verify_block_for_gossip_slashing_detection() {
.unwrap(), .unwrap(),
); );
let harness = BeaconChainHarness::ephemeral_with_mutator( let inner_slasher = slasher.clone();
MainnetEthSpec, let harness = BeaconChainHarness::builder(MainnetEthSpec)
None, .default_spec()
KEYPAIRS.to_vec(), .keypairs(KEYPAIRS.to_vec())
StoreConfig::default(), .fresh_ephemeral_store()
ChainConfig::default(), .initial_mutator(Box::new(move |builder| builder.slasher(inner_slasher)))
|builder| builder.slasher(slasher.clone()), .build();
);
harness.advance_slot(); harness.advance_slot();
let state = harness.get_current_state(); let state = harness.get_current_state();
@ -923,13 +920,11 @@ fn add_base_block_to_altair_chain() {
// The Altair fork happens at epoch 1. // The Altair fork happens at epoch 1.
spec.altair_fork_epoch = Some(Epoch::new(1)); spec.altair_fork_epoch = Some(Epoch::new(1));
let harness = BeaconChainHarness::new_with_chain_config( let harness = BeaconChainHarness::builder(MainnetEthSpec)
MainnetEthSpec, .spec(spec)
Some(spec), .keypairs(KEYPAIRS[..].to_vec())
KEYPAIRS[..].to_vec(), .fresh_ephemeral_store()
StoreConfig::default(), .build();
ChainConfig::default(),
);
// Move out of the genesis slot. // Move out of the genesis slot.
harness.advance_slot(); harness.advance_slot();
@ -1042,13 +1037,11 @@ fn add_altair_block_to_base_chain() {
// Altair never happens. // Altair never happens.
spec.altair_fork_epoch = None; spec.altair_fork_epoch = None;
let harness = BeaconChainHarness::new_with_chain_config( let harness = BeaconChainHarness::builder(MainnetEthSpec)
MainnetEthSpec, .spec(spec)
Some(spec), .keypairs(KEYPAIRS[..].to_vec())
KEYPAIRS[..].to_vec(), .fresh_ephemeral_store()
StoreConfig::default(), .build();
ChainConfig::default(),
);
// Move out of the genesis slot. // Move out of the genesis slot.
harness.advance_slot(); harness.advance_slot();

View File

@ -38,12 +38,11 @@ fn get_store(db_path: &TempDir) -> Arc<HotColdDB> {
} }
fn get_harness(store: Arc<HotColdDB>, validator_count: usize) -> TestHarness { fn get_harness(store: Arc<HotColdDB>, validator_count: usize) -> TestHarness {
let harness = BeaconChainHarness::new_with_disk_store( let harness = BeaconChainHarness::builder(MinimalEthSpec)
MinimalEthSpec, .default_spec()
None, .keypairs(KEYPAIRS[0..validator_count].to_vec())
store, .fresh_disk_store(store)
KEYPAIRS[0..validator_count].to_vec(), .build();
);
harness.advance_slot(); harness.advance_slot();
harness harness
} }

View File

@ -61,12 +61,11 @@ fn get_harness(
store: Arc<HotColdDB<E, LevelDB<E>, LevelDB<E>>>, store: Arc<HotColdDB<E, LevelDB<E>, LevelDB<E>>>,
validator_count: usize, validator_count: usize,
) -> TestHarness { ) -> TestHarness {
let harness = BeaconChainHarness::new_with_disk_store( let harness = BeaconChainHarness::builder(MinimalEthSpec)
MinimalEthSpec, .default_spec()
None, .keypairs(KEYPAIRS[0..validator_count].to_vec())
store, .fresh_disk_store(store)
KEYPAIRS[0..validator_count].to_vec(), .build();
);
harness.advance_slot(); harness.advance_slot();
harness harness
} }
@ -365,12 +364,11 @@ fn delete_blocks_and_states() {
let store = get_store(&db_path); let store = get_store(&db_path);
let validators_keypairs = let validators_keypairs =
types::test_utils::generate_deterministic_keypairs(LOW_VALIDATOR_COUNT); types::test_utils::generate_deterministic_keypairs(LOW_VALIDATOR_COUNT);
let harness = BeaconChainHarness::new_with_disk_store( let harness = BeaconChainHarness::builder(MinimalEthSpec)
MinimalEthSpec, .default_spec()
None, .keypairs(validators_keypairs)
store.clone(), .fresh_disk_store(store.clone())
validators_keypairs, .build();
);
let unforked_blocks: u64 = 4 * E::slots_per_epoch(); let unforked_blocks: u64 = 4 * E::slots_per_epoch();
@ -492,8 +490,11 @@ fn multi_epoch_fork_valid_blocks_test(
let store = get_store(&db_path); let store = get_store(&db_path);
let validators_keypairs = let validators_keypairs =
types::test_utils::generate_deterministic_keypairs(LOW_VALIDATOR_COUNT); types::test_utils::generate_deterministic_keypairs(LOW_VALIDATOR_COUNT);
let harness = let harness = BeaconChainHarness::builder(MinimalEthSpec)
BeaconChainHarness::new_with_disk_store(MinimalEthSpec, None, store, validators_keypairs); .default_spec()
.keypairs(validators_keypairs)
.fresh_disk_store(store)
.build();
let num_fork1_blocks: u64 = num_fork1_blocks_.try_into().unwrap(); let num_fork1_blocks: u64 = num_fork1_blocks_.try_into().unwrap();
let num_fork2_blocks: u64 = num_fork2_blocks_.try_into().unwrap(); let num_fork2_blocks: u64 = num_fork2_blocks_.try_into().unwrap();
@ -783,7 +784,11 @@ fn prunes_abandoned_fork_between_two_finalized_checkpoints() {
let validators_keypairs = types::test_utils::generate_deterministic_keypairs(VALIDATOR_COUNT); let validators_keypairs = types::test_utils::generate_deterministic_keypairs(VALIDATOR_COUNT);
let honest_validators: Vec<usize> = (0..HONEST_VALIDATOR_COUNT).collect(); let honest_validators: Vec<usize> = (0..HONEST_VALIDATOR_COUNT).collect();
let adversarial_validators: Vec<usize> = (HONEST_VALIDATOR_COUNT..VALIDATOR_COUNT).collect(); let adversarial_validators: Vec<usize> = (HONEST_VALIDATOR_COUNT..VALIDATOR_COUNT).collect();
let rig = BeaconChainHarness::new(MinimalEthSpec, None, validators_keypairs); let rig = BeaconChainHarness::builder(MinimalEthSpec)
.default_spec()
.keypairs(validators_keypairs)
.fresh_ephemeral_store()
.build();
let slots_per_epoch = rig.slots_per_epoch(); let slots_per_epoch = rig.slots_per_epoch();
let (mut state, state_root) = rig.get_current_state_and_root(); let (mut state, state_root) = rig.get_current_state_and_root();
@ -888,7 +893,11 @@ fn pruning_does_not_touch_abandoned_block_shared_with_canonical_chain() {
let validators_keypairs = types::test_utils::generate_deterministic_keypairs(VALIDATOR_COUNT); let validators_keypairs = types::test_utils::generate_deterministic_keypairs(VALIDATOR_COUNT);
let honest_validators: Vec<usize> = (0..HONEST_VALIDATOR_COUNT).collect(); let honest_validators: Vec<usize> = (0..HONEST_VALIDATOR_COUNT).collect();
let adversarial_validators: Vec<usize> = (HONEST_VALIDATOR_COUNT..VALIDATOR_COUNT).collect(); let adversarial_validators: Vec<usize> = (HONEST_VALIDATOR_COUNT..VALIDATOR_COUNT).collect();
let rig = BeaconChainHarness::new(MinimalEthSpec, None, validators_keypairs); let rig = BeaconChainHarness::builder(MinimalEthSpec)
.default_spec()
.keypairs(validators_keypairs)
.fresh_ephemeral_store()
.build();
let slots_per_epoch = rig.slots_per_epoch(); let slots_per_epoch = rig.slots_per_epoch();
let (state, state_root) = rig.get_current_state_and_root(); let (state, state_root) = rig.get_current_state_and_root();
@ -1013,7 +1022,11 @@ fn pruning_does_not_touch_blocks_prior_to_finalization() {
let validators_keypairs = types::test_utils::generate_deterministic_keypairs(VALIDATOR_COUNT); let validators_keypairs = types::test_utils::generate_deterministic_keypairs(VALIDATOR_COUNT);
let honest_validators: Vec<usize> = (0..HONEST_VALIDATOR_COUNT).collect(); let honest_validators: Vec<usize> = (0..HONEST_VALIDATOR_COUNT).collect();
let adversarial_validators: Vec<usize> = (HONEST_VALIDATOR_COUNT..VALIDATOR_COUNT).collect(); let adversarial_validators: Vec<usize> = (HONEST_VALIDATOR_COUNT..VALIDATOR_COUNT).collect();
let rig = BeaconChainHarness::new(MinimalEthSpec, None, validators_keypairs); let rig = BeaconChainHarness::builder(MinimalEthSpec)
.default_spec()
.keypairs(validators_keypairs)
.fresh_ephemeral_store()
.build();
let slots_per_epoch = rig.slots_per_epoch(); let slots_per_epoch = rig.slots_per_epoch();
let (mut state, state_root) = rig.get_current_state_and_root(); let (mut state, state_root) = rig.get_current_state_and_root();
@ -1103,7 +1116,11 @@ fn prunes_fork_growing_past_youngest_finalized_checkpoint() {
let validators_keypairs = types::test_utils::generate_deterministic_keypairs(VALIDATOR_COUNT); let validators_keypairs = types::test_utils::generate_deterministic_keypairs(VALIDATOR_COUNT);
let honest_validators: Vec<usize> = (0..HONEST_VALIDATOR_COUNT).collect(); let honest_validators: Vec<usize> = (0..HONEST_VALIDATOR_COUNT).collect();
let adversarial_validators: Vec<usize> = (HONEST_VALIDATOR_COUNT..VALIDATOR_COUNT).collect(); let adversarial_validators: Vec<usize> = (HONEST_VALIDATOR_COUNT..VALIDATOR_COUNT).collect();
let rig = BeaconChainHarness::new(MinimalEthSpec, None, validators_keypairs); let rig = BeaconChainHarness::builder(MinimalEthSpec)
.default_spec()
.keypairs(validators_keypairs)
.fresh_ephemeral_store()
.build();
let (state, state_root) = rig.get_current_state_and_root(); let (state, state_root) = rig.get_current_state_and_root();
// Fill up 0th epoch with canonical chain blocks // Fill up 0th epoch with canonical chain blocks
@ -1241,7 +1258,11 @@ fn prunes_skipped_slots_states() {
let validators_keypairs = types::test_utils::generate_deterministic_keypairs(VALIDATOR_COUNT); let validators_keypairs = types::test_utils::generate_deterministic_keypairs(VALIDATOR_COUNT);
let honest_validators: Vec<usize> = (0..HONEST_VALIDATOR_COUNT).collect(); let honest_validators: Vec<usize> = (0..HONEST_VALIDATOR_COUNT).collect();
let adversarial_validators: Vec<usize> = (HONEST_VALIDATOR_COUNT..VALIDATOR_COUNT).collect(); let adversarial_validators: Vec<usize> = (HONEST_VALIDATOR_COUNT..VALIDATOR_COUNT).collect();
let rig = BeaconChainHarness::new(MinimalEthSpec, None, validators_keypairs); let rig = BeaconChainHarness::builder(MinimalEthSpec)
.default_spec()
.keypairs(validators_keypairs)
.fresh_ephemeral_store()
.build();
let (state, state_root) = rig.get_current_state_and_root(); let (state, state_root) = rig.get_current_state_and_root();
let canonical_slots_zeroth_epoch: Vec<Slot> = let canonical_slots_zeroth_epoch: Vec<Slot> =
@ -1360,7 +1381,11 @@ fn finalizes_non_epoch_start_slot() {
let validators_keypairs = types::test_utils::generate_deterministic_keypairs(VALIDATOR_COUNT); let validators_keypairs = types::test_utils::generate_deterministic_keypairs(VALIDATOR_COUNT);
let honest_validators: Vec<usize> = (0..HONEST_VALIDATOR_COUNT).collect(); let honest_validators: Vec<usize> = (0..HONEST_VALIDATOR_COUNT).collect();
let adversarial_validators: Vec<usize> = (HONEST_VALIDATOR_COUNT..VALIDATOR_COUNT).collect(); let adversarial_validators: Vec<usize> = (HONEST_VALIDATOR_COUNT..VALIDATOR_COUNT).collect();
let rig = BeaconChainHarness::new(MinimalEthSpec, None, validators_keypairs); let rig = BeaconChainHarness::builder(MinimalEthSpec)
.default_spec()
.keypairs(validators_keypairs)
.fresh_ephemeral_store()
.build();
let (state, state_root) = rig.get_current_state_and_root(); let (state, state_root) = rig.get_current_state_and_root();
let canonical_slots_zeroth_epoch: Vec<Slot> = let canonical_slots_zeroth_epoch: Vec<Slot> =
@ -1923,12 +1948,11 @@ fn finalizes_after_resuming_from_db() {
let db_path = tempdir().unwrap(); let db_path = tempdir().unwrap();
let store = get_store(&db_path); let store = get_store(&db_path);
let harness = BeaconChainHarness::new_with_disk_store( let harness = BeaconChainHarness::builder(MinimalEthSpec)
MinimalEthSpec, .default_spec()
None, .keypairs(KEYPAIRS[0..validator_count].to_vec())
store.clone(), .fresh_disk_store(store.clone())
KEYPAIRS[0..validator_count].to_vec(), .build();
);
harness.advance_slot(); harness.advance_slot();
@ -1967,12 +1991,11 @@ fn finalizes_after_resuming_from_db() {
let original_chain = harness.chain; let original_chain = harness.chain;
let resumed_harness = BeaconChainHarness::resume_from_disk_store( let resumed_harness = BeaconChainHarness::builder(MinimalEthSpec)
MinimalEthSpec, .default_spec()
None, .keypairs(KEYPAIRS[0..validator_count].to_vec())
store, .resumed_disk_store(store)
KEYPAIRS[0..validator_count].to_vec(), .build();
);
assert_chains_pretty_much_the_same(&original_chain, &resumed_harness.chain); assert_chains_pretty_much_the_same(&original_chain, &resumed_harness.chain);
@ -2037,22 +2060,20 @@ fn revert_minority_fork_on_resume() {
// Chain with no fork epoch configured. // Chain with no fork epoch configured.
let db_path1 = tempdir().unwrap(); let db_path1 = tempdir().unwrap();
let store1 = get_store_with_spec(&db_path1, spec1.clone()); let store1 = get_store_with_spec(&db_path1, spec1.clone());
let harness1 = BeaconChainHarness::new_with_disk_store( let harness1 = BeaconChainHarness::builder(MinimalEthSpec)
MinimalEthSpec, .spec(spec1)
Some(spec1), .keypairs(KEYPAIRS[0..validator_count].to_vec())
store1, .fresh_disk_store(store1)
KEYPAIRS[0..validator_count].to_vec(), .build();
);
// Chain with fork epoch configured. // Chain with fork epoch configured.
let db_path2 = tempdir().unwrap(); let db_path2 = tempdir().unwrap();
let store2 = get_store_with_spec(&db_path2, spec2.clone()); let store2 = get_store_with_spec(&db_path2, spec2.clone());
let harness2 = BeaconChainHarness::new_with_disk_store( let harness2 = BeaconChainHarness::builder(MinimalEthSpec)
MinimalEthSpec, .spec(spec2.clone())
Some(spec2.clone()), .keypairs(KEYPAIRS[0..validator_count].to_vec())
store2, .fresh_disk_store(store2)
KEYPAIRS[0..validator_count].to_vec(), .build();
);
// Apply the same blocks to both chains initially. // Apply the same blocks to both chains initially.
let mut state = harness1.get_current_state(); let mut state = harness1.get_current_state();
@ -2130,13 +2151,12 @@ fn revert_minority_fork_on_resume() {
// the beacon chain builder loads the head block. // the beacon chain builder loads the head block.
drop(harness1); drop(harness1);
let resume_store = get_store_with_spec(&db_path1, spec2.clone()); let resume_store = get_store_with_spec(&db_path1, spec2.clone());
let resumed_harness = BeaconChainHarness::new_with_mutator(
MinimalEthSpec, let resumed_harness = BeaconChainHarness::builder(MinimalEthSpec)
spec2, .spec(spec2)
resume_store, .keypairs(KEYPAIRS[0..validator_count].to_vec())
KEYPAIRS[0..validator_count].to_vec(), .resumed_disk_store(resume_store)
ChainConfig::default(), .override_store_mutator(Box::new(move |mut builder| {
|mut builder| {
builder = builder builder = builder
.resume_from_db() .resume_from_db()
.unwrap() .unwrap()
@ -2147,8 +2167,8 @@ fn revert_minority_fork_on_resume() {
.unwrap() .unwrap()
.set_slot(end_slot.as_u64()); .set_slot(end_slot.as_u64());
builder builder
}, }))
); .build();
// Head should now be just before the fork. // Head should now be just before the fork.
resumed_harness.chain.fork_choice().unwrap(); resumed_harness.chain.fork_choice().unwrap();

View File

@ -28,11 +28,11 @@ lazy_static! {
fn get_harness(validator_count: usize) -> BeaconChainHarness<EphemeralHarnessType<E>> { fn get_harness(validator_count: usize) -> BeaconChainHarness<EphemeralHarnessType<E>> {
let mut spec = E::default_spec(); let mut spec = E::default_spec();
spec.altair_fork_epoch = Some(Epoch::new(0)); spec.altair_fork_epoch = Some(Epoch::new(0));
let harness = BeaconChainHarness::new( let harness = BeaconChainHarness::builder(MainnetEthSpec)
MainnetEthSpec, .spec(spec)
Some(spec), .keypairs(KEYPAIRS[0..validator_count].to_vec())
KEYPAIRS[0..validator_count].to_vec(), .fresh_ephemeral_store()
); .build();
harness.advance_slot(); harness.advance_slot();

View File

@ -15,7 +15,6 @@ use operation_pool::PersistedOperationPool;
use state_processing::{ use state_processing::{
per_slot_processing, per_slot_processing::Error as SlotProcessingError, EpochProcessingError, per_slot_processing, per_slot_processing::Error as SlotProcessingError, EpochProcessingError,
}; };
use store::config::StoreConfig;
use types::{BeaconStateError, EthSpec, Hash256, Keypair, MinimalEthSpec, RelativeEpoch, Slot}; use types::{BeaconStateError, EthSpec, Hash256, Keypair, MinimalEthSpec, RelativeEpoch, Slot};
// Should ideally be divisible by 3. // Should ideally be divisible by 3.
@ -27,12 +26,11 @@ lazy_static! {
} }
fn get_harness(validator_count: usize) -> BeaconChainHarness<EphemeralHarnessType<MinimalEthSpec>> { fn get_harness(validator_count: usize) -> BeaconChainHarness<EphemeralHarnessType<MinimalEthSpec>> {
let harness = BeaconChainHarness::new_with_store_config( let harness = BeaconChainHarness::builder(MinimalEthSpec)
MinimalEthSpec, .default_spec()
None, .keypairs(KEYPAIRS[0..validator_count].to_vec())
KEYPAIRS[0..validator_count].to_vec(), .fresh_ephemeral_store()
StoreConfig::default(), .build();
);
harness.advance_slot(); harness.advance_slot();

View File

@ -18,7 +18,7 @@ use std::net::{Ipv4Addr, SocketAddr};
use std::sync::Arc; use std::sync::Arc;
use std::time::Duration; use std::time::Duration;
use tokio::sync::{mpsc, oneshot}; use tokio::sync::{mpsc, oneshot};
use types::{test_utils::generate_deterministic_keypairs, ChainSpec, EthSpec}; use types::{ChainSpec, EthSpec};
pub const TCP_PORT: u16 = 42; pub const TCP_PORT: u16 = 42;
pub const UDP_PORT: u16 = 42; pub const UDP_PORT: u16 = 42;
@ -47,11 +47,11 @@ pub struct ApiServer<E: EthSpec, SFut: Future<Output = ()>> {
impl<E: EthSpec> InteractiveTester<E> { impl<E: EthSpec> InteractiveTester<E> {
pub async fn new(spec: Option<ChainSpec>, validator_count: usize) -> Self { pub async fn new(spec: Option<ChainSpec>, validator_count: usize) -> Self {
let harness = BeaconChainHarness::new( let harness = BeaconChainHarness::builder(E::default())
E::default(), .spec_or_default(spec)
spec, .deterministic_keypairs(validator_count)
generate_deterministic_keypairs(validator_count), .fresh_ephemeral_store()
); .build();
let ApiServer { let ApiServer {
server, server,

View File

@ -21,8 +21,8 @@ use tokio::sync::{mpsc, oneshot};
use tokio::time::Duration; use tokio::time::Duration;
use tree_hash::TreeHash; use tree_hash::TreeHash;
use types::{ use types::{
test_utils::generate_deterministic_keypairs, AggregateSignature, BeaconState, BitList, Domain, AggregateSignature, BeaconState, BitList, Domain, EthSpec, Hash256, Keypair, MainnetEthSpec,
EthSpec, Hash256, Keypair, MainnetEthSpec, RelativeEpoch, SelectionProof, SignedRoot, Slot, RelativeEpoch, SelectionProof, SignedRoot, Slot,
}; };
type E = MainnetEthSpec; type E = MainnetEthSpec;
@ -71,11 +71,11 @@ impl ApiTester {
} }
pub async fn new_from_spec(spec: ChainSpec) -> Self { pub async fn new_from_spec(spec: ChainSpec) -> Self {
let harness = BeaconChainHarness::new( let harness = BeaconChainHarness::builder(MainnetEthSpec)
MainnetEthSpec, .spec(spec.clone())
Some(spec.clone()), .deterministic_keypairs(VALIDATOR_COUNT)
generate_deterministic_keypairs(VALIDATOR_COUNT), .fresh_ephemeral_store()
); .build();
harness.advance_slot(); harness.advance_slot();
@ -214,11 +214,11 @@ impl ApiTester {
} }
pub async fn new_from_genesis() -> Self { pub async fn new_from_genesis() -> Self {
let harness = BeaconChainHarness::new( let harness = BeaconChainHarness::builder(MainnetEthSpec)
MainnetEthSpec, .default_spec()
None, .deterministic_keypairs(VALIDATOR_COUNT)
generate_deterministic_keypairs(VALIDATOR_COUNT), .fresh_ephemeral_store()
); .build();
harness.advance_slot(); harness.advance_slot();

View File

@ -23,8 +23,8 @@ use std::time::Duration;
use tokio::runtime::Runtime; use tokio::runtime::Runtime;
use tokio::sync::mpsc; use tokio::sync::mpsc;
use types::{ use types::{
test_utils::generate_deterministic_keypairs, Attestation, AttesterSlashing, EthSpec, Attestation, AttesterSlashing, EthSpec, MainnetEthSpec, ProposerSlashing, SignedBeaconBlock,
MainnetEthSpec, ProposerSlashing, SignedBeaconBlock, SignedVoluntaryExit, SubnetId, SignedVoluntaryExit, SubnetId,
}; };
type E = MainnetEthSpec; type E = MainnetEthSpec;
@ -75,11 +75,11 @@ impl TestRig {
let mut spec = E::default_spec(); let mut spec = E::default_spec();
spec.shard_committee_period = 2; spec.shard_committee_period = 2;
let harness = BeaconChainHarness::new( let harness = BeaconChainHarness::builder(MainnetEthSpec)
MainnetEthSpec, .spec(spec)
Some(spec), .deterministic_keypairs(VALIDATOR_COUNT)
generate_deterministic_keypairs(VALIDATOR_COUNT), .fresh_ephemeral_store()
); .build();
harness.advance_slot(); harness.advance_slot();

View File

@ -9,9 +9,8 @@ mod tests {
use sloggers::{null::NullLoggerBuilder, Build}; use sloggers::{null::NullLoggerBuilder, Build};
use std::str::FromStr; use std::str::FromStr;
use std::sync::Arc; use std::sync::Arc;
use store::config::StoreConfig;
use tokio::runtime::Runtime; use tokio::runtime::Runtime;
use types::{test_utils::generate_deterministic_keypairs, MinimalEthSpec}; use types::MinimalEthSpec;
fn get_logger(actual_log: bool) -> Logger { fn get_logger(actual_log: bool) -> Logger {
if actual_log { if actual_log {
@ -35,12 +34,11 @@ mod tests {
fn test_dht_persistence() { fn test_dht_persistence() {
let log = get_logger(false); let log = get_logger(false);
let beacon_chain = BeaconChainHarness::new_with_store_config( let beacon_chain = BeaconChainHarness::builder(MinimalEthSpec)
MinimalEthSpec, .default_spec()
None, .deterministic_keypairs(8)
generate_deterministic_keypairs(8), .fresh_ephemeral_store()
StoreConfig::default(), .build()
)
.chain; .chain;
let store = beacon_chain.store.clone(); let store = beacon_chain.store.clone();

View File

@ -632,8 +632,11 @@ mod release_tests {
validator_count: usize, validator_count: usize,
spec: Option<ChainSpec>, spec: Option<ChainSpec>,
) -> BeaconChainHarness<EphemeralHarnessType<E>> { ) -> BeaconChainHarness<EphemeralHarnessType<E>> {
let harness = let harness = BeaconChainHarness::builder(E::default())
BeaconChainHarness::new(E::default(), spec, KEYPAIRS[0..validator_count].to_vec()); .spec_or_default(spec)
.keypairs(KEYPAIRS[0..validator_count].to_vec())
.fresh_ephemeral_store()
.build();
harness.advance_slot(); harness.advance_slot();

View File

@ -371,18 +371,16 @@ mod test {
use super::*; use super::*;
use crate::HotColdDB; use crate::HotColdDB;
use crate::StoreConfig as Config; use crate::StoreConfig as Config;
use beacon_chain::store::StoreConfig;
use beacon_chain::test_utils::BeaconChainHarness; use beacon_chain::test_utils::BeaconChainHarness;
use beacon_chain::types::{ChainSpec, Keypair, MainnetEthSpec}; use beacon_chain::types::{ChainSpec, MainnetEthSpec};
use sloggers::{null::NullLoggerBuilder, Build}; use sloggers::{null::NullLoggerBuilder, Build};
fn get_state<T: EthSpec>() -> BeaconState<T> { fn get_state<T: EthSpec>() -> BeaconState<T> {
let harness = BeaconChainHarness::new_with_store_config( let harness = BeaconChainHarness::builder(T::default())
T::default(), .default_spec()
None, .deterministic_keypairs(1)
vec![Keypair::random()], .fresh_ephemeral_store()
StoreConfig::default(), .build();
);
harness.advance_slot(); harness.advance_slot();
harness.get_current_state() harness.get_current_state()
} }

View File

@ -14,11 +14,10 @@ use fork_choice::{
ForkChoiceStore, InvalidAttestation, InvalidBlock, QueuedAttestation, ForkChoiceStore, InvalidAttestation, InvalidBlock, QueuedAttestation,
SAFE_SLOTS_TO_UPDATE_JUSTIFIED, SAFE_SLOTS_TO_UPDATE_JUSTIFIED,
}; };
use store::{MemoryStore, StoreConfig}; use store::MemoryStore;
use types::{ use types::{
test_utils::{generate_deterministic_keypair, generate_deterministic_keypairs}, test_utils::generate_deterministic_keypair, BeaconBlock, BeaconBlockRef, BeaconState,
BeaconBlock, BeaconBlockRef, BeaconState, Checkpoint, Epoch, EthSpec, Hash256, Checkpoint, Epoch, EthSpec, Hash256, IndexedAttestation, MainnetEthSpec, Slot, SubnetId,
IndexedAttestation, MainnetEthSpec, Slot, SubnetId,
}; };
pub type E = MainnetEthSpec; pub type E = MainnetEthSpec;
@ -48,25 +47,23 @@ impl fmt::Debug for ForkChoiceTest {
impl ForkChoiceTest { impl ForkChoiceTest {
/// Creates a new tester. /// Creates a new tester.
pub fn new() -> Self { pub fn new() -> Self {
let harness = BeaconChainHarness::new_with_store_config( let harness = BeaconChainHarness::builder(MainnetEthSpec)
MainnetEthSpec, .default_spec()
None, .deterministic_keypairs(VALIDATOR_COUNT)
generate_deterministic_keypairs(VALIDATOR_COUNT), .fresh_ephemeral_store()
StoreConfig::default(), .build();
);
Self { harness } Self { harness }
} }
/// Creates a new tester with a custom chain config. /// Creates a new tester with a custom chain config.
pub fn new_with_chain_config(chain_config: ChainConfig) -> Self { pub fn new_with_chain_config(chain_config: ChainConfig) -> Self {
let harness = BeaconChainHarness::new_with_chain_config( let harness = BeaconChainHarness::builder(MainnetEthSpec)
MainnetEthSpec, .default_spec()
None, .chain_config(chain_config)
generate_deterministic_keypairs(VALIDATOR_COUNT), .deterministic_keypairs(VALIDATOR_COUNT)
StoreConfig::default(), .fresh_ephemeral_store()
chain_config, .build();
);
Self { harness } Self { harness }
} }

View File

@ -7,7 +7,6 @@ use crate::per_block_processing::errors::{
ProposerSlashingInvalid, ProposerSlashingInvalid,
}; };
use crate::{per_block_processing::process_operations, BlockSignatureStrategy, VerifySignatures}; use crate::{per_block_processing::process_operations, BlockSignatureStrategy, VerifySignatures};
use beacon_chain::store::StoreConfig;
use beacon_chain::test_utils::{BeaconChainHarness, EphemeralHarnessType}; use beacon_chain::test_utils::{BeaconChainHarness, EphemeralHarnessType};
use lazy_static::lazy_static; use lazy_static::lazy_static;
use ssz_types::Bitfield; use ssz_types::Bitfield;
@ -32,12 +31,11 @@ fn get_harness<E: EthSpec>(
// Set the state and block to be in the last slot of the `epoch_offset`th epoch. // Set the state and block to be in the last slot of the `epoch_offset`th epoch.
let last_slot_of_epoch = let last_slot_of_epoch =
(MainnetEthSpec::genesis_epoch() + epoch_offset).end_slot(E::slots_per_epoch()); (MainnetEthSpec::genesis_epoch() + epoch_offset).end_slot(E::slots_per_epoch());
let harness = BeaconChainHarness::new_with_store_config( let harness = BeaconChainHarness::builder(E::default())
E::default(), .default_spec()
None, .keypairs(KEYPAIRS[0..num_validators].to_vec())
KEYPAIRS[0..num_validators].to_vec(), .fresh_ephemeral_store()
StoreConfig::default(), .build();
);
let state = harness.get_current_state(); let state = harness.get_current_state();
if last_slot_of_epoch > Slot::new(0) { if last_slot_of_epoch > Slot::new(0) {
harness.add_attested_blocks_at_slots( harness.add_attested_blocks_at_slots(

View File

@ -1,6 +1,5 @@
#![cfg(test)] #![cfg(test)]
use crate::per_epoch_processing::process_epoch; use crate::per_epoch_processing::process_epoch;
use beacon_chain::store::StoreConfig;
use beacon_chain::test_utils::BeaconChainHarness; use beacon_chain::test_utils::BeaconChainHarness;
use beacon_chain::types::{EthSpec, MinimalEthSpec}; use beacon_chain::types::{EthSpec, MinimalEthSpec};
use bls::Hash256; use bls::Hash256;
@ -11,12 +10,11 @@ use types::Slot;
fn runs_without_error() { fn runs_without_error() {
Builder::from_env(Env::default().default_filter_or("error")).init(); Builder::from_env(Env::default().default_filter_or("error")).init();
let harness = BeaconChainHarness::new_with_store_config( let harness = BeaconChainHarness::builder(MinimalEthSpec)
MinimalEthSpec, .default_spec()
None, .deterministic_keypairs(8)
types::test_utils::generate_deterministic_keypairs(8), .fresh_ephemeral_store()
StoreConfig::default(), .build();
);
harness.advance_slot(); harness.advance_slot();
let spec = MinimalEthSpec::default_spec(); let spec = MinimalEthSpec::default_spec();
@ -55,11 +53,11 @@ mod release_tests {
spec.altair_fork_epoch = Some(Epoch::new(1)); spec.altair_fork_epoch = Some(Epoch::new(1));
let altair_state = { let altair_state = {
let harness = BeaconChainHarness::new( let harness = BeaconChainHarness::builder(MainnetEthSpec)
MainnetEthSpec, .spec(spec.clone())
Some(spec.clone()), .deterministic_keypairs(8)
types::test_utils::generate_deterministic_keypairs(8), .fresh_ephemeral_store()
); .build();
harness.advance_slot(); harness.advance_slot();
@ -113,11 +111,11 @@ mod release_tests {
spec.altair_fork_epoch = None; spec.altair_fork_epoch = None;
let base_state = { let base_state = {
let harness = BeaconChainHarness::new( let harness = BeaconChainHarness::builder(MainnetEthSpec)
MainnetEthSpec, .spec(spec.clone())
Some(spec.clone()), .deterministic_keypairs(8)
types::test_utils::generate_deterministic_keypairs(8), .fresh_ephemeral_store()
); .build();
harness.advance_slot(); harness.advance_slot();

View File

@ -1,4 +1,3 @@
use beacon_chain::store::StoreConfig;
use beacon_chain::test_utils::{BeaconChainHarness, EphemeralHarnessType}; use beacon_chain::test_utils::{BeaconChainHarness, EphemeralHarnessType};
use types::{BeaconState, EthSpec, MainnetEthSpec}; use types::{BeaconState, EthSpec, MainnetEthSpec};
@ -6,12 +5,11 @@ const TREE_HASH_LOOPS: usize = 1_000;
const VALIDATOR_COUNT: usize = 1_000; const VALIDATOR_COUNT: usize = 1_000;
fn get_harness<T: EthSpec>() -> BeaconChainHarness<EphemeralHarnessType<T>> { fn get_harness<T: EthSpec>() -> BeaconChainHarness<EphemeralHarnessType<T>> {
let harness = BeaconChainHarness::new_with_store_config( let harness = BeaconChainHarness::builder(T::default())
T::default(), .default_spec()
None, .deterministic_keypairs(VALIDATOR_COUNT)
types::test_utils::generate_deterministic_keypairs(VALIDATOR_COUNT), .fresh_ephemeral_store()
StoreConfig::default(), .build();
);
harness.advance_slot(); harness.advance_slot();

View File

@ -1,6 +1,5 @@
#![cfg(test)] #![cfg(test)]
use crate::test_utils::*; use crate::test_utils::*;
use beacon_chain::store::StoreConfig;
use beacon_chain::test_utils::{BeaconChainHarness, EphemeralHarnessType}; use beacon_chain::test_utils::{BeaconChainHarness, EphemeralHarnessType};
use beacon_chain::types::*; use beacon_chain::types::*;
use swap_or_not_shuffle::shuffle_list; use swap_or_not_shuffle::shuffle_list;
@ -13,12 +12,11 @@ lazy_static! {
} }
fn get_harness<E: EthSpec>(validator_count: usize) -> BeaconChainHarness<EphemeralHarnessType<E>> { fn get_harness<E: EthSpec>(validator_count: usize) -> BeaconChainHarness<EphemeralHarnessType<E>> {
let harness = BeaconChainHarness::new_with_store_config( let harness = BeaconChainHarness::builder(E::default())
E::default(), .default_spec()
None, .keypairs(KEYPAIRS[0..validator_count].to_vec())
KEYPAIRS[0..validator_count].to_vec(), .fresh_ephemeral_store()
StoreConfig::default(), .build();
);
harness.advance_slot(); harness.advance_slot();
harness harness
} }

View File

@ -1,7 +1,6 @@
#![cfg(test)] #![cfg(test)]
use crate::test_utils::*; use crate::test_utils::*;
use crate::test_utils::{SeedableRng, XorShiftRng}; use crate::test_utils::{SeedableRng, XorShiftRng};
use beacon_chain::store::config::StoreConfig;
use beacon_chain::test_utils::{ use beacon_chain::test_utils::{
interop_genesis_state, test_spec, BeaconChainHarness, EphemeralHarnessType, interop_genesis_state, test_spec, BeaconChainHarness, EphemeralHarnessType,
}; };
@ -29,12 +28,11 @@ fn get_harness<E: EthSpec>(
validator_count: usize, validator_count: usize,
slot: Slot, slot: Slot,
) -> BeaconChainHarness<EphemeralHarnessType<E>> { ) -> BeaconChainHarness<EphemeralHarnessType<E>> {
let harness = BeaconChainHarness::new_with_store_config( let harness = BeaconChainHarness::builder(E::default())
E::default(), .default_spec()
None, .keypairs(KEYPAIRS[0..validator_count].to_vec())
KEYPAIRS[0..validator_count].to_vec(), .fresh_ephemeral_store()
StoreConfig::default(), .build();
);
let skip_to_slot = slot - SLOT_OFFSET; let skip_to_slot = slot - SLOT_OFFSET;
if skip_to_slot > Slot::new(0) { if skip_to_slot > Slot::new(0) {

View File

@ -2,10 +2,7 @@
mod macros; mod macros;
mod exit; mod exit;
use beacon_chain::{ use beacon_chain::test_utils::{BeaconChainHarness, EphemeralHarnessType};
store::StoreConfig,
test_utils::{BeaconChainHarness, EphemeralHarnessType},
};
use lazy_static::lazy_static; use lazy_static::lazy_static;
use ssz::Encode; use ssz::Encode;
use std::env; use std::env;
@ -56,12 +53,11 @@ fn get_harness<E: EthSpec>(
slot: Slot, slot: Slot,
validator_count: usize, validator_count: usize,
) -> BeaconChainHarness<EphemeralHarnessType<E>> { ) -> BeaconChainHarness<EphemeralHarnessType<E>> {
let harness = BeaconChainHarness::new_with_store_config( let harness = BeaconChainHarness::builder(E::default())
E::default(), .default_spec()
None, .keypairs(KEYPAIRS[0..validator_count].to_vec())
KEYPAIRS[0..validator_count].to_vec(), .fresh_ephemeral_store()
StoreConfig::default(), .build();
);
let skip_to_slot = slot - SLOT_OFFSET; let skip_to_slot = slot - SLOT_OFFSET;
if skip_to_slot > Slot::new(0) { if skip_to_slot > Slot::new(0) {
let state = harness.get_current_state(); let state = harness.get_current_state();