Skip to content

Commit

Permalink
Apply Danny's code review
Browse files Browse the repository at this point in the history
  • Loading branch information
adiasg authored and djrtwo committed Nov 22, 2021
1 parent 859bbf4 commit 88c76ab
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
6 changes: 4 additions & 2 deletions specs/merge/fork-choice.md
Expand Up @@ -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)
Expand Down
13 changes: 7 additions & 6 deletions specs/phase0/fork-choice.md
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions specs/phase0/validator.md
Expand Up @@ -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.

Expand Down Expand Up @@ -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.

Expand Down

0 comments on commit 88c76ab

Please sign in to comment.