Update BeaconChain struct to use new store

This commit is contained in:
Paul Hauner 2019-05-21 13:36:14 +10:00
parent 2128d411bc
commit f1584dada4
No known key found for this signature in database
GPG Key ID: 5E2CFF9B75FA63DF
2 changed files with 12 additions and 24 deletions

View File

@ -1,9 +1,6 @@
use crate::checkpoint::CheckPoint; use crate::checkpoint::CheckPoint;
use crate::errors::{BeaconChainError as Error, BlockProductionError}; use crate::errors::{BeaconChainError as Error, BlockProductionError};
use db::{ use db::{Error as DBError, Store};
stores::{BeaconBlockStore, BeaconStateStore},
ClientDB, DBError,
};
use fork_choice::{ForkChoice, ForkChoiceError}; use fork_choice::{ForkChoice, ForkChoiceError};
use log::{debug, trace}; use log::{debug, trace};
use operation_pool::DepositInsertStatus; use operation_pool::DepositInsertStatus;
@ -83,9 +80,8 @@ impl BlockProcessingOutcome {
} }
} }
pub struct BeaconChain<T: ClientDB + Sized, U: SlotClock, F: ForkChoice, E: EthSpec> { pub struct BeaconChain<T, U, F, E: EthSpec> {
pub block_store: Arc<BeaconBlockStore<T>>, pub store: Arc<T>,
pub state_store: Arc<BeaconStateStore<T>>,
pub slot_clock: U, pub slot_clock: U,
pub op_pool: OperationPool<E>, pub op_pool: OperationPool<E>,
canonical_head: RwLock<CheckPoint<E>>, canonical_head: RwLock<CheckPoint<E>>,
@ -97,15 +93,14 @@ pub struct BeaconChain<T: ClientDB + Sized, U: SlotClock, F: ForkChoice, E: EthS
impl<T, U, F, E> BeaconChain<T, U, F, E> impl<T, U, F, E> BeaconChain<T, U, F, E>
where where
T: ClientDB, T: Store,
U: SlotClock, U: SlotClock,
F: ForkChoice, F: ForkChoice,
E: EthSpec, E: EthSpec,
{ {
/// Instantiate a new Beacon Chain, from genesis. /// Instantiate a new Beacon Chain, from genesis.
pub fn from_genesis( pub fn from_genesis(
state_store: Arc<BeaconStateStore<T>>, store: Arc<T>,
block_store: Arc<BeaconBlockStore<T>>,
slot_clock: U, slot_clock: U,
mut genesis_state: BeaconState<E>, mut genesis_state: BeaconState<E>,
genesis_block: BeaconBlock, genesis_block: BeaconBlock,
@ -113,10 +108,10 @@ where
fork_choice: F, fork_choice: F,
) -> Result<Self, Error> { ) -> Result<Self, Error> {
let state_root = genesis_state.canonical_root(); let state_root = genesis_state.canonical_root();
state_store.put(&state_root, &ssz_encode(&genesis_state)[..])?; store.put(&state_root, &genesis_state)?;
let block_root = genesis_block.block_header().canonical_root(); let block_root = genesis_block.block_header().canonical_root();
block_store.put(&block_root, &ssz_encode(&genesis_block)[..])?; store.put(&block_root, &genesis_block)?;
let finalized_head = RwLock::new(CheckPoint::new( let finalized_head = RwLock::new(CheckPoint::new(
genesis_block.clone(), genesis_block.clone(),
@ -134,8 +129,7 @@ where
genesis_state.build_all_caches(&spec)?; genesis_state.build_all_caches(&spec)?;
Ok(Self { Ok(Self {
block_store, store,
state_store,
slot_clock, slot_clock,
op_pool: OperationPool::new(), op_pool: OperationPool::new(),
state: RwLock::new(genesis_state), state: RwLock::new(genesis_state),

View File

@ -1,8 +1,5 @@
pub use crate::{BeaconChain, BeaconChainError, CheckPoint}; pub use crate::{BeaconChain, BeaconChainError, CheckPoint};
use db::{ use db::MemoryDB;
stores::{BeaconBlockStore, BeaconStateStore},
MemoryDB,
};
use fork_choice::BitwiseLMDGhost; use fork_choice::BitwiseLMDGhost;
use slot_clock::TestingSlotClock; use slot_clock::TestingSlotClock;
use std::sync::Arc; use std::sync::Arc;
@ -19,11 +16,9 @@ pub struct TestingBeaconChainBuilder<E: EthSpec> {
impl<E: EthSpec> TestingBeaconChainBuilder<E> { impl<E: EthSpec> TestingBeaconChainBuilder<E> {
pub fn build(self, spec: &ChainSpec) -> TestingBeaconChain<E> { pub fn build(self, spec: &ChainSpec) -> TestingBeaconChain<E> {
let db = Arc::new(MemoryDB::open()); let store = Arc::new(MemoryDB::open());
let block_store = Arc::new(BeaconBlockStore::new(db.clone()));
let state_store = Arc::new(BeaconStateStore::new(db.clone()));
let slot_clock = TestingSlotClock::new(spec.genesis_slot.as_u64()); let slot_clock = TestingSlotClock::new(spec.genesis_slot.as_u64());
let fork_choice = BitwiseLMDGhost::new(block_store.clone(), state_store.clone()); let fork_choice = BitwiseLMDGhost::new(store.clone());
let (genesis_state, _keypairs) = self.state_builder.build(); let (genesis_state, _keypairs) = self.state_builder.build();
@ -32,8 +27,7 @@ impl<E: EthSpec> TestingBeaconChainBuilder<E> {
// Create the Beacon Chain // Create the Beacon Chain
BeaconChain::from_genesis( BeaconChain::from_genesis(
state_store.clone(), store,
block_store.clone(),
slot_clock, slot_clock,
genesis_state, genesis_state,
genesis_block, genesis_block,