From d94540c85c6f98068c6a5cadac312c55eff22353 Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Sun, 17 Mar 2019 17:59:29 +1100 Subject: [PATCH] Remove readers from fork choice crate. --- eth2/fork_choice/src/bitwise_lmd_ghost.rs | 24 ++++++++++----------- eth2/fork_choice/src/optimized_lmd_ghost.rs | 24 ++++++++++----------- eth2/fork_choice/src/slow_lmd_ghost.rs | 15 ++++++------- 3 files changed, 31 insertions(+), 32 deletions(-) diff --git a/eth2/fork_choice/src/bitwise_lmd_ghost.rs b/eth2/fork_choice/src/bitwise_lmd_ghost.rs index d7b10015b..9410fd203 100644 --- a/eth2/fork_choice/src/bitwise_lmd_ghost.rs +++ b/eth2/fork_choice/src/bitwise_lmd_ghost.rs @@ -11,8 +11,8 @@ use log::{debug, trace}; use std::collections::HashMap; use std::sync::Arc; use types::{ - readers::BeaconBlockReader, validator_registry::get_active_validator_indices, BeaconBlock, - ChainSpec, Hash256, Slot, SlotHeight, + validator_registry::get_active_validator_indices, BeaconBlock, ChainSpec, Hash256, Slot, + SlotHeight, }; //TODO: Pruning - Children @@ -255,17 +255,17 @@ impl ForkChoice for BitwiseLMDGhost { // get the height of the parent let parent_height = self .block_store - .get_deserialized(&block.parent_root)? - .ok_or_else(|| ForkChoiceError::MissingBeaconBlock(block.parent_root))? - .slot() + .get_deserialized(&block.previous_block_root)? + .ok_or_else(|| ForkChoiceError::MissingBeaconBlock(block.previous_block_root))? + .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 (*self .children - .entry(block.parent_root) + .entry(block.previous_block_root) .or_insert_with(|| vec![])) .push(block_hash.clone()); @@ -309,7 +309,7 @@ impl ForkChoice for BitwiseLMDGhost { .block_store .get_deserialized(&target_block_root)? .ok_or_else(|| ForkChoiceError::MissingBeaconBlock(*target_block_root))? - .slot() + .slot .height(spec.genesis_slot); // get the height of the past target block @@ -317,7 +317,7 @@ impl ForkChoice for BitwiseLMDGhost { .block_store .get_deserialized(&attestation_target)? .ok_or_else(|| ForkChoiceError::MissingBeaconBlock(*attestation_target))? - .slot() + .slot .height(spec.genesis_slot); // update the attestation only if the new target is higher if past_block_height < block_height { @@ -343,8 +343,8 @@ impl ForkChoice for BitwiseLMDGhost { .get_deserialized(&justified_block_start)? .ok_or_else(|| ForkChoiceError::MissingBeaconBlock(*justified_block_start))?; - let block_slot = block.slot(); - let state_root = block.state_root(); + let block_slot = block.slot; + let state_root = block.state_root; let mut block_height = block_slot.height(spec.genesis_slot); let mut current_head = *justified_block_start; @@ -434,7 +434,7 @@ impl ForkChoice for BitwiseLMDGhost { .block_store .get_deserialized(¤t_head)? .ok_or_else(|| ForkChoiceError::MissingBeaconBlock(current_head))? - .slot() + .slot .height(spec.genesis_slot); // 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 diff --git a/eth2/fork_choice/src/optimized_lmd_ghost.rs b/eth2/fork_choice/src/optimized_lmd_ghost.rs index 30c84e9e1..e1b8914a6 100644 --- a/eth2/fork_choice/src/optimized_lmd_ghost.rs +++ b/eth2/fork_choice/src/optimized_lmd_ghost.rs @@ -11,8 +11,8 @@ use std::cmp::Ordering; use std::collections::HashMap; use std::sync::Arc; use types::{ - readers::BeaconBlockReader, validator_registry::get_active_validator_indices, BeaconBlock, - ChainSpec, Hash256, Slot, SlotHeight, + validator_registry::get_active_validator_indices, BeaconBlock, ChainSpec, Hash256, Slot, + SlotHeight, }; //TODO: Pruning - Children @@ -226,17 +226,17 @@ impl ForkChoice for OptimizedLMDGhost { // get the height of the parent let parent_height = self .block_store - .get_deserialized(&block.parent_root)? - .ok_or_else(|| ForkChoiceError::MissingBeaconBlock(block.parent_root))? - .slot() + .get_deserialized(&block.previous_block_root)? + .ok_or_else(|| ForkChoiceError::MissingBeaconBlock(block.previous_block_root))? + .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 (*self .children - .entry(block.parent_root) + .entry(block.previous_block_root) .or_insert_with(|| vec![])) .push(block_hash.clone()); @@ -280,7 +280,7 @@ impl ForkChoice for OptimizedLMDGhost { .block_store .get_deserialized(&target_block_root)? .ok_or_else(|| ForkChoiceError::MissingBeaconBlock(*target_block_root))? - .slot() + .slot .height(spec.genesis_slot); // get the height of the past target block @@ -288,7 +288,7 @@ impl ForkChoice for OptimizedLMDGhost { .block_store .get_deserialized(&attestation_target)? .ok_or_else(|| ForkChoiceError::MissingBeaconBlock(*attestation_target))? - .slot() + .slot .height(spec.genesis_slot); // update the attestation only if the new target is higher if past_block_height < block_height { @@ -314,8 +314,8 @@ impl ForkChoice for OptimizedLMDGhost { .get_deserialized(&justified_block_start)? .ok_or_else(|| ForkChoiceError::MissingBeaconBlock(*justified_block_start))?; - let block_slot = block.slot(); - let state_root = block.state_root(); + let block_slot = block.slot; + let state_root = block.state_root; let mut block_height = block_slot.height(spec.genesis_slot); let mut current_head = *justified_block_start; @@ -405,7 +405,7 @@ impl ForkChoice for OptimizedLMDGhost { .block_store .get_deserialized(¤t_head)? .ok_or_else(|| ForkChoiceError::MissingBeaconBlock(current_head))? - .slot() + .slot .height(spec.genesis_slot); // 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 diff --git a/eth2/fork_choice/src/slow_lmd_ghost.rs b/eth2/fork_choice/src/slow_lmd_ghost.rs index abf13f21b..af58aa7b8 100644 --- a/eth2/fork_choice/src/slow_lmd_ghost.rs +++ b/eth2/fork_choice/src/slow_lmd_ghost.rs @@ -9,8 +9,7 @@ use log::{debug, trace}; use std::collections::HashMap; use std::sync::Arc; use types::{ - readers::BeaconBlockReader, validator_registry::get_active_validator_indices, BeaconBlock, - ChainSpec, Hash256, Slot, + validator_registry::get_active_validator_indices, BeaconBlock, ChainSpec, Hash256, Slot, }; //TODO: Pruning and syncing @@ -95,7 +94,7 @@ where .block_store .get_deserialized(&block_root)? .ok_or_else(|| ForkChoiceError::MissingBeaconBlock(*block_root))? - .slot(); + .slot; for (vote_hash, votes) in latest_votes.iter() { let (root_at_slot, _) = self @@ -122,7 +121,7 @@ impl ForkChoice for SlowLMDGhost { // add the new block to the children of parent (*self .children - .entry(block.parent_root) + .entry(block.previous_block_root) .or_insert_with(|| vec![])) .push(block_hash.clone()); @@ -155,7 +154,7 @@ impl ForkChoice for SlowLMDGhost { .block_store .get_deserialized(&target_block_root)? .ok_or_else(|| ForkChoiceError::MissingBeaconBlock(*target_block_root))? - .slot() + .slot .height(spec.genesis_slot); // get the height of the past target block @@ -163,7 +162,7 @@ impl ForkChoice for SlowLMDGhost { .block_store .get_deserialized(&attestation_target)? .ok_or_else(|| ForkChoiceError::MissingBeaconBlock(*attestation_target))? - .slot() + .slot .height(spec.genesis_slot); // update the attestation only if the new target is higher if past_block_height < block_height { @@ -186,9 +185,9 @@ impl ForkChoice for SlowLMDGhost { .get_deserialized(&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;