mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-20 14:28:37 +00:00
Remove old DB crates, start fixing fork_choice
This commit is contained in:
@@ -16,22 +16,23 @@
|
||||
//! [`slow_lmd_ghost`]: struct.SlowLmdGhost.html
|
||||
//! [`bitwise_lmd_ghost`]: struct.OptimisedLmdGhost.html
|
||||
|
||||
extern crate db;
|
||||
extern crate ssz;
|
||||
extern crate types;
|
||||
|
||||
/*
|
||||
pub mod bitwise_lmd_ghost;
|
||||
pub mod longest_chain;
|
||||
pub mod optimized_lmd_ghost;
|
||||
*/
|
||||
pub mod slow_lmd_ghost;
|
||||
|
||||
use db::stores::BeaconBlockAtSlotError;
|
||||
use db::DBError;
|
||||
// use db::stores::BeaconBlockAtSlotError;
|
||||
// use db::DBError;
|
||||
use db::Error as DBError;
|
||||
use types::{BeaconBlock, ChainSpec, Hash256};
|
||||
|
||||
/*
|
||||
pub use bitwise_lmd_ghost::BitwiseLMDGhost;
|
||||
pub use longest_chain::LongestChain;
|
||||
pub use optimized_lmd_ghost::OptimizedLMDGhost;
|
||||
*/
|
||||
pub use slow_lmd_ghost::SlowLMDGhost;
|
||||
|
||||
/// Defines the interface for Fork Choices. Each Fork choice will define their own data structures
|
||||
@@ -77,10 +78,11 @@ pub enum ForkChoiceError {
|
||||
|
||||
impl From<DBError> for ForkChoiceError {
|
||||
fn from(e: DBError) -> ForkChoiceError {
|
||||
ForkChoiceError::StorageError(e.message)
|
||||
ForkChoiceError::StorageError(format!("{:?}", e))
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
impl From<BeaconBlockAtSlotError> for ForkChoiceError {
|
||||
fn from(e: BeaconBlockAtSlotError) -> ForkChoiceError {
|
||||
match e {
|
||||
@@ -94,6 +96,7 @@ impl From<BeaconBlockAtSlotError> for ForkChoiceError {
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
/// Fork choice options that are currently implemented.
|
||||
#[derive(Debug, Clone)]
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
extern crate db;
|
||||
|
||||
use crate::{ForkChoice, ForkChoiceError};
|
||||
use db::{
|
||||
stores::{BeaconBlockStore, BeaconStateStore},
|
||||
ClientDB,
|
||||
};
|
||||
use db::{Store, StoreItem};
|
||||
use log::{debug, trace};
|
||||
use std::collections::HashMap;
|
||||
use std::marker::PhantomData;
|
||||
@@ -13,32 +10,23 @@ use types::{BeaconBlock, BeaconState, ChainSpec, EthSpec, Hash256, Slot};
|
||||
|
||||
//TODO: Pruning and syncing
|
||||
|
||||
pub struct SlowLMDGhost<T: ClientDB + Sized, E> {
|
||||
pub struct SlowLMDGhost<T, E> {
|
||||
/// 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>,
|
||||
/// Stores the children for any given parent.
|
||||
children: HashMap<Hash256, Vec<Hash256>>,
|
||||
/// Block storage access.
|
||||
block_store: Arc<BeaconBlockStore<T>>,
|
||||
/// State storage access.
|
||||
state_store: Arc<BeaconStateStore<T>>,
|
||||
/// Persistent storage
|
||||
store: Arc<T>,
|
||||
_phantom: PhantomData<E>,
|
||||
}
|
||||
|
||||
impl<T, E: EthSpec> SlowLMDGhost<T, E>
|
||||
where
|
||||
T: ClientDB + Sized,
|
||||
{
|
||||
pub fn new(
|
||||
block_store: Arc<BeaconBlockStore<T>>,
|
||||
state_store: Arc<BeaconStateStore<T>>,
|
||||
) -> Self {
|
||||
impl<T: Store, E: EthSpec> SlowLMDGhost<T, E> {
|
||||
pub fn new(store: Arc<T>) -> Self {
|
||||
SlowLMDGhost {
|
||||
latest_attestation_targets: HashMap::new(),
|
||||
children: HashMap::new(),
|
||||
block_store,
|
||||
state_store,
|
||||
store,
|
||||
_phantom: PhantomData,
|
||||
}
|
||||
}
|
||||
@@ -58,8 +46,8 @@ where
|
||||
let mut latest_votes: HashMap<Hash256, u64> = HashMap::new();
|
||||
// gets the current weighted votes
|
||||
let current_state: BeaconState<E> = self
|
||||
.state_store
|
||||
.get_deserialized(&state_root)?
|
||||
.store
|
||||
.get(state_root)?
|
||||
.ok_or_else(|| ForkChoiceError::MissingBeaconState(*state_root))?;
|
||||
|
||||
let active_validator_indices =
|
||||
@@ -90,8 +78,8 @@ where
|
||||
) -> Result<u64, ForkChoiceError> {
|
||||
let mut count = 0;
|
||||
let block_slot = self
|
||||
.block_store
|
||||
.get_deserialized(&block_root)?
|
||||
.store
|
||||
.get::<BeaconBlock>(&block_root)?
|
||||
.ok_or_else(|| ForkChoiceError::MissingBeaconBlock(*block_root))?
|
||||
.slot;
|
||||
|
||||
@@ -108,7 +96,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: ClientDB + Sized, E: EthSpec> ForkChoice for SlowLMDGhost<T, E> {
|
||||
impl<T: Store, E: EthSpec> ForkChoice for SlowLMDGhost<T, E> {
|
||||
/// Process when a block is added
|
||||
fn add_block(
|
||||
&mut self,
|
||||
|
||||
Reference in New Issue
Block a user