Skip to content

Commit

Permalink
Provide different state root to db migrator
Browse files Browse the repository at this point in the history
  • Loading branch information
paulhauner committed Jun 28, 2022
1 parent be38daa commit 90730a7
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions beacon_node/beacon_chain/src/canonical_head.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,23 @@ impl<T: BeaconChainTypes> BeaconChain<T> {

// If the finalized checkpoint changed, perform some updates.
if new_view.finalized_checkpoint != old_view.finalized_checkpoint {
if let Err(e) = self.after_finalization(new_head, new_view, finalized_proto_block) {
// The store migration task requires the *state at the slot of the finalized epoch*,
// rather than the state of the latest finalized block. These two values will only
// differ when the first slot of the finalized epoch is a skip slot.
let new_finalized_slot = new_view
.finalized_checkpoint
.epoch
.start_slot(T::EthSpec::slots_per_epoch());
let new_finalized_state_root = self
.state_root_at_slot(new_finalized_slot)?
.ok_or(Error::MissingFinalizedStateRoot(new_finalized_slot))?;

if let Err(e) = self.after_finalization(
new_head,
new_view,
finalized_proto_block,
new_finalized_state_root,
) {
crit!(
self.log,
"Error updating finalization";
Expand Down Expand Up @@ -585,6 +601,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
new_head: &BeaconSnapshot<T::EthSpec>,
new_view: ForkChoiceView,
finalized_proto_block: ProtoBlock,
new_finalized_state_root: Hash256,
) -> Result<(), Error> {
self.op_pool
.prune_all(&new_head.beacon_state, self.epoch()?);
Expand Down Expand Up @@ -620,7 +637,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
});

chain.store_migrator.process_finalization(
finalized_proto_block.state_root.into(),
new_finalized_state_root.into(),
new_view.finalized_checkpoint,
chain.head_tracker.clone(),
)?;
Expand All @@ -635,6 +652,9 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
SseFinalizedCheckpoint {
epoch: new_view.finalized_checkpoint.epoch,
block: new_view.finalized_checkpoint.root,
// Provide the state root of the latest finalized block, rather than the
// specific state root at the first slot of the finalized epoch (which
// might be a skip slot).
state: finalized_proto_block.state_root,
},
));
Expand Down

0 comments on commit 90730a7

Please sign in to comment.