Apply Danny's code review

This commit is contained in:
Aditya Asgaonkar 2021-11-22 09:34:32 -08:00 committed by Danny Ryan
parent 859bbf4358
commit 88c76abd7f
No known key found for this signature in database
GPG Key ID: 2765A792E42CE07A
3 changed files with 13 additions and 10 deletions

View File

@ -176,8 +176,10 @@ def on_block(store: Store, signed_block: SignedBeaconBlock) -> None:
store.block_states[hash_tree_root(block)] = state store.block_states[hash_tree_root(block)] = state
# Add proposer score boost if the block is timely # Add proposer score boost if the block is timely
if (get_current_slot(store) == block.slot and is_before_attestation_broadcast = (
store.time % SECONDS_PER_SLOT < SECONDS_PER_SLOT // ATTESTATION_OFFSET_QUOTIENT): 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( store.proposer_score_boost = LatestMessage(
root=hash_tree_root(block), root=hash_tree_root(block),
epoch=compute_epoch_at_slot(block.slot) epoch=compute_epoch_at_slot(block.slot)

View File

@ -176,12 +176,11 @@ def get_latest_attesting_balance(store: Store, root: Root) -> Gwei:
)) ))
proposer_score = Gwei(0) proposer_score = Gwei(0)
if store.proposer_score_boost.root != Root(): if store.proposer_score_boost.root != Root():
block_slot = store.blocks[root].slot block = store.blocks[root]
if get_ancestor(store, root, block_slot) == store.proposer_score_boost.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))) num_validators = len(get_active_validator_indices(state, get_current_epoch(state)))
avg_balance = get_total_active_balance(state) // num_validators avg_balance = get_total_active_balance(state) // num_validators
block_epoch = compute_epoch_at_slot(block_slot) committee_size = num_validators // SLOTS_PER_EPOCH
committee_size = get_committee_count_per_slot(state, block_epoch) * TARGET_COMMITTEE_SIZE
committee_weight = committee_size * avg_balance committee_weight = committee_size * avg_balance
proposer_score = (committee_weight * PROPOSER_SCORE_BOOST) // 100 proposer_score = (committee_weight * PROPOSER_SCORE_BOOST) // 100
return attestation_score + proposer_score 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 store.block_states[hash_tree_root(block)] = state
# Add proposer score boost if the block is timely # Add proposer score boost if the block is timely
if (get_current_slot(store) == block.slot and is_before_attestation_broadcast = (
store.time % SECONDS_PER_SLOT < SECONDS_PER_SLOT // ATTESTATION_OFFSET_QUOTIENT): 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( store.proposer_score_boost = LatestMessage(
root=hash_tree_root(block), root=hash_tree_root(block),
epoch=compute_epoch_at_slot(block.slot) epoch=compute_epoch_at_slot(block.slot)

View File

@ -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 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. *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 #### 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. Selection proofs are provided in `AggregateAndProof` to prove to the gossip channel that the validator has been selected as an aggregator.