From 7b99588b8affbfaad119c00a0be04e611a7bdafc Mon Sep 17 00:00:00 2001 From: Eitan Seri-Levi Date: Wed, 3 May 2023 09:02:58 +0000 Subject: [PATCH] simplify calculate_committee_fraction (#4213) ## Issue Addressed [#4211](https://github.com/sigp/lighthouse/issues/4211) ## Proposed Changes This PR conforms the helper function `calculate_committee_fraction` to the [v1.3.0 spec](https://github.com/ethereum/consensus-specs/blob/v1.3.0/specs/phase0/fork-choice.md#get_weight) ## Additional Info the old definition of `calculate_committee_fraction` is almost identical, but the new definition is simpler. --- .../src/fork_choice_test_definition/execution_status.rs | 6 +++--- consensus/proto_array/src/proto_array.rs | 6 +----- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/consensus/proto_array/src/fork_choice_test_definition/execution_status.rs b/consensus/proto_array/src/fork_choice_test_definition/execution_status.rs index ede5bb39481..aa26a843069 100644 --- a/consensus/proto_array/src/fork_choice_test_definition/execution_status.rs +++ b/consensus/proto_array/src/fork_choice_test_definition/execution_status.rs @@ -987,11 +987,11 @@ pub fn get_execution_status_test_definition_03() -> ForkChoiceTestDefinition { ops.push(Operation::AssertWeight { block_root: get_root(0), - weight: 33_000, + weight: 33_250, }); ops.push(Operation::AssertWeight { block_root: get_root(1), - weight: 33_000, + weight: 33_250, }); ops.push(Operation::AssertWeight { block_root: get_root(2), @@ -1000,7 +1000,7 @@ pub fn get_execution_status_test_definition_03() -> ForkChoiceTestDefinition { ops.push(Operation::AssertWeight { block_root: get_root(3), // This is a "magic number" generated from `calculate_committee_fraction`. - weight: 31_000, + weight: 31_250, }); // Invalidate the payload of 3. diff --git a/consensus/proto_array/src/proto_array.rs b/consensus/proto_array/src/proto_array.rs index 2c19206cb75..1cc34beff0c 100644 --- a/consensus/proto_array/src/proto_array.rs +++ b/consensus/proto_array/src/proto_array.rs @@ -1055,13 +1055,9 @@ pub fn calculate_committee_fraction( justified_balances: &JustifiedBalances, proposer_score_boost: u64, ) -> Option { - let average_balance = justified_balances + let committee_weight = justified_balances .total_effective_balance - .checked_div(justified_balances.num_active_validators)?; - let committee_size = justified_balances - .num_active_validators .checked_div(E::slots_per_epoch())?; - let committee_weight = committee_size.checked_mul(average_balance)?; committee_weight .checked_mul(proposer_score_boost)? .checked_div(100)