From 1a5016157a24f059afcab33a309adc2f21e47543 Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Fri, 19 Jun 2020 23:46:01 +0800 Subject: [PATCH] Fix 1. To make it more compatible, update `is_on_time_attestation` argument: replace `attestation: Attestation` with `attestation_data: AttestationData` 2. Fix `get_sample_shard_transition` --- specs/phase1/beacon-chain.md | 16 ++++++++-------- specs/phase1/validator.md | 2 +- .../core/pyspec/eth2spec/test/helpers/custody.py | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/specs/phase1/beacon-chain.md b/specs/phase1/beacon-chain.md index f90d61f26..f9b123d3b 100644 --- a/specs/phase1/beacon-chain.md +++ b/specs/phase1/beacon-chain.md @@ -652,11 +652,11 @@ def get_offset_slots(state: BeaconState, shard: Shard) -> Sequence[Slot]: ```python def is_on_time_attestation(state: BeaconState, - attestation: Attestation) -> bool: + attestation_data: AttestationData) -> bool: """ - Check if the given attestation is on-time. + Check if the given ``attestation_data`` is on-time. """ - return attestation.data.slot == compute_previous_slot(state.slot) + return attestation_data.slot == compute_previous_slot(state.slot) ``` #### `is_winning_attestation` @@ -667,11 +667,11 @@ def is_winning_attestation(state: BeaconState, committee_index: CommitteeIndex, winning_root: Root) -> bool: """ - Check if ``attestation`` helped contribute to the successful crosslink of - ``winning_root`` formed by ``committee_index`` committee at the current slot. + Check if on-time ``attestation`` helped contribute to the successful crosslink of + ``winning_root`` formed by ``committee_index`` committee. """ return ( - is_on_time_attestation(state, attestation) + is_on_time_attestation(state, attestation.data) and attestation.data.index == committee_index and attestation.data.shard_transition_root == winning_root ) @@ -766,7 +766,7 @@ def validate_attestation(state: BeaconState, attestation: Attestation) -> None: assert attestation.data.source == state.previous_justified_checkpoint # Type 1: on-time attestations - if is_on_time_attestation(state, attestation): + if is_on_time_attestation(state, attestation.data): # Correct parent block root assert data.beacon_block_root == get_block_root_at_slot(state, compute_previous_slot(state.slot)) # Correct shard number @@ -941,7 +941,7 @@ def process_crosslinks(state: BeaconState, # Since the attestations are validated, all `shard_attestations` satisfy `attestation.data.shard == shard` shard_attestations = [ attestation for attestation in attestations - if is_on_time_attestation(state, attestation) and attestation.data.index == committee_index + if is_on_time_attestation(state, attestation.data) and attestation.data.index == committee_index ] winning_root = process_crosslink_for_shard( state, committee_index, shard_transitions[shard], shard_attestations diff --git a/specs/phase1/validator.md b/specs/phase1/validator.md index f347f8757..fd3b7fef6 100644 --- a/specs/phase1/validator.md +++ b/specs/phase1/validator.md @@ -157,7 +157,7 @@ def get_shard_winning_roots(state: BeaconState, # All attestations in the block for this committee/shard and are "on time" shard_attestations = [ attestation for attestation in attestations - if is_on_time_attestation(state, attestation) and attestation.data.index == committee_index + if is_on_time_attestation(state, attestation.data) and attestation.data.index == committee_index ] committee = get_beacon_committee(state, on_time_attestation_slot, committee_index) diff --git a/tests/core/pyspec/eth2spec/test/helpers/custody.py b/tests/core/pyspec/eth2spec/test/helpers/custody.py index f63a07099..d25b91a41 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/custody.py +++ b/tests/core/pyspec/eth2spec/test/helpers/custody.py @@ -172,7 +172,7 @@ def get_sample_shard_transition(spec, start_slot, block_lengths): start_slot=start_slot, shard_block_lengths=block_lengths, shard_data_roots=b, - shard_states=[spec.Root() for x in block_lengths], + shard_states=[spec.ShardState() for x in block_lengths], proposer_signature_aggregate=spec.BLSSignature(), ) return shard_transition