diff --git a/beacon_node/beacon_chain/test_harness/src/beacon_chain_harness.rs b/beacon_node/beacon_chain/test_harness/src/beacon_chain_harness.rs index 9d61952f03..a20441beb5 100644 --- a/beacon_node/beacon_chain/test_harness/src/beacon_chain_harness.rs +++ b/beacon_node/beacon_chain/test_harness/src/beacon_chain_harness.rs @@ -6,7 +6,7 @@ use db::{ stores::{BeaconBlockStore, BeaconStateStore}, MemoryDB, }; -use fork_choice::OptimisedLMDGhost; +use fork_choice::BitwiseLMDGhost; use log::debug; use rayon::prelude::*; use slot_clock::TestingSlotClock; @@ -28,7 +28,7 @@ use types::{ /// is not useful for testing that multiple beacon nodes can reach consensus. pub struct BeaconChainHarness { pub db: Arc, - pub beacon_chain: Arc>>, + pub beacon_chain: Arc>>, pub block_store: Arc>, pub state_store: Arc>, pub validators: Vec, @@ -46,7 +46,7 @@ impl BeaconChainHarness { let state_store = Arc::new(BeaconStateStore::new(db.clone())); let genesis_time = 1_549_935_547; // 12th Feb 2018 (arbitrary value in the past). let slot_clock = TestingSlotClock::new(spec.genesis_slot.as_u64()); - let fork_choice = OptimisedLMDGhost::new(block_store.clone(), state_store.clone()); + let fork_choice = BitwiseLMDGhost::new(block_store.clone(), state_store.clone()); let latest_eth1_data = Eth1Data { deposit_root: Hash256::zero(), block_hash: Hash256::zero(), diff --git a/beacon_node/beacon_chain/test_harness/src/validator_harness/mod.rs b/beacon_node/beacon_chain/test_harness/src/validator_harness/mod.rs index f483095415..60c2f8ecf3 100644 --- a/beacon_node/beacon_chain/test_harness/src/validator_harness/mod.rs +++ b/beacon_node/beacon_chain/test_harness/src/validator_harness/mod.rs @@ -10,7 +10,7 @@ use block_proposer::{BlockProducer, Error as BlockPollError}; use db::MemoryDB; use direct_beacon_node::DirectBeaconNode; use direct_duties::DirectDuties; -use fork_choice::OptimisedLMDGhost; +use fork_choice::BitwiseLMDGhost; use local_signer::LocalSigner; use slot_clock::TestingSlotClock; use std::sync::Arc; @@ -36,20 +36,20 @@ pub enum AttestationProduceError { pub struct ValidatorHarness { pub block_producer: BlockProducer< TestingSlotClock, - DirectBeaconNode>, - DirectDuties>, + DirectBeaconNode>, + DirectDuties>, LocalSigner, >, pub attester: Attester< TestingSlotClock, - DirectBeaconNode>, - DirectDuties>, + DirectBeaconNode>, + DirectDuties>, LocalSigner, >, pub spec: Arc, - pub epoch_map: Arc>>, + pub epoch_map: Arc>>, pub keypair: Keypair, - pub beacon_node: Arc>>, + pub beacon_node: Arc>>, pub slot_clock: Arc, pub signer: Arc, } @@ -61,7 +61,7 @@ impl ValidatorHarness { /// A `BlockProducer` and `Attester` is created.. pub fn new( keypair: Keypair, - beacon_chain: Arc>>, + beacon_chain: Arc>>, spec: Arc, ) -> Self { let slot_clock = Arc::new(TestingSlotClock::new(spec.genesis_slot.as_u64())); diff --git a/beacon_node/src/main.rs b/beacon_node/src/main.rs index 2b6cdddcda..b9ef2c8a7a 100644 --- a/beacon_node/src/main.rs +++ b/beacon_node/src/main.rs @@ -14,7 +14,7 @@ use db::{ stores::{BeaconBlockStore, BeaconStateStore}, MemoryDB, }; -use fork_choice::optimised_lmd_ghost::OptimisedLMDGhost; +use fork_choice::BitwiseLMDGhost; use slog::{error, info, o, Drain}; use slot_clock::SystemTimeSlotClock; use std::sync::Arc; @@ -81,7 +81,7 @@ fn main() { let slot_clock = SystemTimeSlotClock::new(genesis_time, spec.slot_duration) .expect("Unable to load SystemTimeSlotClock"); // Choose the fork choice - let fork_choice = OptimisedLMDGhost::new(block_store.clone(), state_store.clone()); + let fork_choice = BitwiseLMDGhost::new(block_store.clone(), state_store.clone()); /* * Generate some random data to start a chain with. diff --git a/eth2/fork_choice/src/optimised_lmd_ghost.rs b/eth2/fork_choice/src/bitwise_lmd_ghost.rs similarity index 99% rename from eth2/fork_choice/src/optimised_lmd_ghost.rs rename to eth2/fork_choice/src/bitwise_lmd_ghost.rs index e85a052ca6..c09de1529e 100644 --- a/eth2/fork_choice/src/optimised_lmd_ghost.rs +++ b/eth2/fork_choice/src/bitwise_lmd_ghost.rs @@ -37,7 +37,7 @@ fn power_of_2_below(x: u32) -> u32 { } /// Stores the necessary data structures to run the optimised lmd ghost algorithm. -pub struct OptimisedLMDGhost { +pub struct BitwiseLMDGhost { /// A cache of known ancestors at given heights for a specific block. //TODO: Consider FnvHashMap cache: HashMap, Hash256>, @@ -56,7 +56,7 @@ pub struct OptimisedLMDGhost { max_known_height: SlotHeight, } -impl OptimisedLMDGhost +impl BitwiseLMDGhost where T: ClientDB + Sized, { @@ -64,7 +64,7 @@ where block_store: Arc>, state_store: Arc>, ) -> Self { - OptimisedLMDGhost { + BitwiseLMDGhost { cache: HashMap::new(), ancestors: vec![HashMap::new(); 16], latest_attestation_targets: HashMap::new(), @@ -253,7 +253,7 @@ where } } -impl ForkChoice for OptimisedLMDGhost { +impl ForkChoice for BitwiseLMDGhost { fn add_block( &mut self, block: &BeaconBlock, diff --git a/eth2/fork_choice/src/lib.rs b/eth2/fork_choice/src/lib.rs index 90fb0e82b4..4a58e30577 100644 --- a/eth2/fork_choice/src/lib.rs +++ b/eth2/fork_choice/src/lib.rs @@ -9,12 +9,12 @@ //! production**. //! - [`slow_lmd_ghost`]: This is a simple and very inefficient implementation given in the ethereum 2.0 //! specifications (https://github.com/ethereum/eth2.0-specs/blob/v0.1/specs/core/0_beacon-chain.md#get_block_root). -//! - [`optimised_lmd_ghost`]: This is an optimised version of bitwise LMD-GHOST as proposed +//! - [`bitwise_lmd_ghost`]: This is an optimised version of bitwise LMD-GHOST as proposed //! by Vitalik. The reference implementation can be found at: https://github.com/ethereum/research/blob/master/ghost/ghost.py //! //! [`longest-chain`]: struct.LongestChain.html //! [`slow_lmd_ghost`]: struct.SlowLmdGhost.html -//! [`optimised_lmd_ghost`]: struct.OptimisedLmdGhost.html +//! [`bitwise_lmd_ghost`]: struct.OptimisedLmdGhost.html extern crate db; extern crate ssz; @@ -22,16 +22,16 @@ extern crate types; #[macro_use] extern crate log; +pub mod bitwise_lmd_ghost; pub mod longest_chain; -pub mod optimised_lmd_ghost; pub mod slow_lmd_ghost; use db::stores::BeaconBlockAtSlotError; use db::DBError; use types::{BeaconBlock, ChainSpec, Hash256}; +pub use bitwise_lmd_ghost::BitwiseLMDGhost; pub use longest_chain::LongestChain; -pub use optimised_lmd_ghost::OptimisedLMDGhost; pub use slow_lmd_ghost::SlowLMDGhost; /// Defines the interface for Fork Choices. Each Fork choice will define their own data structures @@ -101,6 +101,6 @@ pub enum ForkChoiceAlgorithm { LongestChain, /// A simple and highly inefficient implementation of LMD ghost. SlowLMDGhost, - /// An optimised version of LMD-GHOST by Vitalik. - OptimisedLMDGhost, + /// An optimised version of bitwise LMD-GHOST by Vitalik. + BitwiseLMDGhost, } diff --git a/eth2/fork_choice/tests/optimised_lmd_ghost_test_vectors.yaml b/eth2/fork_choice/tests/bitwise_lmd_ghost_test_vectors.yaml similarity index 100% rename from eth2/fork_choice/tests/optimised_lmd_ghost_test_vectors.yaml rename to eth2/fork_choice/tests/bitwise_lmd_ghost_test_vectors.yaml diff --git a/eth2/fork_choice/tests/tests.rs b/eth2/fork_choice/tests/tests.rs index 0bebe6a775..1d93cd0dbd 100644 --- a/eth2/fork_choice/tests/tests.rs +++ b/eth2/fork_choice/tests/tests.rs @@ -16,7 +16,7 @@ use bls::{PublicKey, Signature}; use db::stores::{BeaconBlockStore, BeaconStateStore}; use db::MemoryDB; //use env_logger::{Builder, Env}; -use fork_choice::{ForkChoice, ForkChoiceAlgorithm, LongestChain, OptimisedLMDGhost, SlowLMDGhost}; +use fork_choice::{BitwiseLMDGhost, ForkChoice, ForkChoiceAlgorithm, LongestChain, SlowLMDGhost}; use ssz::ssz_encode; use std::collections::HashMap; use std::sync::Arc; @@ -29,13 +29,13 @@ use yaml_rust::yaml; // Note: We Assume the block Id's are hex-encoded. #[test] -fn test_optimised_lmd_ghost() { +fn test_bitwise_lmd_ghost() { // set up logging //Builder::from_env(Env::default().default_filter_or("trace")).init(); test_yaml_vectors( - ForkChoiceAlgorithm::OptimisedLMDGhost, - "tests/optimised_lmd_ghost_test_vectors.yaml", + ForkChoiceAlgorithm::BitwiseLMDGhost, + "tests/bitwise_lmd_ghost_test_vectors.yaml", 100, ); } @@ -214,7 +214,7 @@ fn setup_inital_state( // the fork choice instantiation let fork_choice: Box = match fork_choice_algo { - ForkChoiceAlgorithm::OptimisedLMDGhost => Box::new(OptimisedLMDGhost::new( + ForkChoiceAlgorithm::BitwiseLMDGhost => Box::new(BitwiseLMDGhost::new( block_store.clone(), state_store.clone(), )),