From 023ce333a183781cf7af304cf39526ffaae6e557 Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Tue, 28 Jan 2020 13:36:10 +1100 Subject: [PATCH] General tidy --- beacon_node/beacon_chain/src/beacon_chain.rs | 6 +++--- eth2/proto_array_fork_choice/src/bin.rs | 4 ++-- eth2/proto_array_fork_choice/src/proto_array.rs | 7 ++----- eth2/proto_array_fork_choice/src/ssz_container.rs | 4 ---- 4 files changed, 7 insertions(+), 14 deletions(-) diff --git a/beacon_node/beacon_chain/src/beacon_chain.rs b/beacon_node/beacon_chain/src/beacon_chain.rs index 5eeae7b5ee..6184013525 100644 --- a/beacon_node/beacon_chain/src/beacon_chain.rs +++ b/beacon_node/beacon_chain/src/beacon_chain.rs @@ -61,7 +61,7 @@ pub enum BlockProcessingOutcome { /// The parent block was unknown. ParentUnknown { parent: Hash256, - reference_location: String, + reference_location: &'static str, }, /// The block slot is greater than the present slot. FutureSlot { @@ -1239,7 +1239,7 @@ impl BeaconChain { if !self.fork_choice.contains_block(&block.parent_root) { return Ok(BlockProcessingOutcome::ParentUnknown { parent: block.parent_root, - reference_location: "fork_choice".to_string(), + reference_location: "fork_choice", }); } @@ -1280,7 +1280,7 @@ impl BeaconChain { None => { return Ok(BlockProcessingOutcome::ParentUnknown { parent: block.parent_root, - reference_location: "database".to_string(), + reference_location: "database", }); } }; diff --git a/eth2/proto_array_fork_choice/src/bin.rs b/eth2/proto_array_fork_choice/src/bin.rs index a1cc1c6835..ee93bd407f 100644 --- a/eth2/proto_array_fork_choice/src/bin.rs +++ b/eth2/proto_array_fork_choice/src/bin.rs @@ -13,8 +13,8 @@ use std::fs::File; fn main() { write_test_def_to_yaml("votes.yaml", get_votes_test_definition()); write_test_def_to_yaml("no_votes.yaml", get_no_votes_test_definition()); - write_test_def_to_yaml("no_votes.yaml", get_ffg_case_01_test_definition()); - write_test_def_to_yaml("no_votes.yaml", get_ffg_case_02_test_definition()); + write_test_def_to_yaml("ffg_01.yaml", get_ffg_case_01_test_definition()); + write_test_def_to_yaml("ffg_02.yaml", get_ffg_case_02_test_definition()); } fn write_test_def_to_yaml(filename: &str, def: ForkChoiceTestDefinition) { diff --git a/eth2/proto_array_fork_choice/src/proto_array.rs b/eth2/proto_array_fork_choice/src/proto_array.rs index 5a5791601c..f3245bd523 100644 --- a/eth2/proto_array_fork_choice/src/proto_array.rs +++ b/eth2/proto_array_fork_choice/src/proto_array.rs @@ -42,8 +42,7 @@ impl ProtoArray { /// - Back-propgrate each nodes delta to its parents delta. /// - Compare the current node with the parents best-child, updating it if the current node /// should become the best child. - /// - Update the parents best-descendant with the current node or its best-descendant, if - /// required. + /// - If required, update the parents best-descendant with the current node or its best-descendant. pub fn apply_score_changes( &mut self, mut deltas: Vec, @@ -187,8 +186,7 @@ impl ProtoArray { .get(best_descendant_index) .ok_or_else(|| Error::InvalidBestDescendant(best_descendant_index))?; - // It is a logic error to try and find the head starting from a block that does not match - // the filter. + // Perform a sanity check that the node is indeed valid to be the head. if !self.node_is_viable_for_head(&best_node) { return Err(Error::InvalidBestNode { start_root: *justified_root, @@ -329,7 +327,6 @@ impl ProtoArray { .get(best_child_index) .ok_or_else(|| Error::InvalidBestDescendant(best_child_index))?; - let child_leads_to_viable_head = self.node_leads_to_viable_head(&child)?; let best_child_leads_to_viable_head = self.node_leads_to_viable_head(&best_child)?; diff --git a/eth2/proto_array_fork_choice/src/ssz_container.rs b/eth2/proto_array_fork_choice/src/ssz_container.rs index 30c52c08fd..bd305ae72c 100644 --- a/eth2/proto_array_fork_choice/src/ssz_container.rs +++ b/eth2/proto_array_fork_choice/src/ssz_container.rs @@ -13,9 +13,6 @@ pub struct SszContainer { votes: Vec, balances: Vec, prune_threshold: usize, - // TODO: this field is no longer required, I'm just leaving it here for the time being so we - // don't need to resync nodes. - ffg_update_required: bool, justified_epoch: Epoch, finalized_epoch: Epoch, nodes: Vec, @@ -30,7 +27,6 @@ impl From<&ProtoArrayForkChoice> for SszContainer { votes: from.votes.read().0.clone(), balances: from.balances.read().clone(), prune_threshold: proto_array.prune_threshold, - ffg_update_required: false, justified_epoch: proto_array.justified_epoch, finalized_epoch: proto_array.finalized_epoch, nodes: proto_array.nodes.clone(),