From 9c2bbb6c056372171db7f6204fe901c0d2b15be4 Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Sun, 16 Jun 2019 16:39:48 -0400 Subject: [PATCH] Add stubbed-out block processing to fork choice --- beacon_node/beacon_chain/src/beacon_chain.rs | 2 +- beacon_node/beacon_chain/src/fork_choice.rs | 5 ++++- eth2/lmd_ghost/src/lib.rs | 15 ++++++++++++--- eth2/lmd_ghost/src/reduced_tree.rs | 7 ++++++- 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/beacon_node/beacon_chain/src/beacon_chain.rs b/beacon_node/beacon_chain/src/beacon_chain.rs index 8602d32c77..d7ba67a37d 100644 --- a/beacon_node/beacon_chain/src/beacon_chain.rs +++ b/beacon_node/beacon_chain/src/beacon_chain.rs @@ -624,7 +624,7 @@ impl BeaconChain { self.store.put(&state_root, &state)?; // Register the new block with the fork choice service. - self.fork_choice.process_block(&state, &block)?; + self.fork_choice.process_block(&state, &block, block_root)?; // Execute the fork choice algorithm, enthroning a new head if discovered. // diff --git a/beacon_node/beacon_chain/src/fork_choice.rs b/beacon_node/beacon_chain/src/fork_choice.rs index 0d132386d5..7aba6fdf5d 100644 --- a/beacon_node/beacon_chain/src/fork_choice.rs +++ b/beacon_node/beacon_chain/src/fork_choice.rs @@ -89,6 +89,7 @@ impl ForkChoice { &self, state: &BeaconState, block: &BeaconBlock, + block_root: Hash256, ) -> Result<()> { // Note: we never count the block as a latest message, only attestations. // @@ -100,6 +101,8 @@ impl ForkChoice { self.process_attestation_from_block(state, attestation)?; } + self.backend.process_block(block_root, block.slot)?; + Ok(()) } @@ -138,7 +141,7 @@ impl ForkChoice { for validator_index in validator_indices { self.backend - .process_message(validator_index, block_hash, block_slot)?; + .process_attestation(validator_index, block_hash, block_slot)?; } } diff --git a/eth2/lmd_ghost/src/lib.rs b/eth2/lmd_ghost/src/lib.rs index 59495e382c..8f5d0b5299 100644 --- a/eth2/lmd_ghost/src/lib.rs +++ b/eth2/lmd_ghost/src/lib.rs @@ -9,18 +9,27 @@ pub use reduced_tree::ThreadSafeReducedTree; pub type Result = std::result::Result; pub trait LmdGhost: Send + Sync { - fn new(store: Arc, genesis_root: Hash256) -> Self; + /// Create a new instance, with the given `store` and `finalized_root`. + fn new(store: Arc, finalized_root: Hash256) -> Self; - fn process_message( + /// Process an attestation message from some validator that attests to some `block_hash` + /// representing a block at some `block_slot`. + fn process_attestation( &self, validator_index: usize, block_hash: Hash256, block_slot: Slot, ) -> Result<()>; + /// Process a block that was seen on the network. + fn process_block(&self, block_hash: Hash256, block_slot: Slot) -> Result<()>; + + /// Returns the head of the chain, starting the search at `start_block_root` and moving upwards + /// (in block height). fn find_head(&self, start_block_root: Hash256, weight: F) -> Result where F: Fn(usize) -> Option + Copy; - fn update_finalized_root(&self, new_root: Hash256) -> Result<()>; + /// Provide an indication that the blockchain has been finalized at the given `finalized_root`. + fn update_finalized_root(&self, finalized_root: Hash256) -> Result<()>; } diff --git a/eth2/lmd_ghost/src/reduced_tree.rs b/eth2/lmd_ghost/src/reduced_tree.rs index 84249b603f..f6db34e36c 100644 --- a/eth2/lmd_ghost/src/reduced_tree.rs +++ b/eth2/lmd_ghost/src/reduced_tree.rs @@ -40,7 +40,7 @@ where } } - fn process_message( + fn process_attestation( &self, validator_index: usize, block_hash: Hash256, @@ -52,6 +52,11 @@ where .map_err(Into::into) } + /// Process a block that was seen on the network. + fn process_block(&self, block_hash: Hash256, block_slot: Slot) -> SuperResult<()> { + unimplemented!(); + } + fn find_head(&self, start_block_root: Hash256, weight_fn: F) -> SuperResult where F: Fn(usize) -> Option + Copy,