From 88c76abd7fba95ef8352dbf2b256e7eb3687a65b Mon Sep 17 00:00:00 2001 From: Aditya Asgaonkar Date: Mon, 22 Nov 2021 09:34:32 -0800 Subject: [PATCH] Apply Danny's code review --- specs/merge/fork-choice.md | 6 ++++-- specs/phase0/fork-choice.md | 13 +++++++------ specs/phase0/validator.md | 4 ++-- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/specs/merge/fork-choice.md b/specs/merge/fork-choice.md index f62c8e014..bf67d2f4f 100644 --- a/specs/merge/fork-choice.md +++ b/specs/merge/fork-choice.md @@ -176,8 +176,10 @@ def on_block(store: Store, signed_block: SignedBeaconBlock) -> None: store.block_states[hash_tree_root(block)] = state # Add proposer score boost if the block is timely - if (get_current_slot(store) == block.slot and - store.time % SECONDS_PER_SLOT < SECONDS_PER_SLOT // ATTESTATION_OFFSET_QUOTIENT): + is_before_attestation_broadcast = ( + store.time % SECONDS_PER_SLOT < SECONDS_PER_SLOT // ATTESTATION_OFFSET_QUOTIENT + ) + if get_current_slot(store) == block.slot and is_before_attestation_broadcast: store.proposer_score_boost = LatestMessage( root=hash_tree_root(block), epoch=compute_epoch_at_slot(block.slot) diff --git a/specs/phase0/fork-choice.md b/specs/phase0/fork-choice.md index 5cb87a061..f302887ec 100644 --- a/specs/phase0/fork-choice.md +++ b/specs/phase0/fork-choice.md @@ -176,12 +176,11 @@ def get_latest_attesting_balance(store: Store, root: Root) -> Gwei: )) proposer_score = Gwei(0) if store.proposer_score_boost.root != Root(): - block_slot = store.blocks[root].slot - if get_ancestor(store, root, block_slot) == store.proposer_score_boost.root: + block = store.blocks[root] + if get_ancestor(store, root, block.slot) == store.proposer_score_boost.root: num_validators = len(get_active_validator_indices(state, get_current_epoch(state))) avg_balance = get_total_active_balance(state) // num_validators - block_epoch = compute_epoch_at_slot(block_slot) - committee_size = get_committee_count_per_slot(state, block_epoch) * TARGET_COMMITTEE_SIZE + committee_size = num_validators // SLOTS_PER_EPOCH committee_weight = committee_size * avg_balance proposer_score = (committee_weight * PROPOSER_SCORE_BOOST) // 100 return attestation_score + proposer_score @@ -407,8 +406,10 @@ def on_block(store: Store, signed_block: SignedBeaconBlock) -> None: store.block_states[hash_tree_root(block)] = state # Add proposer score boost if the block is timely - if (get_current_slot(store) == block.slot and - store.time % SECONDS_PER_SLOT < SECONDS_PER_SLOT // ATTESTATION_OFFSET_QUOTIENT): + is_before_attestation_broadcast = ( + store.time % SECONDS_PER_SLOT < SECONDS_PER_SLOT // ATTESTATION_OFFSET_QUOTIENT + ) + if get_current_slot(store) == block.slot and is_before_attestation_broadcast: store.proposer_score_boost = LatestMessage( root=hash_tree_root(block), epoch=compute_epoch_at_slot(block.slot) diff --git a/specs/phase0/validator.md b/specs/phase0/validator.md index b25a9a8b3..209cc7e5d 100644 --- a/specs/phase0/validator.md +++ b/specs/phase0/validator.md @@ -446,7 +446,7 @@ def get_block_signature(state: BeaconState, block: BeaconBlock, privkey: int) -> A validator is expected to create, sign, and broadcast an attestation during each epoch. The `committee`, assigned `index`, and assigned `slot` for which the validator performs this role during an epoch are defined by `get_committee_assignment(state, epoch, validator_index)`. -A validator should create and broadcast the `attestation` to the associated attestation subnet when either (a) the validator has received a valid block from the expected block proposer for the assigned `slot` or (b) one-third of the `slot` has transpired (`SECONDS_PER_SLOT / ATTESTATION_OFFSET_QUOTIENT` seconds after the start of `slot`) -- whichever comes _first_. +A validator should create and broadcast the `attestation` to the associated attestation subnet when either (a) the validator has received a valid block from the expected block proposer for the assigned `slot` or (b) `1 / ATTESTATION_OFFSET_QUOTIENT` of the `slot` has transpired (`SECONDS_PER_SLOT / ATTESTATION_OFFSET_QUOTIENT` seconds after the start of `slot`) -- whichever comes _first_. *Note*: Although attestations during `GENESIS_EPOCH` do not count toward FFG finality, these initial attestations do give weight to the fork choice, are rewarded, and should be made. @@ -569,7 +569,7 @@ def get_aggregate_signature(attestations: Sequence[Attestation]) -> BLSSignature #### Broadcast aggregate -If the validator is selected to aggregate (`is_aggregator`), then they broadcast their best aggregate as a `SignedAggregateAndProof` to the global aggregate channel (`beacon_aggregate_and_proof`) two-thirds of the way through the `slot`-that is, `SECONDS_PER_SLOT * 2 / 3` seconds after the start of `slot`. +If the validator is selected to aggregate (`is_aggregator`), then they broadcast their best aggregate as a `SignedAggregateAndProof` to the global aggregate channel (`beacon_aggregate_and_proof`) `2 / ATTESTATION_OFFSET_QUOTIENT` of the way through the `slot`-that is, `SECONDS_PER_SLOT * 2 / ATTESTATION_OFFSET_QUOTIENT` seconds after the start of `slot`. Selection proofs are provided in `AggregateAndProof` to prove to the gossip channel that the validator has been selected as an aggregator.