Skip to content

Commit b1416c8

Browse files
committed
simplify calculate_committee_fraction (#4213)
## Issue Addressed [#4211](#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.
1 parent edbb47d commit b1416c8

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

consensus/proto_array/src/fork_choice_test_definition/execution_status.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -987,11 +987,11 @@ pub fn get_execution_status_test_definition_03() -> ForkChoiceTestDefinition {
987987

988988
ops.push(Operation::AssertWeight {
989989
block_root: get_root(0),
990-
weight: 33_000,
990+
weight: 33_250,
991991
});
992992
ops.push(Operation::AssertWeight {
993993
block_root: get_root(1),
994-
weight: 33_000,
994+
weight: 33_250,
995995
});
996996
ops.push(Operation::AssertWeight {
997997
block_root: get_root(2),
@@ -1000,7 +1000,7 @@ pub fn get_execution_status_test_definition_03() -> ForkChoiceTestDefinition {
10001000
ops.push(Operation::AssertWeight {
10011001
block_root: get_root(3),
10021002
// This is a "magic number" generated from `calculate_committee_fraction`.
1003-
weight: 31_000,
1003+
weight: 31_250,
10041004
});
10051005

10061006
// Invalidate the payload of 3.

consensus/proto_array/src/proto_array.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,13 +1055,9 @@ pub fn calculate_committee_fraction<E: EthSpec>(
10551055
justified_balances: &JustifiedBalances,
10561056
proposer_score_boost: u64,
10571057
) -> Option<u64> {
1058-
let average_balance = justified_balances
1058+
let committee_weight = justified_balances
10591059
.total_effective_balance
1060-
.checked_div(justified_balances.num_active_validators)?;
1061-
let committee_size = justified_balances
1062-
.num_active_validators
10631060
.checked_div(E::slots_per_epoch())?;
1064-
let committee_weight = committee_size.checked_mul(average_balance)?;
10651061
committee_weight
10661062
.checked_mul(proposer_score_boost)?
10671063
.checked_div(100)

0 commit comments

Comments
 (0)