diff --git a/Cargo.lock b/Cargo.lock index 51e44bc46..7f62628cf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4561,7 +4561,6 @@ dependencies = [ "db-key", "eth2_ssz", "eth2_ssz_derive", - "fork_choice", "itertools 0.9.0", "lazy_static", "leveldb", diff --git a/beacon_node/beacon_chain/src/beacon_chain.rs b/beacon_node/beacon_chain/src/beacon_chain.rs index 9dd19ba53..c7e93b2b2 100644 --- a/beacon_node/beacon_chain/src/beacon_chain.rs +++ b/beacon_node/beacon_chain/src/beacon_chain.rs @@ -203,7 +203,9 @@ pub struct BeaconChain { pub genesis_validators_root: Hash256, /// A state-machine that is updated with information from the network and chooses a canonical /// head block. - pub fork_choice: RwLock, T::EthSpec>>, + pub fork_choice: RwLock< + ForkChoice, T::EthSpec>, + >, /// A handler for events generated by the beacon chain. pub event_handler: T::EventHandler, /// Used to track the heads of the beacon chain. diff --git a/beacon_node/beacon_chain/src/beacon_fork_choice_store.rs b/beacon_node/beacon_chain/src/beacon_fork_choice_store.rs index 376f114e0..0ddedda06 100644 --- a/beacon_node/beacon_chain/src/beacon_fork_choice_store.rs +++ b/beacon_node/beacon_chain/src/beacon_fork_choice_store.rs @@ -9,7 +9,7 @@ use fork_choice::ForkChoiceStore; use ssz_derive::{Decode, Encode}; use std::marker::PhantomData; use std::sync::Arc; -use store::{Error as StoreError, Store}; +use store::{Error as StoreError, HotColdDB, ItemStore}; use types::{ BeaconBlock, BeaconState, BeaconStateError, Checkpoint, EthSpec, Hash256, SignedBeaconBlock, Slot, @@ -158,8 +158,8 @@ impl BalancesCache { /// Implements `fork_choice::ForkChoiceStore` in order to provide a persistent backing to the /// `fork_choice::ForkChoice` struct. #[derive(Debug)] -pub struct BeaconForkChoiceStore { - store: Arc, +pub struct BeaconForkChoiceStore, Cold: ItemStore> { + store: Arc>, balances_cache: BalancesCache, time: Slot, finalized_checkpoint: Checkpoint, @@ -169,7 +169,12 @@ pub struct BeaconForkChoiceStore { _phantom: PhantomData, } -impl PartialEq for BeaconForkChoiceStore { +impl PartialEq for BeaconForkChoiceStore +where + E: EthSpec, + Hot: ItemStore, + Cold: ItemStore, +{ /// This implementation ignores the `store` and `slot_clock`. fn eq(&self, other: &Self) -> bool { self.balances_cache == other.balances_cache @@ -181,7 +186,12 @@ impl PartialEq for BeaconForkChoiceStore { } } -impl, E: EthSpec> BeaconForkChoiceStore { +impl BeaconForkChoiceStore +where + E: EthSpec, + Hot: ItemStore, + Cold: ItemStore, +{ /// Initialize `Self` from some `anchor` checkpoint which may or may not be the genesis state. /// /// ## Specification @@ -193,7 +203,10 @@ impl, E: EthSpec> BeaconForkChoiceStore { /// ## Notes: /// /// It is assumed that `anchor` is already persisted in `store`. - pub fn get_forkchoice_store(store: Arc, anchor: &BeaconSnapshot) -> Self { + pub fn get_forkchoice_store( + store: Arc>, + anchor: &BeaconSnapshot, + ) -> Self { let anchor_state = &anchor.beacon_state; let mut anchor_block_header = anchor_state.latest_block_header.clone(); if anchor_block_header.state_root == Hash256::zero() { @@ -235,7 +248,7 @@ impl, E: EthSpec> BeaconForkChoiceStore { /// Restore `Self` from a previously-generated `PersistedForkChoiceStore`. pub fn from_persisted( persisted: PersistedForkChoiceStore, - store: Arc, + store: Arc>, ) -> Result { Ok(Self { store, @@ -250,7 +263,12 @@ impl, E: EthSpec> BeaconForkChoiceStore { } } -impl, E: EthSpec> ForkChoiceStore for BeaconForkChoiceStore { +impl ForkChoiceStore for BeaconForkChoiceStore +where + E: EthSpec, + Hot: ItemStore, + Cold: ItemStore, +{ type Error = Error; fn get_current_slot(&self) -> Slot { diff --git a/beacon_node/store/Cargo.toml b/beacon_node/store/Cargo.toml index 23657daa0..79d25ecfb 100644 --- a/beacon_node/store/Cargo.toml +++ b/beacon_node/store/Cargo.toml @@ -29,5 +29,4 @@ serde_derive = "1.0.110" lazy_static = "1.4.0" lighthouse_metrics = { path = "../../common/lighthouse_metrics" } lru = "0.5.1" -fork_choice = { path = "../../consensus/fork_choice" } sloggers = "1.0.0" diff --git a/beacon_node/store/src/hot_cold_store.rs b/beacon_node/store/src/hot_cold_store.rs index 8ec6c3453..73ddad436 100644 --- a/beacon_node/store/src/hot_cold_store.rs +++ b/beacon_node/store/src/hot_cold_store.rs @@ -34,6 +34,7 @@ pub const SPLIT_DB_KEY: &str = "FREEZERDBSPLITFREEZERDBSPLITFREE"; /// /// Stores vector fields like the `block_roots` and `state_roots` separately, and only stores /// intermittent "restore point" states pre-finalization. +#[derive(Debug)] pub struct HotColdDB, Cold: ItemStore> { /// The slot and state root at the point where the database is split between hot and cold. /// diff --git a/consensus/fork_choice/tests/tests.rs b/consensus/fork_choice/tests/tests.rs index 1c1bfcbfa..3746f0ba1 100644 --- a/consensus/fork_choice/tests/tests.rs +++ b/consensus/fork_choice/tests/tests.rs @@ -9,7 +9,7 @@ use fork_choice::{ SAFE_SLOTS_TO_UPDATE_JUSTIFIED, }; use std::sync::Mutex; -use store::{MemoryStore, Store}; +use store::{MemoryStore, StoreConfig}; use types::{ test_utils::{generate_deterministic_keypair, generate_deterministic_keypairs}, Epoch, EthSpec, IndexedAttestation, MainnetEthSpec, Slot, @@ -41,6 +41,7 @@ impl ForkChoiceTest { generate_deterministic_keypairs(VALIDATOR_COUNT), // Ensure we always have an aggregator for each slot. u64::max_value(), + StoreConfig::default(), ); Self { harness } @@ -49,7 +50,7 @@ impl ForkChoiceTest { /// Get a value from the `ForkChoice` instantiation. fn get(&self, func: T) -> U where - T: Fn(&BeaconForkChoiceStore, E>) -> U, + T: Fn(&BeaconForkChoiceStore, MemoryStore>) -> U, { func(&self.harness.chain.fork_choice.read().fc_store()) }