Run fork-choice after every block import

This commit is contained in:
Paul Hauner 2019-05-29 17:55:38 +10:00
parent 0b719e1523
commit 42b6e0c8a9
No known key found for this signature in database
GPG Key ID: 5E2CFF9B75FA63DF

View File

@ -713,21 +713,16 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
self.store.put(&block_root, &block)?; self.store.put(&block_root, &block)?;
self.store.put(&state_root, &state)?; self.store.put(&state_root, &state)?;
// run the fork_choice add_block logic // Register the new block with the fork choice service.
self.fork_choice self.fork_choice
.write() .write()
.add_block(&block, &block_root, &self.spec)?; .add_block(&block, &block_root, &self.spec)?;
// If the parent block was the parent_block, automatically update the canonical head. // Execute the fork choice algorithm, enthroning a new head if discovered.
// //
// TODO: this is a first-in-best-dressed scenario that is not ideal; fork_choice should be // Note: in the future we may choose to run fork-choice less often, potentially based upon
// run instead. // some heuristic around number of attestations seen for the block.
if self.head().beacon_block_root == parent_block_root { self.fork_choice()?;
self.update_canonical_head(block.clone(), block_root, state.clone(), state_root);
// Update the canonical `BeaconState`.
self.update_state(state)?;
}
self.metrics.block_processing_successes.inc(); self.metrics.block_processing_successes.inc();
timer.observe_duration(); timer.observe_duration();