From 2199b8e0f08651edd2c7af7b26f75b01bd57868a Mon Sep 17 00:00:00 2001 From: Anton Nashatyrev Date: Fri, 30 Apr 2021 14:58:30 +0300 Subject: [PATCH 1/5] Calc the right root with respect to (slot, shard) for an empty PendingShardHeader --- specs/sharding/beacon-chain.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specs/sharding/beacon-chain.md b/specs/sharding/beacon-chain.md index 6fd83c9cf..df52cce41 100644 --- a/specs/sharding/beacon-chain.md +++ b/specs/sharding/beacon-chain.md @@ -763,7 +763,7 @@ def reset_pending_headers(state: BeaconState) -> None: slot=slot, shard=shard, commitment=DataCommitment(), - root=Root(), + root=hash_tree_root(ShardBlobHeader(slot = slot, shard = shard)), votes=Bitlist[MAX_VALIDATORS_PER_COMMITTEE]([0] * committee_length), confirmed=False, )) From dca6d3370a0c0095133dd0fddc32b3052fb61d39 Mon Sep 17 00:00:00 2001 From: Anton Nashatyrev Date: Fri, 30 Apr 2021 15:21:51 +0300 Subject: [PATCH 2/5] Search winning 'empty' PendingShardHeader index by the empty DataCommitment instead of zero Root --- specs/sharding/beacon-chain.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specs/sharding/beacon-chain.md b/specs/sharding/beacon-chain.md index df52cce41..68f6ccaa2 100644 --- a/specs/sharding/beacon-chain.md +++ b/specs/sharding/beacon-chain.md @@ -701,7 +701,7 @@ def process_pending_headers(state: BeaconState) -> None: winning_index = voting_balances.index(max(voting_balances)) else: # If no votes, zero wins - winning_index = [c.root for c in candidates].index(Root()) + winning_index = [c.commitment for c in candidates].index(DataCommitment()) candidates[winning_index].confirmed = True for slot_index in range(SLOTS_PER_EPOCH): for shard in range(SHARD_COUNT): From ddc59422ba31e8ec164239280a69868ae65ce7ce Mon Sep 17 00:00:00 2001 From: Anton Nashatyrev Date: Wed, 5 May 2021 13:21:15 +0300 Subject: [PATCH 3/5] Revert "Calc the right root with respect to (slot, shard) for an empty PendingShardHeader" This reverts commit 2199b8e0 --- specs/sharding/beacon-chain.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specs/sharding/beacon-chain.md b/specs/sharding/beacon-chain.md index 68f6ccaa2..decffdaa7 100644 --- a/specs/sharding/beacon-chain.md +++ b/specs/sharding/beacon-chain.md @@ -763,7 +763,7 @@ def reset_pending_headers(state: BeaconState) -> None: slot=slot, shard=shard, commitment=DataCommitment(), - root=hash_tree_root(ShardBlobHeader(slot = slot, shard = shard)), + root=Root(), votes=Bitlist[MAX_VALIDATORS_PER_COMMITTEE]([0] * committee_length), confirmed=False, )) From befe4c7db3a8d0bdda6719a220a9f010037a07b7 Mon Sep 17 00:00:00 2001 From: Anton Nashatyrev Date: Wed, 5 May 2021 13:21:25 +0300 Subject: [PATCH 4/5] Revert "Search winning 'empty' PendingShardHeader index by the empty DataCommitment instead of zero Root" This reverts commit dca6d337 --- specs/sharding/beacon-chain.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specs/sharding/beacon-chain.md b/specs/sharding/beacon-chain.md index decffdaa7..6fd83c9cf 100644 --- a/specs/sharding/beacon-chain.md +++ b/specs/sharding/beacon-chain.md @@ -701,7 +701,7 @@ def process_pending_headers(state: BeaconState) -> None: winning_index = voting_balances.index(max(voting_balances)) else: # If no votes, zero wins - winning_index = [c.commitment for c in candidates].index(DataCommitment()) + winning_index = [c.root for c in candidates].index(Root()) candidates[winning_index].confirmed = True for slot_index in range(SLOTS_PER_EPOCH): for shard in range(SHARD_COUNT): From 3cc1256a723ea719f9a81b4dedacb15c439ae327 Mon Sep 17 00:00:00 2001 From: Anton Nashatyrev Date: Wed, 5 May 2021 13:31:19 +0300 Subject: [PATCH 5/5] update_pending_votes: search pending header by header.(root + slot + shard) --- specs/sharding/beacon-chain.md | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/specs/sharding/beacon-chain.md b/specs/sharding/beacon-chain.md index 6fd83c9cf..b93cd2e2a 100644 --- a/specs/sharding/beacon-chain.md +++ b/specs/sharding/beacon-chain.md @@ -512,17 +512,22 @@ def update_pending_votes(state: BeaconState, attestation: Attestation) -> None: pending_headers = state.current_epoch_pending_shard_headers else: pending_headers = state.previous_epoch_pending_shard_headers - pending_header = None - for header in pending_headers: - if header.root == attestation.data.shard_header_root: - pending_header = header - assert pending_header is not None - assert pending_header.slot == attestation.data.slot - assert pending_header.shard == compute_shard_from_committee_index( + + attestation_shard = compute_shard_from_committee_index( state, attestation.data.slot, attestation.data.index, ) + pending_header = None + for header in pending_headers: + if ( + header.root == attestation.data.shard_header_root + and header.slot == attestation.data.slot + and header.shard == attestation_shard + ): + pending_header = header + assert pending_header is not None + for i in range(len(pending_header.votes)): pending_header.votes[i] = pending_header.votes[i] or attestation.aggregation_bits[i]