Skip to content

Commit

Permalink
Refactor + simplify skipped slot processing
Browse files Browse the repository at this point in the history
  • Loading branch information
hwwhww committed Apr 16, 2020
1 parent f868754 commit 536c073
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 21 deletions.
23 changes: 10 additions & 13 deletions specs/phase1/beacon-chain.md
Original file line number Diff line number Diff line change
Expand Up @@ -712,27 +712,24 @@ 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
for i in range(len(offset_slots)):
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)

Expand Down
9 changes: 1 addition & 8 deletions specs/phase1/fraud-proofs.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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:
Expand Down

0 comments on commit 536c073

Please sign in to comment.