Fix `attestation.data.shard_head_root` bug

This commit is contained in:
Hsiao-Wei Wang 2020-06-19 23:34:51 +08:00
parent 80c6c0b5f1
commit c28857e4e1
No known key found for this signature in database
GPG Key ID: 95B070122902DEA4
2 changed files with 8 additions and 7 deletions

View File

@ -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 >=

View File

@ -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