Rename fork_choice_2 to lmd_ghost
This commit is contained in:
parent
8f44402691
commit
c43bbfe183
@ -1,7 +1,7 @@
|
|||||||
[workspace]
|
[workspace]
|
||||||
members = [
|
members = [
|
||||||
"eth2/fork_choice",
|
"eth2/fork_choice",
|
||||||
"eth2/fork_choice_2",
|
"eth2/lmd_ghost",
|
||||||
"eth2/operation_pool",
|
"eth2/operation_pool",
|
||||||
"eth2/state_processing",
|
"eth2/state_processing",
|
||||||
"eth2/types",
|
"eth2/types",
|
||||||
|
@ -1,36 +0,0 @@
|
|||||||
pub mod reduced_tree;
|
|
||||||
|
|
||||||
use std::sync::Arc;
|
|
||||||
use types::{Hash256, Slot};
|
|
||||||
|
|
||||||
type Result<T> = std::result::Result<T, Error>;
|
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
|
||||||
pub enum Error {
|
|
||||||
BackendError(String),
|
|
||||||
}
|
|
||||||
|
|
||||||
pub trait LmdGhostBackend<T>: Send + Sync {
|
|
||||||
fn new(store: Arc<T>) -> Self;
|
|
||||||
|
|
||||||
fn process_message(
|
|
||||||
&self,
|
|
||||||
validator_index: usize,
|
|
||||||
block_hash: Hash256,
|
|
||||||
block_slot: Slot,
|
|
||||||
) -> Result<()>;
|
|
||||||
|
|
||||||
fn find_head(&self) -> Result<Hash256>;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct ForkChoice<T> {
|
|
||||||
algorithm: T,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T: LmdGhostBackend<T>> ForkChoice<T> {
|
|
||||||
pub fn new(store: Arc<T>) -> Self {
|
|
||||||
Self {
|
|
||||||
algorithm: T::new(store),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,19 +1,20 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "fork_choice_2"
|
name = "lmd_ghost"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["Age Manning <Age@AgeManning.com>", "Paul Hauner <paul@sigmaprime.io>"]
|
authors = ["Age Manning <Age@AgeManning.com>", "Paul Hauner <paul@sigmaprime.io>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
parking_lot = "0.7"
|
||||||
store = { path = "../../beacon_node/store" }
|
store = { path = "../../beacon_node/store" }
|
||||||
ssz = { path = "../utils/ssz" }
|
ssz = { path = "../utils/ssz" }
|
||||||
|
state_processing = { path = "../state_processing" }
|
||||||
types = { path = "../types" }
|
types = { path = "../types" }
|
||||||
log = "0.4.6"
|
log = "0.4.6"
|
||||||
bit-vec = "0.5.0"
|
bit-vec = "0.5.0"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
criterion = "0.2"
|
criterion = "0.2"
|
||||||
parking_lot = "0.7"
|
|
||||||
hex = "0.3.2"
|
hex = "0.3.2"
|
||||||
yaml-rust = "0.4.2"
|
yaml-rust = "0.4.2"
|
||||||
bls = { path = "../utils/bls" }
|
bls = { path = "../utils/bls" }
|
99
eth2/lmd_ghost/src/lib.rs
Normal file
99
eth2/lmd_ghost/src/lib.rs
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
pub mod reduced_tree;
|
||||||
|
|
||||||
|
use state_processing::common::get_attesting_indices_unsorted;
|
||||||
|
use std::marker::PhantomData;
|
||||||
|
use std::sync::Arc;
|
||||||
|
use types::{Attestation, BeaconBlock, BeaconState, BeaconStateError, EthSpec, Hash256, Slot};
|
||||||
|
|
||||||
|
type Result<T> = std::result::Result<T, Error>;
|
||||||
|
|
||||||
|
#[derive(Debug, PartialEq)]
|
||||||
|
pub enum Error {
|
||||||
|
BackendError(String),
|
||||||
|
BeaconStateError(BeaconStateError),
|
||||||
|
}
|
||||||
|
|
||||||
|
pub trait LmdGhostBackend<T, E: EthSpec>: Send + Sync {
|
||||||
|
fn new(store: Arc<T>) -> Self;
|
||||||
|
|
||||||
|
fn process_message(
|
||||||
|
&self,
|
||||||
|
validator_index: usize,
|
||||||
|
block_hash: Hash256,
|
||||||
|
block_slot: Slot,
|
||||||
|
) -> Result<()>;
|
||||||
|
|
||||||
|
fn find_head(&self) -> Result<Hash256>;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct ForkChoice<T, E> {
|
||||||
|
backend: T,
|
||||||
|
_phantom: PhantomData<E>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T, E> ForkChoice<T, E>
|
||||||
|
where
|
||||||
|
T: LmdGhostBackend<T, E>,
|
||||||
|
E: EthSpec,
|
||||||
|
{
|
||||||
|
pub fn new(store: Arc<T>) -> Self {
|
||||||
|
Self {
|
||||||
|
backend: T::new(store),
|
||||||
|
_phantom: PhantomData,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn find_head(&self) -> Result<Hash256> {
|
||||||
|
self.backend.find_head()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn process_attestation(
|
||||||
|
&self,
|
||||||
|
state: &BeaconState<E>,
|
||||||
|
attestation: &Attestation,
|
||||||
|
) -> Result<()> {
|
||||||
|
let validator_indices = get_attesting_indices_unsorted(
|
||||||
|
state,
|
||||||
|
&attestation.data,
|
||||||
|
&attestation.aggregation_bitfield,
|
||||||
|
)?;
|
||||||
|
|
||||||
|
let block_hash = attestation.data.target_root;
|
||||||
|
|
||||||
|
// TODO: what happens when the target root is not the same slot as the block?
|
||||||
|
let block_slot = attestation
|
||||||
|
.data
|
||||||
|
.target_epoch
|
||||||
|
.start_slot(E::slots_per_epoch());
|
||||||
|
|
||||||
|
for validator_index in validator_indices {
|
||||||
|
self.backend
|
||||||
|
.process_message(validator_index, block_hash, block_slot)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn process_block(
|
||||||
|
&self,
|
||||||
|
state: &BeaconState<E>,
|
||||||
|
block: &BeaconBlock,
|
||||||
|
block_hash: Hash256,
|
||||||
|
block_proposer: usize,
|
||||||
|
) -> Result<()> {
|
||||||
|
self.backend
|
||||||
|
.process_message(block_proposer, block_hash, block.slot)?;
|
||||||
|
|
||||||
|
for attestation in &block.body.attestations {
|
||||||
|
self.process_attestation(state, attestation)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<BeaconStateError> for Error {
|
||||||
|
fn from(e: BeaconStateError) -> Error {
|
||||||
|
Error::BeaconStateError(e)
|
||||||
|
}
|
||||||
|
}
|
@ -69,7 +69,7 @@ pub struct Vote {
|
|||||||
slot: Slot,
|
slot: Slot,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T, E> LmdGhostBackend<T> for ThreadSafeReducedTree<T, E>
|
impl<T, E> LmdGhostBackend<T, E> for ThreadSafeReducedTree<T, E>
|
||||||
where
|
where
|
||||||
T: Store,
|
T: Store,
|
||||||
E: EthSpec,
|
E: EthSpec,
|
Loading…
Reference in New Issue
Block a user