Allow fork_choice and beacon_chain to compile

This commit is contained in:
Paul Hauner
2019-05-08 18:18:17 +10:00
parent 9fd8af8428
commit 51dc97ee42
8 changed files with 87 additions and 64 deletions

View File

@@ -7,12 +7,13 @@ use db::{
};
use log::{debug, trace};
use std::collections::HashMap;
use std::marker::PhantomData;
use std::sync::Arc;
use types::{BeaconBlock, ChainSpec, Hash256, Slot};
use types::{BeaconBlock, BeaconState, BeaconStateTypes, ChainSpec, Hash256, Slot};
//TODO: Pruning and syncing
pub struct SlowLMDGhost<T: ClientDB + Sized> {
pub struct SlowLMDGhost<T: ClientDB + Sized, B: BeaconStateTypes> {
/// The latest attestation targets as a map of validator index to block hash.
//TODO: Could this be a fixed size vec
latest_attestation_targets: HashMap<u64, Hash256>,
@@ -22,9 +23,10 @@ pub struct SlowLMDGhost<T: ClientDB + Sized> {
block_store: Arc<BeaconBlockStore<T>>,
/// State storage access.
state_store: Arc<BeaconStateStore<T>>,
_phantom: PhantomData<B>,
}
impl<T> SlowLMDGhost<T>
impl<T, B: BeaconStateTypes> SlowLMDGhost<T, B>
where
T: ClientDB + Sized,
{
@@ -37,6 +39,7 @@ where
children: HashMap::new(),
block_store,
state_store,
_phantom: PhantomData,
}
}
@@ -54,7 +57,7 @@ where
// build a hashmap of block_hash to weighted votes
let mut latest_votes: HashMap<Hash256, u64> = HashMap::new();
// gets the current weighted votes
let current_state = self
let current_state: BeaconState<B> = self
.state_store
.get_deserialized(&state_root)?
.ok_or_else(|| ForkChoiceError::MissingBeaconState(*state_root))?;
@@ -105,7 +108,7 @@ where
}
}
impl<T: ClientDB + Sized> ForkChoice for SlowLMDGhost<T> {
impl<T: ClientDB + Sized, B: BeaconStateTypes> ForkChoice for SlowLMDGhost<T, B> {
/// Process when a block is added
fn add_block(
&mut self,