Rebase the fc changes

This commit is contained in:
Hsiao-Wei Wang 2023-05-15 17:25:48 +08:00
parent f9c4076b87
commit 340f3cc1a3
No known key found for this signature in database
GPG Key ID: AE3D6B174F971DE4
1 changed files with 13 additions and 13 deletions

View File

@ -86,16 +86,22 @@ def on_block(store: Store, signed_block: SignedBeaconBlock) -> None:
finalized_slot = compute_start_slot_at_epoch(store.finalized_checkpoint.epoch) finalized_slot = compute_start_slot_at_epoch(store.finalized_checkpoint.epoch)
assert block.slot > finalized_slot assert block.slot > finalized_slot
# Check block is a descendant of the finalized block at the checkpoint finalized slot # Check block is a descendant of the finalized block at the checkpoint finalized slot
assert get_ancestor(store, block.parent_root, finalized_slot) == store.finalized_checkpoint.root finalized_checkpoint_block = get_checkpoint_block(
store,
block.parent_root,
store.finalized_checkpoint.epoch,
)
assert store.finalized_checkpoint.root == finalized_checkpoint_block
# Check the block is valid and compute the post-state # Check the block is valid and compute the post-state
state = pre_state.copy() state = pre_state.copy()
block_root = hash_tree_root(block)
state_transition(state, signed_block, True) state_transition(state, signed_block, True)
# Add new block to the store # Add new block to the store
store.blocks[hash_tree_root(block)] = block store.blocks[block_root] = block
# Add new state for this block to the store # Add new state for this block to the store
store.block_states[hash_tree_root(block)] = state store.block_states[block_root] = state
# Add proposer score boost if the block is timely # Add proposer score boost if the block is timely
time_into_slot = (store.time - store.genesis_time) % SECONDS_PER_SLOT time_into_slot = (store.time - store.genesis_time) % SECONDS_PER_SLOT
@ -103,15 +109,9 @@ def on_block(store: Store, signed_block: SignedBeaconBlock) -> None:
if get_current_slot(store) == block.slot and is_before_attesting_interval: if get_current_slot(store) == block.slot and is_before_attesting_interval:
store.proposer_boost_root = hash_tree_root(block) store.proposer_boost_root = hash_tree_root(block)
# Update justified checkpoint # Update checkpoints in store if necessary
if state.current_justified_checkpoint.epoch > store.justified_checkpoint.epoch: update_checkpoints(store, state.current_justified_checkpoint, state.finalized_checkpoint)
if state.current_justified_checkpoint.epoch > store.best_justified_checkpoint.epoch:
store.best_justified_checkpoint = state.current_justified_checkpoint
if should_update_justified_checkpoint(store, state.current_justified_checkpoint):
store.justified_checkpoint = state.current_justified_checkpoint
# Update finalized checkpoint # Eagerly compute unrealized justification and finality.
if state.finalized_checkpoint.epoch > store.finalized_checkpoint.epoch: compute_pulled_up_tip(store, block_root)
store.finalized_checkpoint = state.finalized_checkpoint
store.justified_checkpoint = state.current_justified_checkpoint
``` ```