Remove readers from fork choice crate.
This commit is contained in:
parent
8b08e9dd2e
commit
d94540c85c
@ -11,8 +11,8 @@ use log::{debug, trace};
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use types::{
|
use types::{
|
||||||
readers::BeaconBlockReader, validator_registry::get_active_validator_indices, BeaconBlock,
|
validator_registry::get_active_validator_indices, BeaconBlock, ChainSpec, Hash256, Slot,
|
||||||
ChainSpec, Hash256, Slot, SlotHeight,
|
SlotHeight,
|
||||||
};
|
};
|
||||||
|
|
||||||
//TODO: Pruning - Children
|
//TODO: Pruning - Children
|
||||||
@ -255,17 +255,17 @@ impl<T: ClientDB + Sized> ForkChoice for BitwiseLMDGhost<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_deserialized(&block.parent_root)?
|
.get_deserialized(&block.previous_block_root)?
|
||||||
.ok_or_else(|| ForkChoiceError::MissingBeaconBlock(block.parent_root))?
|
.ok_or_else(|| ForkChoiceError::MissingBeaconBlock(block.previous_block_root))?
|
||||||
.slot()
|
.slot
|
||||||
.height(spec.genesis_slot);
|
.height(spec.genesis_slot);
|
||||||
|
|
||||||
let parent_hash = &block.parent_root;
|
let parent_hash = &block.previous_block_root;
|
||||||
|
|
||||||
// add the new block to the children of parent
|
// add the new block to the children of parent
|
||||||
(*self
|
(*self
|
||||||
.children
|
.children
|
||||||
.entry(block.parent_root)
|
.entry(block.previous_block_root)
|
||||||
.or_insert_with(|| vec![]))
|
.or_insert_with(|| vec![]))
|
||||||
.push(block_hash.clone());
|
.push(block_hash.clone());
|
||||||
|
|
||||||
@ -309,7 +309,7 @@ impl<T: ClientDB + Sized> ForkChoice for BitwiseLMDGhost<T> {
|
|||||||
.block_store
|
.block_store
|
||||||
.get_deserialized(&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(spec.genesis_slot);
|
.height(spec.genesis_slot);
|
||||||
|
|
||||||
// get the height of the past target block
|
// get the height of the past target block
|
||||||
@ -317,7 +317,7 @@ impl<T: ClientDB + Sized> ForkChoice for BitwiseLMDGhost<T> {
|
|||||||
.block_store
|
.block_store
|
||||||
.get_deserialized(&attestation_target)?
|
.get_deserialized(&attestation_target)?
|
||||||
.ok_or_else(|| ForkChoiceError::MissingBeaconBlock(*attestation_target))?
|
.ok_or_else(|| ForkChoiceError::MissingBeaconBlock(*attestation_target))?
|
||||||
.slot()
|
.slot
|
||||||
.height(spec.genesis_slot);
|
.height(spec.genesis_slot);
|
||||||
// update the attestation only if the new target is higher
|
// update the attestation only if the new target is higher
|
||||||
if past_block_height < block_height {
|
if past_block_height < block_height {
|
||||||
@ -343,8 +343,8 @@ impl<T: ClientDB + Sized> ForkChoice for BitwiseLMDGhost<T> {
|
|||||||
.get_deserialized(&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;
|
||||||
let state_root = block.state_root();
|
let state_root = block.state_root;
|
||||||
let mut block_height = block_slot.height(spec.genesis_slot);
|
let mut block_height = block_slot.height(spec.genesis_slot);
|
||||||
|
|
||||||
let mut current_head = *justified_block_start;
|
let mut current_head = *justified_block_start;
|
||||||
@ -434,7 +434,7 @@ impl<T: ClientDB + Sized> ForkChoice for BitwiseLMDGhost<T> {
|
|||||||
.block_store
|
.block_store
|
||||||
.get_deserialized(¤t_head)?
|
.get_deserialized(¤t_head)?
|
||||||
.ok_or_else(|| ForkChoiceError::MissingBeaconBlock(current_head))?
|
.ok_or_else(|| ForkChoiceError::MissingBeaconBlock(current_head))?
|
||||||
.slot()
|
.slot
|
||||||
.height(spec.genesis_slot);
|
.height(spec.genesis_slot);
|
||||||
// prune the latest votes for votes that are not part of current chosen chain
|
// prune the latest votes for votes that are not part of current chosen chain
|
||||||
// more specifically, only keep votes that have head as an ancestor
|
// more specifically, only keep votes that have head as an ancestor
|
||||||
|
@ -11,8 +11,8 @@ use std::cmp::Ordering;
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use types::{
|
use types::{
|
||||||
readers::BeaconBlockReader, validator_registry::get_active_validator_indices, BeaconBlock,
|
validator_registry::get_active_validator_indices, BeaconBlock, ChainSpec, Hash256, Slot,
|
||||||
ChainSpec, Hash256, Slot, SlotHeight,
|
SlotHeight,
|
||||||
};
|
};
|
||||||
|
|
||||||
//TODO: Pruning - Children
|
//TODO: Pruning - Children
|
||||||
@ -226,17 +226,17 @@ impl<T: ClientDB + Sized> ForkChoice for OptimizedLMDGhost<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_deserialized(&block.parent_root)?
|
.get_deserialized(&block.previous_block_root)?
|
||||||
.ok_or_else(|| ForkChoiceError::MissingBeaconBlock(block.parent_root))?
|
.ok_or_else(|| ForkChoiceError::MissingBeaconBlock(block.previous_block_root))?
|
||||||
.slot()
|
.slot
|
||||||
.height(spec.genesis_slot);
|
.height(spec.genesis_slot);
|
||||||
|
|
||||||
let parent_hash = &block.parent_root;
|
let parent_hash = &block.previous_block_root;
|
||||||
|
|
||||||
// add the new block to the children of parent
|
// add the new block to the children of parent
|
||||||
(*self
|
(*self
|
||||||
.children
|
.children
|
||||||
.entry(block.parent_root)
|
.entry(block.previous_block_root)
|
||||||
.or_insert_with(|| vec![]))
|
.or_insert_with(|| vec![]))
|
||||||
.push(block_hash.clone());
|
.push(block_hash.clone());
|
||||||
|
|
||||||
@ -280,7 +280,7 @@ impl<T: ClientDB + Sized> ForkChoice for OptimizedLMDGhost<T> {
|
|||||||
.block_store
|
.block_store
|
||||||
.get_deserialized(&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(spec.genesis_slot);
|
.height(spec.genesis_slot);
|
||||||
|
|
||||||
// get the height of the past target block
|
// get the height of the past target block
|
||||||
@ -288,7 +288,7 @@ impl<T: ClientDB + Sized> ForkChoice for OptimizedLMDGhost<T> {
|
|||||||
.block_store
|
.block_store
|
||||||
.get_deserialized(&attestation_target)?
|
.get_deserialized(&attestation_target)?
|
||||||
.ok_or_else(|| ForkChoiceError::MissingBeaconBlock(*attestation_target))?
|
.ok_or_else(|| ForkChoiceError::MissingBeaconBlock(*attestation_target))?
|
||||||
.slot()
|
.slot
|
||||||
.height(spec.genesis_slot);
|
.height(spec.genesis_slot);
|
||||||
// update the attestation only if the new target is higher
|
// update the attestation only if the new target is higher
|
||||||
if past_block_height < block_height {
|
if past_block_height < block_height {
|
||||||
@ -314,8 +314,8 @@ impl<T: ClientDB + Sized> ForkChoice for OptimizedLMDGhost<T> {
|
|||||||
.get_deserialized(&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;
|
||||||
let state_root = block.state_root();
|
let state_root = block.state_root;
|
||||||
let mut block_height = block_slot.height(spec.genesis_slot);
|
let mut block_height = block_slot.height(spec.genesis_slot);
|
||||||
|
|
||||||
let mut current_head = *justified_block_start;
|
let mut current_head = *justified_block_start;
|
||||||
@ -405,7 +405,7 @@ impl<T: ClientDB + Sized> ForkChoice for OptimizedLMDGhost<T> {
|
|||||||
.block_store
|
.block_store
|
||||||
.get_deserialized(¤t_head)?
|
.get_deserialized(¤t_head)?
|
||||||
.ok_or_else(|| ForkChoiceError::MissingBeaconBlock(current_head))?
|
.ok_or_else(|| ForkChoiceError::MissingBeaconBlock(current_head))?
|
||||||
.slot()
|
.slot
|
||||||
.height(spec.genesis_slot);
|
.height(spec.genesis_slot);
|
||||||
// prune the latest votes for votes that are not part of current chosen chain
|
// prune the latest votes for votes that are not part of current chosen chain
|
||||||
// more specifically, only keep votes that have head as an ancestor
|
// more specifically, only keep votes that have head as an ancestor
|
||||||
|
@ -9,8 +9,7 @@ use log::{debug, trace};
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use types::{
|
use types::{
|
||||||
readers::BeaconBlockReader, validator_registry::get_active_validator_indices, BeaconBlock,
|
validator_registry::get_active_validator_indices, BeaconBlock, ChainSpec, Hash256, Slot,
|
||||||
ChainSpec, Hash256, Slot,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//TODO: Pruning and syncing
|
//TODO: Pruning and syncing
|
||||||
@ -95,7 +94,7 @@ where
|
|||||||
.block_store
|
.block_store
|
||||||
.get_deserialized(&block_root)?
|
.get_deserialized(&block_root)?
|
||||||
.ok_or_else(|| ForkChoiceError::MissingBeaconBlock(*block_root))?
|
.ok_or_else(|| ForkChoiceError::MissingBeaconBlock(*block_root))?
|
||||||
.slot();
|
.slot;
|
||||||
|
|
||||||
for (vote_hash, votes) in latest_votes.iter() {
|
for (vote_hash, votes) in latest_votes.iter() {
|
||||||
let (root_at_slot, _) = self
|
let (root_at_slot, _) = self
|
||||||
@ -122,7 +121,7 @@ impl<T: ClientDB + Sized> ForkChoice for SlowLMDGhost<T> {
|
|||||||
// add the new block to the children of parent
|
// add the new block to the children of parent
|
||||||
(*self
|
(*self
|
||||||
.children
|
.children
|
||||||
.entry(block.parent_root)
|
.entry(block.previous_block_root)
|
||||||
.or_insert_with(|| vec![]))
|
.or_insert_with(|| vec![]))
|
||||||
.push(block_hash.clone());
|
.push(block_hash.clone());
|
||||||
|
|
||||||
@ -155,7 +154,7 @@ impl<T: ClientDB + Sized> ForkChoice for SlowLMDGhost<T> {
|
|||||||
.block_store
|
.block_store
|
||||||
.get_deserialized(&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(spec.genesis_slot);
|
.height(spec.genesis_slot);
|
||||||
|
|
||||||
// get the height of the past target block
|
// get the height of the past target block
|
||||||
@ -163,7 +162,7 @@ impl<T: ClientDB + Sized> ForkChoice for SlowLMDGhost<T> {
|
|||||||
.block_store
|
.block_store
|
||||||
.get_deserialized(&attestation_target)?
|
.get_deserialized(&attestation_target)?
|
||||||
.ok_or_else(|| ForkChoiceError::MissingBeaconBlock(*attestation_target))?
|
.ok_or_else(|| ForkChoiceError::MissingBeaconBlock(*attestation_target))?
|
||||||
.slot()
|
.slot
|
||||||
.height(spec.genesis_slot);
|
.height(spec.genesis_slot);
|
||||||
// update the attestation only if the new target is higher
|
// update the attestation only if the new target is higher
|
||||||
if past_block_height < block_height {
|
if past_block_height < block_height {
|
||||||
@ -186,9 +185,9 @@ impl<T: ClientDB + Sized> ForkChoice for SlowLMDGhost<T> {
|
|||||||
.get_deserialized(&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;
|
||||||
|
|
||||||
let latest_votes = self.get_latest_votes(&start_state_root, start.slot(), spec)?;
|
let latest_votes = self.get_latest_votes(&start_state_root, start.slot, spec)?;
|
||||||
|
|
||||||
let mut head_hash = *justified_block_start;
|
let mut head_hash = *justified_block_start;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user