From 536c0733f84bb9a3868f858982f677b8979e433c Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Fri, 17 Apr 2020 00:04:27 +0800 Subject: [PATCH] Refactor + simplify skipped slot processing --- specs/phase1/beacon-chain.md | 23 ++++++++++------------- specs/phase1/fraud-proofs.md | 9 +-------- 2 files changed, 11 insertions(+), 21 deletions(-) diff --git a/specs/phase1/beacon-chain.md b/specs/phase1/beacon-chain.md index 29ba742b94..5c67fe4f2a 100644 --- a/specs/phase1/beacon-chain.md +++ b/specs/phase1/beacon-chain.md @@ -712,7 +712,6 @@ def apply_shard_transition(state: BeaconState, shard: Shard, transition: ShardTr assert transition.start_slot == offset_slots[0] headers = [] - header = ShardBlockHeader() proposers = [] prev_gasprice = state.shard_states[shard].gasprice shard_parent_root = state.shard_states[shard].latest_block_root @@ -720,19 +719,17 @@ def apply_shard_transition(state: BeaconState, shard: Shard, transition: ShardTr shard_block_length = transition.shard_block_lengths[i] is_empty_proposal = shard_block_length == 0 shard_state = transition.shard_states[i] - proposal_index = get_shard_proposer_index(state, offset_slots[i], shard) - # Reconstruct shard headers - header = ShardBlockHeader( - shard_parent_root=shard_parent_root, - beacon_parent_root=get_block_root_at_slot(state, offset_slots[i]), - proposer_index=proposal_index, - slot=offset_slots[i], - body_root=transition.shard_data_roots[i] - ) - shard_parent_root = hash_tree_root(header) - if not is_empty_proposal: - # Only add non-empty signature + proposal_index = get_shard_proposer_index(state, offset_slots[i], shard) + # Reconstruct shard headers + header = ShardBlockHeader( + shard_parent_root=shard_parent_root, + beacon_parent_root=get_block_root_at_slot(state, offset_slots[i]), + proposer_index=proposal_index, + slot=offset_slots[i], + body_root=transition.shard_data_roots[i] + ) + shard_parent_root = hash_tree_root(header) headers.append(header) proposers.append(proposal_index) diff --git a/specs/phase1/fraud-proofs.md b/specs/phase1/fraud-proofs.md index d58eaf3210..2a48dae8c7 100644 --- a/specs/phase1/fraud-proofs.md +++ b/specs/phase1/fraud-proofs.md @@ -197,7 +197,6 @@ def get_proposal_at_slot(beacon_state: BeaconState, Return ``proposal``, ``shard_state`` of the given ``slot``. Note that this function doesn't change the state. """ - proposer_index = get_shard_proposer_index(beacon_state, slot, shard) shard_state = shard_state.copy() # Don't update the given shard_state choices = get_proposal_choices_at_slot( beacon_state=beacon_state, @@ -208,13 +207,7 @@ def get_proposal_at_slot(beacon_state: BeaconState, validate_signature=validate_signature, ) if len(choices) == 0: - block_header = ShardBlock( - shard_parent_root=shard_state.latest_block_root, - beacon_parent_root=get_block_root_at_slot(beacon_state, slot), - slot=slot, - proposer_index=proposer_index, - ) - proposal = SignedShardBlock(message=block_header) + proposal = SignedShardBlock() # empty proposal elif len(choices) == 1: proposal = choices[0] else: