Add stubbed-out block processing to fork choice

This commit is contained in:
Paul Hauner 2019-06-16 16:39:48 -04:00
parent f6c86d0f7f
commit 9c2bbb6c05
No known key found for this signature in database
GPG Key ID: 303E4494BB28068C
4 changed files with 23 additions and 6 deletions

View File

@ -624,7 +624,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
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.
//

View File

@ -89,6 +89,7 @@ impl<T: BeaconChainTypes> ForkChoice<T> {
&self,
state: &BeaconState<T::EthSpec>,
block: &BeaconBlock,
block_root: Hash256,
) -> Result<()> {
// Note: we never count the block as a latest message, only attestations.
//
@ -100,6 +101,8 @@ impl<T: BeaconChainTypes> ForkChoice<T> {
self.process_attestation_from_block(state, attestation)?;
}
self.backend.process_block(block_root, block.slot)?;
Ok(())
}
@ -138,7 +141,7 @@ impl<T: BeaconChainTypes> ForkChoice<T> {
for validator_index in validator_indices {
self.backend
.process_message(validator_index, block_hash, block_slot)?;
.process_attestation(validator_index, block_hash, block_slot)?;
}
}

View File

@ -9,18 +9,27 @@ pub use reduced_tree::ThreadSafeReducedTree;
pub type Result<T> = std::result::Result<T, String>;
pub trait LmdGhost<S: Store, E: EthSpec>: Send + Sync {
fn new(store: Arc<S>, genesis_root: Hash256) -> Self;
/// Create a new instance, with the given `store` and `finalized_root`.
fn new(store: Arc<S>, 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<F>(&self, start_block_root: Hash256, weight: F) -> Result<Hash256>
where
F: Fn(usize) -> Option<u64> + 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<()>;
}

View File

@ -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<F>(&self, start_block_root: Hash256, weight_fn: F) -> SuperResult<Hash256>
where
F: Fn(usize) -> Option<u64> + Copy,