Update lmd_ghost algorithms to use get_deserialized.
This commit is contained in:
parent
cb9f24224d
commit
6cf332c679
@ -112,7 +112,7 @@ pub enum ForkChoiceAlgorithms {
|
|||||||
/// A simple and highly inefficient implementation of LMD ghost.
|
/// A simple and highly inefficient implementation of LMD ghost.
|
||||||
SlowLMDGhost,
|
SlowLMDGhost,
|
||||||
/// An optimised version of LMD-GHOST by Vitalik.
|
/// An optimised version of LMD-GHOST by Vitalik.
|
||||||
OptimmisedLMDGhost,
|
OptimisedLMDGhost,
|
||||||
/// An optimised version of LMD-GHOST by Protolambda.
|
/// An optimised version of LMD-GHOST by Protolambda.
|
||||||
ProtoLMDGhost,
|
ProtoLMDGhost,
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ use fast_math::log2_raw;
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use types::{
|
use types::{
|
||||||
readers::{BeaconBlockReader, BeaconStateReader},
|
readers::BeaconBlockReader,
|
||||||
slot_epoch_height::{Height, Slot},
|
slot_epoch_height::{Height, Slot},
|
||||||
validator_registry::get_active_validator_indices,
|
validator_registry::get_active_validator_indices,
|
||||||
BeaconBlock, Hash256,
|
BeaconBlock, Hash256,
|
||||||
@ -114,10 +114,8 @@ where
|
|||||||
// gets the current weighted votes
|
// gets the current weighted votes
|
||||||
let current_state = self
|
let current_state = self
|
||||||
.state_store
|
.state_store
|
||||||
.get_reader(&state_root)?
|
.get_deserialized(&state_root)?
|
||||||
.ok_or_else(|| ForkChoiceError::MissingBeaconState(*state_root))?
|
.ok_or_else(|| ForkChoiceError::MissingBeaconState(*state_root))?;
|
||||||
.into_beacon_state()
|
|
||||||
.ok_or_else(|| ForkChoiceError::IncorrectBeaconState(*state_root))?;
|
|
||||||
|
|
||||||
let active_validator_indices = get_active_validator_indices(
|
let active_validator_indices = get_active_validator_indices(
|
||||||
¤t_state.validator_registry,
|
¤t_state.validator_registry,
|
||||||
@ -144,10 +142,9 @@ where
|
|||||||
let block_height = {
|
let block_height = {
|
||||||
let block_slot = self
|
let block_slot = self
|
||||||
.block_store
|
.block_store
|
||||||
.get_reader(&block_hash)
|
.get_deserialized(&block_hash)
|
||||||
.ok()?
|
.ok()?
|
||||||
.expect("Should have returned already if None")
|
.expect("Should have returned already if None")
|
||||||
.into_beacon_block()?
|
|
||||||
.slot;
|
.slot;
|
||||||
|
|
||||||
block_slot.height(Slot::from(GENESIS_SLOT))
|
block_slot.height(Slot::from(GENESIS_SLOT))
|
||||||
@ -267,7 +264,7 @@ impl<T: ClientDB + Sized> ForkChoice for OptimisedLMDGhost<T> {
|
|||||||
// get the height of the parent
|
// get the height of the parent
|
||||||
let parent_height = self
|
let parent_height = self
|
||||||
.block_store
|
.block_store
|
||||||
.get_reader(&block.parent_root)?
|
.get_deserialized(&block.parent_root)?
|
||||||
.ok_or_else(|| ForkChoiceError::MissingBeaconBlock(block.parent_root))?
|
.ok_or_else(|| ForkChoiceError::MissingBeaconBlock(block.parent_root))?
|
||||||
.slot()
|
.slot()
|
||||||
.height(Slot::from(GENESIS_SLOT));
|
.height(Slot::from(GENESIS_SLOT));
|
||||||
@ -312,7 +309,7 @@ impl<T: ClientDB + Sized> ForkChoice for OptimisedLMDGhost<T> {
|
|||||||
// get the height of the target block
|
// get the height of the target block
|
||||||
let block_height = self
|
let block_height = self
|
||||||
.block_store
|
.block_store
|
||||||
.get_reader(&target_block_root)?
|
.get_deserialized(&target_block_root)?
|
||||||
.ok_or_else(|| ForkChoiceError::MissingBeaconBlock(*target_block_root))?
|
.ok_or_else(|| ForkChoiceError::MissingBeaconBlock(*target_block_root))?
|
||||||
.slot()
|
.slot()
|
||||||
.height(Slot::from(GENESIS_SLOT));
|
.height(Slot::from(GENESIS_SLOT));
|
||||||
@ -320,7 +317,7 @@ impl<T: ClientDB + Sized> ForkChoice for OptimisedLMDGhost<T> {
|
|||||||
// get the height of the past target block
|
// get the height of the past target block
|
||||||
let past_block_height = self
|
let past_block_height = self
|
||||||
.block_store
|
.block_store
|
||||||
.get_reader(&attestation_target)?
|
.get_deserialized(&attestation_target)?
|
||||||
.ok_or_else(|| ForkChoiceError::MissingBeaconBlock(*attestation_target))?
|
.ok_or_else(|| ForkChoiceError::MissingBeaconBlock(*attestation_target))?
|
||||||
.slot()
|
.slot()
|
||||||
.height(Slot::from(GENESIS_SLOT));
|
.height(Slot::from(GENESIS_SLOT));
|
||||||
@ -336,7 +333,7 @@ impl<T: ClientDB + Sized> ForkChoice for OptimisedLMDGhost<T> {
|
|||||||
fn find_head(&mut self, justified_block_start: &Hash256) -> Result<Hash256, ForkChoiceError> {
|
fn find_head(&mut self, justified_block_start: &Hash256) -> Result<Hash256, ForkChoiceError> {
|
||||||
let block = self
|
let block = self
|
||||||
.block_store
|
.block_store
|
||||||
.get_reader(&justified_block_start)?
|
.get_deserialized(&justified_block_start)?
|
||||||
.ok_or_else(|| ForkChoiceError::MissingBeaconBlock(*justified_block_start))?;
|
.ok_or_else(|| ForkChoiceError::MissingBeaconBlock(*justified_block_start))?;
|
||||||
|
|
||||||
let block_slot = block.slot();
|
let block_slot = block.slot();
|
||||||
@ -399,7 +396,7 @@ impl<T: ClientDB + Sized> ForkChoice for OptimisedLMDGhost<T> {
|
|||||||
// update the block height for the next iteration
|
// update the block height for the next iteration
|
||||||
let block_height = self
|
let block_height = self
|
||||||
.block_store
|
.block_store
|
||||||
.get_reader(¤t_head)?
|
.get_deserialized(¤t_head)?
|
||||||
.ok_or_else(|| ForkChoiceError::MissingBeaconBlock(*justified_block_start))?
|
.ok_or_else(|| ForkChoiceError::MissingBeaconBlock(*justified_block_start))?
|
||||||
.slot()
|
.slot()
|
||||||
.height(Slot::from(GENESIS_SLOT));
|
.height(Slot::from(GENESIS_SLOT));
|
||||||
|
@ -82,10 +82,8 @@ where
|
|||||||
// gets the current weighted votes
|
// gets the current weighted votes
|
||||||
let current_state = self
|
let current_state = self
|
||||||
.state_store
|
.state_store
|
||||||
.get_reader(&state_root)?
|
.get_deserialized(&state_root)?
|
||||||
.ok_or_else(|| ForkChoiceError::MissingBeaconState(*state_root))?
|
.ok_or_else(|| ForkChoiceError::MissingBeaconState(*state_root))?;
|
||||||
.into_beacon_state()
|
|
||||||
.ok_or_else(|| ForkChoiceError::IncorrectBeaconState(*state_root))?;
|
|
||||||
|
|
||||||
let active_validator_indices = get_active_validator_indices(
|
let active_validator_indices = get_active_validator_indices(
|
||||||
¤t_state.validator_registry,
|
¤t_state.validator_registry,
|
||||||
@ -117,7 +115,7 @@ where
|
|||||||
let mut count = 0;
|
let mut count = 0;
|
||||||
let block_slot = self
|
let block_slot = self
|
||||||
.block_store
|
.block_store
|
||||||
.get_reader(&block_root)?
|
.get_deserialized(&block_root)?
|
||||||
.ok_or_else(|| ForkChoiceError::MissingBeaconBlock(*block_root))?
|
.ok_or_else(|| ForkChoiceError::MissingBeaconBlock(*block_root))?
|
||||||
.slot();
|
.slot();
|
||||||
|
|
||||||
@ -169,7 +167,7 @@ impl<T: ClientDB + Sized> ForkChoice for SlowLMDGhost<T> {
|
|||||||
// get the height of the target block
|
// get the height of the target block
|
||||||
let block_height = self
|
let block_height = self
|
||||||
.block_store
|
.block_store
|
||||||
.get_reader(&target_block_root)?
|
.get_deserialized(&target_block_root)?
|
||||||
.ok_or_else(|| ForkChoiceError::MissingBeaconBlock(*target_block_root))?
|
.ok_or_else(|| ForkChoiceError::MissingBeaconBlock(*target_block_root))?
|
||||||
.slot()
|
.slot()
|
||||||
.height(Slot::from(GENESIS_SLOT));
|
.height(Slot::from(GENESIS_SLOT));
|
||||||
@ -177,7 +175,7 @@ impl<T: ClientDB + Sized> ForkChoice for SlowLMDGhost<T> {
|
|||||||
// get the height of the past target block
|
// get the height of the past target block
|
||||||
let past_block_height = self
|
let past_block_height = self
|
||||||
.block_store
|
.block_store
|
||||||
.get_reader(&attestation_target)?
|
.get_deserialized(&attestation_target)?
|
||||||
.ok_or_else(|| ForkChoiceError::MissingBeaconBlock(*attestation_target))?
|
.ok_or_else(|| ForkChoiceError::MissingBeaconBlock(*attestation_target))?
|
||||||
.slot()
|
.slot()
|
||||||
.height(Slot::from(GENESIS_SLOT));
|
.height(Slot::from(GENESIS_SLOT));
|
||||||
@ -193,7 +191,7 @@ impl<T: ClientDB + Sized> ForkChoice for SlowLMDGhost<T> {
|
|||||||
fn find_head(&mut self, justified_block_start: &Hash256) -> Result<Hash256, ForkChoiceError> {
|
fn find_head(&mut self, justified_block_start: &Hash256) -> Result<Hash256, ForkChoiceError> {
|
||||||
let start = self
|
let start = self
|
||||||
.block_store
|
.block_store
|
||||||
.get_reader(&justified_block_start)?
|
.get_deserialized(&justified_block_start)?
|
||||||
.ok_or_else(|| ForkChoiceError::MissingBeaconBlock(*justified_block_start))?;
|
.ok_or_else(|| ForkChoiceError::MissingBeaconBlock(*justified_block_start))?;
|
||||||
|
|
||||||
let start_state_root = start.state_root();
|
let start_state_root = start.state_root();
|
||||||
|
Loading…
Reference in New Issue
Block a user