From c28857e4e1f7226cb177f60c94364398428d5b77 Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Fri, 19 Jun 2020 23:34:51 +0800 Subject: [PATCH] Fix `attestation.data.shard_head_root` bug --- specs/phase1/beacon-chain.md | 7 ++++--- tests/core/pyspec/eth2spec/test/helpers/attestations.py | 8 ++++---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/specs/phase1/beacon-chain.md b/specs/phase1/beacon-chain.md index aa250f9c4..f90d61f26 100644 --- a/specs/phase1/beacon-chain.md +++ b/specs/phase1/beacon-chain.md @@ -886,10 +886,11 @@ def process_crosslink_for_shard(state: BeaconState, for attestation in transition_attestations: participants = get_attesting_indices(state, attestation.data, attestation.aggregation_bits) transition_participants = transition_participants.union(participants) - if len(shard_transition.shard_data_roots) > 0: + if len(shard_transition.shard_states) > 0: # Is the `shard_transition` candidate - last_offset_index = len(shard_transition.shard_data_roots) - 1 - assert attestation.data.shard_head_root == shard_transition.shard_data_roots[last_offset_index] + last_offset_index = len(shard_transition.shard_states) - 1 + shard_head_root = shard_transition.shard_states[last_offset_index].latest_block_root + assert attestation.data.shard_head_root == shard_head_root enough_online_stake = ( get_total_balance(state, online_indices.intersection(transition_participants)) * 3 >= diff --git a/tests/core/pyspec/eth2spec/test/helpers/attestations.py b/tests/core/pyspec/eth2spec/test/helpers/attestations.py index 0c3f012f5..3445f9ff6 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/attestations.py +++ b/tests/core/pyspec/eth2spec/test/helpers/attestations.py @@ -83,14 +83,14 @@ def build_attestation_data(spec, state, slot, index, shard=None, shard_transitio attestation_data.shard = shard if shard_transition is not None: - lastest_shard_data_root_index = len(shard_transition.shard_data_roots) - 1 - attestation_data.shard_head_root = shard_transition.shard_data_roots[lastest_shard_data_root_index] + last_offset_index = len(shard_transition.shard_data_roots) - 1 + attestation_data.shard_head_root = shard_transition.shard_states[last_offset_index].latest_block_root attestation_data.shard_transition_root = shard_transition.hash_tree_root() else: if on_time: shard_transition = spec.get_shard_transition(state, shard, shard_blocks=[]) - lastest_shard_data_root_index = len(shard_transition.shard_data_roots) - 1 - attestation_data.shard_head_root = shard_transition.shard_data_roots[lastest_shard_data_root_index] + last_offset_index = len(shard_transition.shard_data_roots) - 1 + attestation_data.shard_head_root = shard_transition.shard_states[last_offset_index].latest_block_root attestation_data.shard_transition_root = shard_transition.hash_tree_root() else: attestation_data.shard_head_root = state.shard_states[shard].latest_block_root