From fd78004ef9e1a2cf49f039b81786b18d70438ed3 Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Fri, 10 May 2019 11:49:28 +1000 Subject: [PATCH 1/5] Update README badges - Changes the travis badge to a gitlab badge. - Adds a docs badge. - Does not modify the gitter badge. - Restructures the badge markdown for readability. --- README.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index abf9acb6a0..879f9b8fe6 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,13 @@ # Lighthouse: an Ethereum Serenity client -[![Build Status](https://travis-ci.org/sigp/lighthouse.svg?branch=master)](https://travis-ci.org/sigp/lighthouse) [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/sigp/lighthouse?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) +[![Build Status]][Build Link] [![Doc Status]][Doc Link] [![Gitter Badge]][Gitter Link] + +[Build Status]: https://gitlab.sigmaprime.io/sigp/lighthouse/badges/master/build.svg +[Build Link]: https://gitlab.sigmaprime.io/sigp/lighthouse/pipelines +[Gitter Badge]: https://badges.gitter.im/Join%20Chat.svg +[Gitter Link]: https://gitter.im/sigp/lighthouse +[Doc Status]: https://img.shields.io/badge/docs-master-blue.svg +[Doc Link]: http://lighthouse-docs.sigmaprime.io/ A work-in-progress, open-source implementation of the Serenity Beacon Chain, maintained by Sigma Prime. From 3be80ba9a99f99d8f893c09c76d9822c017066f8 Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Fri, 10 May 2019 13:29:43 +1000 Subject: [PATCH 2/5] Marginally improve `cached_tree_hash` docs --- eth2/utils/cached_tree_hash/src/btree_overlay.rs | 8 ++++---- eth2/utils/cached_tree_hash/src/lib.rs | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/eth2/utils/cached_tree_hash/src/btree_overlay.rs b/eth2/utils/cached_tree_hash/src/btree_overlay.rs index a96df769cf..5692a43917 100644 --- a/eth2/utils/cached_tree_hash/src/btree_overlay.rs +++ b/eth2/utils/cached_tree_hash/src/btree_overlay.rs @@ -2,8 +2,8 @@ use super::*; /// A schema defining a binary tree over a `TreeHashCache`. /// -/// This structure is used for succinct storage, run-time functionality is gained by converting the -/// schema into a `BTreeOverlay`. +/// This structure is used for succinct storage; run-time functionality is gained by converting a +/// `BTreeSchema` into a `BTreeOverlay`. #[derive(Debug, PartialEq, Clone)] pub struct BTreeSchema { /// The depth of a schema defines how far it is nested within other fixed-length items. @@ -48,8 +48,8 @@ pub enum LeafNode { Padding, } -/// Instantiated from a `BTreeSchema`, allows for interpreting some chunks of a `TreeHashCache` as -/// a perfect binary tree. +/// Instantiated from a `BTreeSchema`, a `BTreeOverlay` allows for interpreting some +/// non-consecutive chunks of a `TreeHashCache` as a perfect binary tree. /// /// The primary purpose of this struct is to map from binary tree "nodes" to `TreeHashCache` /// "chunks". Each tree has nodes `0..n` where `n` is the number of nodes and `0` is the root node. diff --git a/eth2/utils/cached_tree_hash/src/lib.rs b/eth2/utils/cached_tree_hash/src/lib.rs index 21fa786e4c..d47a4bdf51 100644 --- a/eth2/utils/cached_tree_hash/src/lib.rs +++ b/eth2/utils/cached_tree_hash/src/lib.rs @@ -2,7 +2,7 @@ //! [here](https://github.com/ethereum/eth2.0-specs/blob/v0.5.1/specs/simple-serialize.md#merkleization). //! //! Caching allows for reduced hashing when some object has only been partially modified. This -//! allows for significant CPU-time savings (at the cost of additional storage). For example, +//! gives significant CPU-time savings (at the cost of additional storage). For example, //! determining the root of a list of 1024 items with a single modification has been observed to //! run in 1/25th of the time of a full merkle hash. //! @@ -61,8 +61,8 @@ pub trait CachedTreeHash: TreeHash { fn update_tree_hash_cache(&self, cache: &mut TreeHashCache) -> Result<(), Error>; } -/// Implements `CachedTreeHash` on `$type` as a fixed-length tree-hash vector of the ssz encoding -/// of `$type`. +/// Implements `CachedTreeHash` on `$type`, where `$type` is a fixed-length vector and each item in +/// the `$type` is encoded as bytes using `ssz_encode`. #[macro_export] macro_rules! cached_tree_hash_ssz_encoding_as_vector { ($type: ident, $num_bytes: expr) => { @@ -95,8 +95,8 @@ macro_rules! cached_tree_hash_ssz_encoding_as_vector { }; } -/// Implements `CachedTreeHash` on `$type` as a variable-length tree-hash list of the result of -/// calling `.as_bytes()` on `$type`. +/// Implements `CachedTreeHash` on `$type`, where `$type` is a variable-length list and each item +/// in `$type` is encoded as bytes by calling `item.as_bytes()`. #[macro_export] macro_rules! cached_tree_hash_bytes_as_list { ($type: ident) => { From 93a4bef41c94862b0f7371d33dfb1d71501af17d Mon Sep 17 00:00:00 2001 From: Luke Anderson Date: Fri, 10 May 2019 13:49:01 +1000 Subject: [PATCH 3/5] Very small wording/typo fixes for docs. --- eth2/utils/cached_tree_hash/src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/eth2/utils/cached_tree_hash/src/lib.rs b/eth2/utils/cached_tree_hash/src/lib.rs index d47a4bdf51..8bc26aa792 100644 --- a/eth2/utils/cached_tree_hash/src/lib.rs +++ b/eth2/utils/cached_tree_hash/src/lib.rs @@ -1,8 +1,8 @@ //! Performs cached merkle-hashing adhering to the Ethereum 2.0 specification defined //! [here](https://github.com/ethereum/eth2.0-specs/blob/v0.5.1/specs/simple-serialize.md#merkleization). //! -//! Caching allows for reduced hashing when some object has only been partially modified. This -//! gives significant CPU-time savings (at the cost of additional storage). For example, +//! Caching allows for reduced hashing when some object has only been partially modified, which +//! consumes less CPU-time at the cost of additional storage. For example, //! determining the root of a list of 1024 items with a single modification has been observed to //! run in 1/25th of the time of a full merkle hash. //! @@ -96,7 +96,7 @@ macro_rules! cached_tree_hash_ssz_encoding_as_vector { } /// Implements `CachedTreeHash` on `$type`, where `$type` is a variable-length list and each item -/// in `$type` is encoded as bytes by calling `item.as_bytes()`. +/// in `$type` is encoded as bytes by calling `item.to_bytes()`. #[macro_export] macro_rules! cached_tree_hash_bytes_as_list { ($type: ident) => { From afa8fff31ab1382a2326c8c7605552f1df2ab066 Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Mon, 13 May 2019 14:14:40 +1000 Subject: [PATCH 4/5] Remove old `tree_hash_vector` file --- eth2/types/src/lib.rs | 2 - eth2/types/src/tree_hash_vector.rs | 142 ----------------------------- 2 files changed, 144 deletions(-) delete mode 100644 eth2/types/src/tree_hash_vector.rs diff --git a/eth2/types/src/lib.rs b/eth2/types/src/lib.rs index c6109e1662..79981c890f 100644 --- a/eth2/types/src/lib.rs +++ b/eth2/types/src/lib.rs @@ -27,7 +27,6 @@ pub mod pending_attestation; pub mod proposer_slashing; pub mod slashable_attestation; pub mod transfer; -// pub mod tree_hash_vector; pub mod voluntary_exit; #[macro_use] pub mod slot_epoch_macros; @@ -66,7 +65,6 @@ pub use crate::slashable_attestation::SlashableAttestation; pub use crate::slot_epoch::{Epoch, Slot}; pub use crate::slot_height::SlotHeight; pub use crate::transfer::Transfer; -// pub use crate::tree_hash_vector::TreeHashVector; pub use crate::validator::Validator; pub use crate::voluntary_exit::VoluntaryExit; diff --git a/eth2/types/src/tree_hash_vector.rs b/eth2/types/src/tree_hash_vector.rs deleted file mode 100644 index 2600ff62f8..0000000000 --- a/eth2/types/src/tree_hash_vector.rs +++ /dev/null @@ -1,142 +0,0 @@ -use crate::test_utils::{RngCore, TestRandom}; -use cached_tree_hash::CachedTreeHash; -use serde_derive::{Deserialize, Serialize}; -use ssz::{Decodable, DecodeError, Encodable, SszStream}; -use std::ops::{Deref, DerefMut}; -use tree_hash::TreeHash; - -#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)] -pub struct TreeHashVector(Vec); - -impl From> for TreeHashVector { - fn from(vec: Vec) -> TreeHashVector { - TreeHashVector(vec) - } -} - -impl Into> for TreeHashVector { - fn into(self) -> Vec { - self.0 - } -} - -impl Deref for TreeHashVector { - type Target = Vec; - - fn deref(&self) -> &Vec { - &self.0 - } -} - -impl DerefMut for TreeHashVector { - fn deref_mut(&mut self) -> &mut Vec { - &mut self.0 - } -} - -impl tree_hash::TreeHash for TreeHashVector -where - T: TreeHash, -{ - fn tree_hash_type() -> tree_hash::TreeHashType { - tree_hash::TreeHashType::Vector - } - - fn tree_hash_packed_encoding(&self) -> Vec { - unreachable!("Vector should never be packed.") - } - - fn tree_hash_packing_factor() -> usize { - unreachable!("Vector should never be packed.") - } - - fn tree_hash_root(&self) -> Vec { - tree_hash::impls::vec_tree_hash_root(self) - } -} - -impl CachedTreeHash for TreeHashVector -where - T: CachedTreeHash + TreeHash, -{ - fn new_tree_hash_cache( - &self, - depth: usize, - ) -> Result { - let (cache, _overlay) = cached_tree_hash::vec::new_tree_hash_cache(self, depth)?; - - Ok(cache) - } - - fn tree_hash_cache_schema(&self, depth: usize) -> cached_tree_hash::BTreeSchema { - cached_tree_hash::vec::produce_schema(self, depth) - } - - fn update_tree_hash_cache( - &self, - cache: &mut cached_tree_hash::TreeHashCache, - ) -> Result<(), cached_tree_hash::Error> { - cached_tree_hash::vec::update_tree_hash_cache(self, cache)?; - - Ok(()) - } -} - -impl Encodable for TreeHashVector -where - T: Encodable, -{ - fn ssz_append(&self, s: &mut SszStream) { - s.append_vec(self) - } -} - -impl Decodable for TreeHashVector -where - T: Decodable, -{ - fn ssz_decode(bytes: &[u8], index: usize) -> Result<(Self, usize), DecodeError> { - ssz::decode_ssz_list(bytes, index).and_then(|(vec, i)| Ok((vec.into(), i))) - } -} - -impl TestRandom for TreeHashVector -where - U: TestRandom, -{ - fn random_for_test(rng: &mut impl RngCore) -> Self { - TreeHashVector::from(vec![ - U::random_for_test(rng), - U::random_for_test(rng), - U::random_for_test(rng), - ]) - } -} - -#[cfg(test)] -mod test { - use super::*; - use tree_hash::TreeHash; - - #[test] - pub fn test_cached_tree_hash() { - let original = TreeHashVector::from(vec![1_u64, 2, 3, 4]); - - let mut cache = cached_tree_hash::TreeHashCache::new(&original).unwrap(); - - assert_eq!( - cache.tree_hash_root().unwrap().to_vec(), - original.tree_hash_root() - ); - - let modified = TreeHashVector::from(vec![1_u64, 1, 1, 1]); - - cache.update(&modified).unwrap(); - - assert_eq!( - cache.tree_hash_root().unwrap().to_vec(), - modified.tree_hash_root() - ); - } - -} From fcabef91da13fe31478be4b5e76e39b9830adf2a Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Mon, 13 May 2019 14:44:43 +1000 Subject: [PATCH 5/5] Use `E` for `EthSpec` trait, instead of `B` --- beacon_node/beacon_chain/src/beacon_chain.rs | 32 +++++++++---------- beacon_node/beacon_chain/src/checkpoint.rs | 10 +++--- .../testing_beacon_chain_builder.rs | 16 +++++----- beacon_node/client/src/lib.rs | 4 +-- .../db/src/stores/beacon_state_store.rs | 6 ++-- beacon_node/network/src/beacon_chain.rs | 18 +++++------ beacon_node/network/src/message_handler.rs | 10 +++--- beacon_node/network/src/service.rs | 8 ++--- beacon_node/network/src/sync/import_queue.rs | 8 ++--- beacon_node/network/src/sync/simple_sync.rs | 14 ++++---- beacon_node/rpc/src/attestation.rs | 6 ++-- beacon_node/rpc/src/beacon_block.rs | 6 ++-- beacon_node/rpc/src/beacon_chain.rs | 18 +++++------ beacon_node/rpc/src/beacon_node.rs | 6 ++-- beacon_node/rpc/src/lib.rs | 4 +-- beacon_node/rpc/src/validator.rs | 6 ++-- eth2/fork_choice/src/bitwise_lmd_ghost.rs | 10 +++--- eth2/fork_choice/src/optimized_lmd_ghost.rs | 10 +++--- eth2/fork_choice/src/slow_lmd_ghost.rs | 10 +++--- eth2/operation_pool/src/lib.rs | 18 +++++------ 20 files changed, 110 insertions(+), 110 deletions(-) diff --git a/beacon_node/beacon_chain/src/beacon_chain.rs b/beacon_node/beacon_chain/src/beacon_chain.rs index b6eb1d2f7a..db5ea1cdb6 100644 --- a/beacon_node/beacon_chain/src/beacon_chain.rs +++ b/beacon_node/beacon_chain/src/beacon_chain.rs @@ -83,31 +83,31 @@ impl BlockProcessingOutcome { } } -pub struct BeaconChain { +pub struct BeaconChain { pub block_store: Arc>, pub state_store: Arc>, pub slot_clock: U, - pub op_pool: OperationPool, - canonical_head: RwLock>, - finalized_head: RwLock>, - pub state: RwLock>, + pub op_pool: OperationPool, + canonical_head: RwLock>, + finalized_head: RwLock>, + pub state: RwLock>, pub spec: ChainSpec, pub fork_choice: RwLock, } -impl BeaconChain +impl BeaconChain where T: ClientDB, U: SlotClock, F: ForkChoice, - B: EthSpec, + E: EthSpec, { /// Instantiate a new Beacon Chain, from genesis. pub fn from_genesis( state_store: Arc>, block_store: Arc>, slot_clock: U, - mut genesis_state: BeaconState, + mut genesis_state: BeaconState, genesis_block: BeaconBlock, spec: ChainSpec, fork_choice: F, @@ -230,7 +230,7 @@ where Err(BeaconStateError::SlotOutOfBounds) => { // Read the earliest historic state in the current slot. let earliest_historic_slot = - state.slot - Slot::from(B::SlotsPerHistoricalRoot::to_usize()); + state.slot - Slot::from(E::SlotsPerHistoricalRoot::to_usize()); // Load the earlier state from disk. let new_state_root = state.get_state_root(earliest_historic_slot)?; @@ -270,7 +270,7 @@ where &self, new_beacon_block: BeaconBlock, new_beacon_block_root: Hash256, - new_beacon_state: BeaconState, + new_beacon_state: BeaconState, new_beacon_state_root: Hash256, ) { debug!( @@ -292,7 +292,7 @@ where /// It is important to note that the `beacon_state` returned may not match the present slot. It /// is the state as it was when the head block was received, which could be some slots prior to /// now. - pub fn head(&self) -> RwLockReadGuard> { + pub fn head(&self) -> RwLockReadGuard> { self.canonical_head.read() } @@ -302,7 +302,7 @@ where /// state and calling `catchup_state` as it will not result in an old state being installed and /// then having it iteratively updated -- in such a case it's possible for another thread to /// find the state at an old slot. - pub fn update_state(&self, mut state: BeaconState) -> Result<(), Error> { + pub fn update_state(&self, mut state: BeaconState) -> Result<(), Error> { let present_slot = match self.slot_clock.present_slot() { Ok(Some(slot)) => slot, _ => return Err(Error::UnableToReadSlot), @@ -357,7 +357,7 @@ where &self, new_beacon_block: BeaconBlock, new_beacon_block_root: Hash256, - new_beacon_state: BeaconState, + new_beacon_state: BeaconState, new_beacon_state_root: Hash256, ) { let mut finalized_head = self.finalized_head.write(); @@ -371,7 +371,7 @@ where /// Returns a read-lock guarded `CheckPoint` struct for reading the justified head (as chosen, /// indirectly, by the fork-choice rule). - pub fn finalized_head(&self) -> RwLockReadGuard> { + pub fn finalized_head(&self) -> RwLockReadGuard> { self.finalized_head.read() } @@ -664,7 +664,7 @@ where pub fn produce_block( &self, randao_reveal: Signature, - ) -> Result<(BeaconBlock, BeaconState), BlockProductionError> { + ) -> Result<(BeaconBlock, BeaconState), BlockProductionError> { debug!("Producing block at slot {}...", self.state.read().slot); let mut state = self.state.read().clone(); @@ -759,7 +759,7 @@ where /// /// This could be a very expensive operation and should only be done in testing/analysis /// activities. - pub fn chain_dump(&self) -> Result>, Error> { + pub fn chain_dump(&self) -> Result>, Error> { let mut dump = vec![]; let mut last_slot = CheckPoint { diff --git a/beacon_node/beacon_chain/src/checkpoint.rs b/beacon_node/beacon_chain/src/checkpoint.rs index 7bed5b5ce3..c069ac1042 100644 --- a/beacon_node/beacon_chain/src/checkpoint.rs +++ b/beacon_node/beacon_chain/src/checkpoint.rs @@ -4,19 +4,19 @@ use types::{BeaconBlock, BeaconState, EthSpec, Hash256}; /// Represents some block and it's associated state. Generally, this will be used for tracking the /// head, justified head and finalized head. #[derive(Clone, Serialize, PartialEq, Debug)] -pub struct CheckPoint { +pub struct CheckPoint { pub beacon_block: BeaconBlock, pub beacon_block_root: Hash256, - pub beacon_state: BeaconState, + pub beacon_state: BeaconState, pub beacon_state_root: Hash256, } -impl CheckPoint { +impl CheckPoint { /// Create a new checkpoint. pub fn new( beacon_block: BeaconBlock, beacon_block_root: Hash256, - beacon_state: BeaconState, + beacon_state: BeaconState, beacon_state_root: Hash256, ) -> Self { Self { @@ -32,7 +32,7 @@ impl CheckPoint { &mut self, beacon_block: BeaconBlock, beacon_block_root: Hash256, - beacon_state: BeaconState, + beacon_state: BeaconState, beacon_state_root: Hash256, ) { self.beacon_block = beacon_block; diff --git a/beacon_node/beacon_chain/src/test_utils/testing_beacon_chain_builder.rs b/beacon_node/beacon_chain/src/test_utils/testing_beacon_chain_builder.rs index b617ed0d7a..f7ff3cdae1 100644 --- a/beacon_node/beacon_chain/src/test_utils/testing_beacon_chain_builder.rs +++ b/beacon_node/beacon_chain/src/test_utils/testing_beacon_chain_builder.rs @@ -10,15 +10,15 @@ use tree_hash::TreeHash; use types::*; use types::{test_utils::TestingBeaconStateBuilder, EthSpec, FewValidatorsEthSpec}; -type TestingBeaconChain = - BeaconChain, B>; +type TestingBeaconChain = + BeaconChain, E>; -pub struct TestingBeaconChainBuilder { - state_builder: TestingBeaconStateBuilder, +pub struct TestingBeaconChainBuilder { + state_builder: TestingBeaconStateBuilder, } -impl TestingBeaconChainBuilder { - pub fn build(self, spec: &ChainSpec) -> TestingBeaconChain { +impl TestingBeaconChainBuilder { + pub fn build(self, spec: &ChainSpec) -> TestingBeaconChain { let db = Arc::new(MemoryDB::open()); let block_store = Arc::new(BeaconBlockStore::new(db.clone())); let state_store = Arc::new(BeaconStateStore::new(db.clone())); @@ -44,8 +44,8 @@ impl TestingBeaconChainBuilder { } } -impl From> for TestingBeaconChainBuilder { - fn from(state_builder: TestingBeaconStateBuilder) -> TestingBeaconChainBuilder { +impl From> for TestingBeaconChainBuilder { + fn from(state_builder: TestingBeaconStateBuilder) -> TestingBeaconChainBuilder { TestingBeaconChainBuilder { state_builder } } } diff --git a/beacon_node/client/src/lib.rs b/beacon_node/client/src/lib.rs index 166f1a9489..5d7c221ef5 100644 --- a/beacon_node/client/src/lib.rs +++ b/beacon_node/client/src/lib.rs @@ -144,12 +144,12 @@ impl Client { } } -fn do_state_catchup(chain: &Arc>, log: &slog::Logger) +fn do_state_catchup(chain: &Arc>, log: &slog::Logger) where T: ClientDB, U: SlotClock, F: ForkChoice, - B: EthSpec, + E: EthSpec, { if let Some(genesis_height) = chain.slots_since_genesis() { let result = chain.catchup_state(); diff --git a/beacon_node/db/src/stores/beacon_state_store.rs b/beacon_node/db/src/stores/beacon_state_store.rs index c0d37edd9f..1b088e4a94 100644 --- a/beacon_node/db/src/stores/beacon_state_store.rs +++ b/beacon_node/db/src/stores/beacon_state_store.rs @@ -19,14 +19,14 @@ impl BeaconStateStore { Self { db } } - pub fn get_deserialized( + pub fn get_deserialized( &self, hash: &Hash256, - ) -> Result>, DBError> { + ) -> Result>, DBError> { match self.get(&hash)? { None => Ok(None), Some(ssz) => { - let state = decode::>(&ssz).map_err(|_| DBError { + let state = decode::>(&ssz).map_err(|_| DBError { message: "Bad State SSZ.".to_string(), })?; Ok(Some(state)) diff --git a/beacon_node/network/src/beacon_chain.rs b/beacon_node/network/src/beacon_chain.rs index db809086a4..a98aa73deb 100644 --- a/beacon_node/network/src/beacon_chain.rs +++ b/beacon_node/network/src/beacon_chain.rs @@ -15,14 +15,14 @@ use types::{ pub use beacon_chain::{BeaconChainError, BlockProcessingOutcome, InvalidBlock}; /// The network's API to the beacon chain. -pub trait BeaconChain: Send + Sync { +pub trait BeaconChain: Send + Sync { fn get_spec(&self) -> &ChainSpec; - fn get_state(&self) -> RwLockReadGuard>; + fn get_state(&self) -> RwLockReadGuard>; fn slot(&self) -> Slot; - fn head(&self) -> RwLockReadGuard>; + fn head(&self) -> RwLockReadGuard>; fn get_block(&self, block_root: &Hash256) -> Result, BeaconChainError>; @@ -30,7 +30,7 @@ pub trait BeaconChain: Send + Sync { fn best_block_root(&self) -> Hash256; - fn finalized_head(&self) -> RwLockReadGuard>; + fn finalized_head(&self) -> RwLockReadGuard>; fn finalized_epoch(&self) -> Epoch; @@ -64,18 +64,18 @@ pub trait BeaconChain: Send + Sync { fn is_new_block_root(&self, beacon_block_root: &Hash256) -> Result; } -impl BeaconChain for RawBeaconChain +impl BeaconChain for RawBeaconChain where T: ClientDB + Sized, U: SlotClock, F: ForkChoice, - B: EthSpec, + E: EthSpec, { fn get_spec(&self) -> &ChainSpec { &self.spec } - fn get_state(&self) -> RwLockReadGuard> { + fn get_state(&self) -> RwLockReadGuard> { self.state.read() } @@ -83,7 +83,7 @@ where self.get_state().slot } - fn head(&self) -> RwLockReadGuard> { + fn head(&self) -> RwLockReadGuard> { self.head() } @@ -95,7 +95,7 @@ where self.get_state().finalized_epoch } - fn finalized_head(&self) -> RwLockReadGuard> { + fn finalized_head(&self) -> RwLockReadGuard> { self.finalized_head() } diff --git a/beacon_node/network/src/message_handler.rs b/beacon_node/network/src/message_handler.rs index 35743fe151..a7d0ff2a13 100644 --- a/beacon_node/network/src/message_handler.rs +++ b/beacon_node/network/src/message_handler.rs @@ -21,11 +21,11 @@ use types::EthSpec; // const HELLO_TIMEOUT: Duration = Duration::from_secs(30); /// Handles messages received from the network and client and organises syncing. -pub struct MessageHandler { +pub struct MessageHandler { /// Currently loaded and initialised beacon chain. - _chain: Arc>, + _chain: Arc>, /// The syncing framework. - sync: SimpleSync, + sync: SimpleSync, /// The context required to send messages to, and process messages from peers. network_context: NetworkContext, /// The `MessageHandler` logger. @@ -45,10 +45,10 @@ pub enum HandlerMessage { PubsubMessage(PeerId, Box), } -impl MessageHandler { +impl MessageHandler { /// Initializes and runs the MessageHandler. pub fn spawn( - beacon_chain: Arc>, + beacon_chain: Arc>, network_send: crossbeam_channel::Sender, executor: &tokio::runtime::TaskExecutor, log: slog::Logger, diff --git a/beacon_node/network/src/service.rs b/beacon_node/network/src/service.rs index 89d1e15267..50454a8759 100644 --- a/beacon_node/network/src/service.rs +++ b/beacon_node/network/src/service.rs @@ -16,17 +16,17 @@ use tokio::runtime::TaskExecutor; use types::{EthSpec, Topic}; /// Service that handles communication between internal services and the eth2_libp2p network service. -pub struct Service { +pub struct Service { //libp2p_service: Arc>, _libp2p_exit: oneshot::Sender<()>, network_send: crossbeam_channel::Sender, - _phantom: PhantomData, //message_handler: MessageHandler, + _phantom: PhantomData, //message_handler: MessageHandler, //message_handler_send: Sender } -impl Service { +impl Service { pub fn new( - beacon_chain: Arc>, + beacon_chain: Arc>, config: &NetworkConfig, executor: &TaskExecutor, log: slog::Logger, diff --git a/beacon_node/network/src/sync/import_queue.rs b/beacon_node/network/src/sync/import_queue.rs index 1fffd8763f..6c2fc33eeb 100644 --- a/beacon_node/network/src/sync/import_queue.rs +++ b/beacon_node/network/src/sync/import_queue.rs @@ -19,8 +19,8 @@ use types::{BeaconBlock, BeaconBlockBody, BeaconBlockHeader, EthSpec, Hash256, S /// `BeaconBlockBody` as the key. /// - It is possible for multiple distinct blocks to have identical `BeaconBlockBodies`. Therefore /// we cannot use a `HashMap` keyed by the root of `BeaconBlockBody`. -pub struct ImportQueue { - pub chain: Arc>, +pub struct ImportQueue { + pub chain: Arc>, /// Partially imported blocks, keyed by the root of `BeaconBlockBody`. pub partials: Vec, /// Time before a queue entry is considered state. @@ -29,9 +29,9 @@ pub struct ImportQueue { log: slog::Logger, } -impl ImportQueue { +impl ImportQueue { /// Return a new, empty queue. - pub fn new(chain: Arc>, stale_time: Duration, log: slog::Logger) -> Self { + pub fn new(chain: Arc>, stale_time: Duration, log: slog::Logger) -> Self { Self { chain, partials: vec![], diff --git a/beacon_node/network/src/sync/simple_sync.rs b/beacon_node/network/src/sync/simple_sync.rs index 3f4fb7aaec..d44ffd4b75 100644 --- a/beacon_node/network/src/sync/simple_sync.rs +++ b/beacon_node/network/src/sync/simple_sync.rs @@ -88,8 +88,8 @@ impl From for PeerSyncInfo { } } -impl From<&Arc>> for PeerSyncInfo { - fn from(chain: &Arc>) -> PeerSyncInfo { +impl From<&Arc>> for PeerSyncInfo { + fn from(chain: &Arc>) -> PeerSyncInfo { Self::from(chain.hello_message()) } } @@ -103,22 +103,22 @@ pub enum SyncState { } /// Simple Syncing protocol. -pub struct SimpleSync { +pub struct SimpleSync { /// A reference to the underlying beacon chain. - chain: Arc>, + chain: Arc>, /// A mapping of Peers to their respective PeerSyncInfo. known_peers: HashMap, /// A queue to allow importing of blocks - import_queue: ImportQueue, + import_queue: ImportQueue, /// The current state of the syncing protocol. state: SyncState, /// Sync logger. log: slog::Logger, } -impl SimpleSync { +impl SimpleSync { /// Instantiate a `SimpleSync` instance, with no peers and an empty queue. - pub fn new(beacon_chain: Arc>, log: &slog::Logger) -> Self { + pub fn new(beacon_chain: Arc>, log: &slog::Logger) -> Self { let sync_logger = log.new(o!("Service"=> "Sync")); let queue_item_stale_time = Duration::from_secs(QUEUE_STALE_SECS); diff --git a/beacon_node/rpc/src/attestation.rs b/beacon_node/rpc/src/attestation.rs index 30f04afbac..5b6d93a955 100644 --- a/beacon_node/rpc/src/attestation.rs +++ b/beacon_node/rpc/src/attestation.rs @@ -12,12 +12,12 @@ use std::sync::Arc; use types::{Attestation, EthSpec}; #[derive(Clone)] -pub struct AttestationServiceInstance { - pub chain: Arc>, +pub struct AttestationServiceInstance { + pub chain: Arc>, pub log: slog::Logger, } -impl AttestationService for AttestationServiceInstance { +impl AttestationService for AttestationServiceInstance { /// Produce the `AttestationData` for signing by a validator. fn produce_attestation_data( &mut self, diff --git a/beacon_node/rpc/src/beacon_block.rs b/beacon_node/rpc/src/beacon_block.rs index 727da9542e..370dce60d5 100644 --- a/beacon_node/rpc/src/beacon_block.rs +++ b/beacon_node/rpc/src/beacon_block.rs @@ -16,13 +16,13 @@ use std::sync::Arc; use types::{BeaconBlock, EthSpec, Signature, Slot}; #[derive(Clone)] -pub struct BeaconBlockServiceInstance { - pub chain: Arc>, +pub struct BeaconBlockServiceInstance { + pub chain: Arc>, pub network_chan: crossbeam_channel::Sender, pub log: Logger, } -impl BeaconBlockService for BeaconBlockServiceInstance { +impl BeaconBlockService for BeaconBlockServiceInstance { /// Produce a `BeaconBlock` for signing by a validator. fn produce_beacon_block( &mut self, diff --git a/beacon_node/rpc/src/beacon_chain.rs b/beacon_node/rpc/src/beacon_chain.rs index e10522d045..7e75b32ced 100644 --- a/beacon_node/rpc/src/beacon_chain.rs +++ b/beacon_node/rpc/src/beacon_chain.rs @@ -11,12 +11,12 @@ pub use beacon_chain::{BeaconChainError, BlockProcessingOutcome}; use types::{Attestation, AttestationData, BeaconBlock, EthSpec}; /// The RPC's API to the beacon chain. -pub trait BeaconChain: Send + Sync { +pub trait BeaconChain: Send + Sync { fn get_spec(&self) -> &ChainSpec; - fn get_state(&self) -> RwLockReadGuard>; + fn get_state(&self) -> RwLockReadGuard>; - fn get_mut_state(&self) -> RwLockWriteGuard>; + fn get_mut_state(&self) -> RwLockWriteGuard>; fn process_block(&self, block: BeaconBlock) -> Result; @@ -24,7 +24,7 @@ pub trait BeaconChain: Send + Sync { fn produce_block( &self, randao_reveal: Signature, - ) -> Result<(BeaconBlock, BeaconState), BlockProductionError>; + ) -> Result<(BeaconBlock, BeaconState), BlockProductionError>; fn produce_attestation_data(&self, shard: u64) -> Result; @@ -34,22 +34,22 @@ pub trait BeaconChain: Send + Sync { ) -> Result<(), AttestationValidationError>; } -impl BeaconChain for RawBeaconChain +impl BeaconChain for RawBeaconChain where T: ClientDB + Sized, U: SlotClock, F: ForkChoice, - B: EthSpec, + E: EthSpec, { fn get_spec(&self) -> &ChainSpec { &self.spec } - fn get_state(&self) -> RwLockReadGuard> { + fn get_state(&self) -> RwLockReadGuard> { self.state.read() } - fn get_mut_state(&self) -> RwLockWriteGuard> { + fn get_mut_state(&self) -> RwLockWriteGuard> { self.state.write() } @@ -63,7 +63,7 @@ where fn produce_block( &self, randao_reveal: Signature, - ) -> Result<(BeaconBlock, BeaconState), BlockProductionError> { + ) -> Result<(BeaconBlock, BeaconState), BlockProductionError> { self.produce_block(randao_reveal) } diff --git a/beacon_node/rpc/src/beacon_node.rs b/beacon_node/rpc/src/beacon_node.rs index 873d1c4781..2ca39ae512 100644 --- a/beacon_node/rpc/src/beacon_node.rs +++ b/beacon_node/rpc/src/beacon_node.rs @@ -8,12 +8,12 @@ use std::sync::Arc; use types::EthSpec; #[derive(Clone)] -pub struct BeaconNodeServiceInstance { - pub chain: Arc>, +pub struct BeaconNodeServiceInstance { + pub chain: Arc>, pub log: slog::Logger, } -impl BeaconNodeService for BeaconNodeServiceInstance { +impl BeaconNodeService for BeaconNodeServiceInstance { /// Provides basic node information. fn info(&mut self, ctx: RpcContext, _req: Empty, sink: UnarySink) { trace!(self.log, "Node info requested via RPC"); diff --git a/beacon_node/rpc/src/lib.rs b/beacon_node/rpc/src/lib.rs index d46dee7b5b..f1d5e9c886 100644 --- a/beacon_node/rpc/src/lib.rs +++ b/beacon_node/rpc/src/lib.rs @@ -23,11 +23,11 @@ use std::sync::Arc; use tokio::runtime::TaskExecutor; use types::EthSpec; -pub fn start_server( +pub fn start_server( config: &RPCConfig, executor: &TaskExecutor, network_chan: crossbeam_channel::Sender, - beacon_chain: Arc>, + beacon_chain: Arc>, log: &slog::Logger, ) -> exit_future::Signal { let log = log.new(o!("Service"=>"RPC")); diff --git a/beacon_node/rpc/src/validator.rs b/beacon_node/rpc/src/validator.rs index e2f8d098f6..6a145d32da 100644 --- a/beacon_node/rpc/src/validator.rs +++ b/beacon_node/rpc/src/validator.rs @@ -10,13 +10,13 @@ use std::sync::Arc; use types::{Epoch, EthSpec, RelativeEpoch}; #[derive(Clone)] -pub struct ValidatorServiceInstance { - pub chain: Arc>, +pub struct ValidatorServiceInstance { + pub chain: Arc>, pub log: slog::Logger, } //TODO: Refactor Errors -impl ValidatorService for ValidatorServiceInstance { +impl ValidatorService for ValidatorServiceInstance { /// For a list of validator public keys, this function returns the slot at which each /// validator must propose a block, attest to a shard, their shard committee and the shard they /// need to attest to. diff --git a/eth2/fork_choice/src/bitwise_lmd_ghost.rs b/eth2/fork_choice/src/bitwise_lmd_ghost.rs index 3eb8bff8c8..0bbac6bb68 100644 --- a/eth2/fork_choice/src/bitwise_lmd_ghost.rs +++ b/eth2/fork_choice/src/bitwise_lmd_ghost.rs @@ -34,7 +34,7 @@ fn power_of_2_below(x: u64) -> u64 { } /// Stores the necessary data structures to run the optimised bitwise lmd ghost algorithm. -pub struct BitwiseLMDGhost { +pub struct BitwiseLMDGhost { /// A cache of known ancestors at given heights for a specific block. //TODO: Consider FnvHashMap cache: HashMap, Hash256>, @@ -51,10 +51,10 @@ pub struct BitwiseLMDGhost { /// State storage access. state_store: Arc>, max_known_height: SlotHeight, - _phantom: PhantomData, + _phantom: PhantomData, } -impl BitwiseLMDGhost +impl BitwiseLMDGhost where T: ClientDB + Sized, { @@ -88,7 +88,7 @@ where // build a hashmap of block_hash to weighted votes let mut latest_votes: HashMap = HashMap::new(); // gets the current weighted votes - let current_state: BeaconState = self + let current_state: BeaconState = self .state_store .get_deserialized(&state_root)? .ok_or_else(|| ForkChoiceError::MissingBeaconState(*state_root))?; @@ -243,7 +243,7 @@ where } } -impl ForkChoice for BitwiseLMDGhost { +impl ForkChoice for BitwiseLMDGhost { fn add_block( &mut self, block: &BeaconBlock, diff --git a/eth2/fork_choice/src/optimized_lmd_ghost.rs b/eth2/fork_choice/src/optimized_lmd_ghost.rs index a471452c83..3f585e3c17 100644 --- a/eth2/fork_choice/src/optimized_lmd_ghost.rs +++ b/eth2/fork_choice/src/optimized_lmd_ghost.rs @@ -34,7 +34,7 @@ fn power_of_2_below(x: u64) -> u64 { } /// Stores the necessary data structures to run the optimised lmd ghost algorithm. -pub struct OptimizedLMDGhost { +pub struct OptimizedLMDGhost { /// A cache of known ancestors at given heights for a specific block. //TODO: Consider FnvHashMap cache: HashMap, Hash256>, @@ -51,10 +51,10 @@ pub struct OptimizedLMDGhost { /// State storage access. state_store: Arc>, max_known_height: SlotHeight, - _phantom: PhantomData, + _phantom: PhantomData, } -impl OptimizedLMDGhost +impl OptimizedLMDGhost where T: ClientDB + Sized, { @@ -88,7 +88,7 @@ where // build a hashmap of block_hash to weighted votes let mut latest_votes: HashMap = HashMap::new(); // gets the current weighted votes - let current_state: BeaconState = self + let current_state: BeaconState = self .state_store .get_deserialized(&state_root)? .ok_or_else(|| ForkChoiceError::MissingBeaconState(*state_root))?; @@ -214,7 +214,7 @@ where } } -impl ForkChoice for OptimizedLMDGhost { +impl ForkChoice for OptimizedLMDGhost { fn add_block( &mut self, block: &BeaconBlock, diff --git a/eth2/fork_choice/src/slow_lmd_ghost.rs b/eth2/fork_choice/src/slow_lmd_ghost.rs index c11ef3eec3..c9aaa70d17 100644 --- a/eth2/fork_choice/src/slow_lmd_ghost.rs +++ b/eth2/fork_choice/src/slow_lmd_ghost.rs @@ -13,7 +13,7 @@ use types::{BeaconBlock, BeaconState, ChainSpec, EthSpec, Hash256, Slot}; //TODO: Pruning and syncing -pub struct SlowLMDGhost { +pub struct SlowLMDGhost { /// 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, @@ -23,10 +23,10 @@ pub struct SlowLMDGhost { block_store: Arc>, /// State storage access. state_store: Arc>, - _phantom: PhantomData, + _phantom: PhantomData, } -impl SlowLMDGhost +impl SlowLMDGhost where T: ClientDB + Sized, { @@ -57,7 +57,7 @@ where // build a hashmap of block_hash to weighted votes let mut latest_votes: HashMap = HashMap::new(); // gets the current weighted votes - let current_state: BeaconState = self + let current_state: BeaconState = self .state_store .get_deserialized(&state_root)? .ok_or_else(|| ForkChoiceError::MissingBeaconState(*state_root))?; @@ -108,7 +108,7 @@ where } } -impl ForkChoice for SlowLMDGhost { +impl ForkChoice for SlowLMDGhost { /// Process when a block is added fn add_block( &mut self, diff --git a/eth2/operation_pool/src/lib.rs b/eth2/operation_pool/src/lib.rs index cbaabe0cd8..c5653e7f92 100644 --- a/eth2/operation_pool/src/lib.rs +++ b/eth2/operation_pool/src/lib.rs @@ -539,10 +539,10 @@ where /// The keys in the map should be validator indices, which will be looked up /// in the state's validator registry and then passed to `prune_if`. /// Entries for unknown validators will be kept. -fn prune_validator_hash_map( +fn prune_validator_hash_map( map: &mut HashMap, prune_if: F, - finalized_state: &BeaconState, + finalized_state: &BeaconState, ) where F: Fn(&Validator) -> bool, { @@ -722,12 +722,12 @@ mod tests { /// Create a signed attestation for use in tests. /// Signed by all validators in `committee[signing_range]` and `committee[extra_signer]`. - fn signed_attestation, B: EthSpec>( + fn signed_attestation, E: EthSpec>( committee: &CrosslinkCommittee, keypairs: &[Keypair], signing_range: R, slot: Slot, - state: &BeaconState, + state: &BeaconState, spec: &ChainSpec, extra_signer: Option, ) -> Attestation { @@ -754,10 +754,10 @@ mod tests { } /// Test state for attestation-related tests. - fn attestation_test_state( + fn attestation_test_state( num_committees: usize, - ) -> (BeaconState, Vec, ChainSpec) { - let spec = B::spec(); + ) -> (BeaconState, Vec, ChainSpec) { + let spec = E::spec(); let num_validators = num_committees * (spec.slots_per_epoch * spec.target_committee_size) as usize; @@ -775,9 +775,9 @@ mod tests { } /// Set the latest crosslink in the state to match the attestation. - fn fake_latest_crosslink( + fn fake_latest_crosslink( att: &Attestation, - state: &mut BeaconState, + state: &mut BeaconState, spec: &ChainSpec, ) { state.latest_crosslinks[att.data.shard as usize] = Crosslink {