mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-22 14:24:44 +00:00
Fix and test checkpoint sync from genesis (#7689)
Fix a bug involving checkpoint sync from genesis reported by Sunnyside labs. Ensure that the store's `anchor` is initialised prior to storing the genesis state. In the case of checkpoint sync from genesis, the genesis state will be in the _hot DB_, so we need the hot DB metadata to be initialised in order to store it. I've extended the existing checkpoint sync tests to cover this case as well. There are some subtleties around what the `state_upper_limit` should be set to in this case. I've opted to just enable state reconstruction from the start in the test so it gets set to 0, which results in an end state more consistent with the other test cases (full state reconstruction). This is required because we can't meaningfully do any state reconstruction when the split slot is 0 (there is no range of frozen slots to reconstruct).
This commit is contained in:
@@ -514,9 +514,26 @@ where
|
||||
"Storing split from weak subjectivity state"
|
||||
);
|
||||
|
||||
// Set the store's split point *before* storing genesis so that genesis is stored
|
||||
// immediately in the freezer DB.
|
||||
// Set the store's split point *before* storing genesis so that if the genesis state
|
||||
// is prior to the split slot, it will immediately be stored in the freezer DB.
|
||||
store.set_split(weak_subj_slot, weak_subj_state_root, weak_subj_block_root);
|
||||
|
||||
// It is also possible for the checkpoint state to be equal to the genesis state, in which
|
||||
// case it will be stored in the hot DB. In this case, we need to ensure the store's anchor
|
||||
// is initialised prior to storing the state, as the anchor is required for working out
|
||||
// hdiff storage strategies.
|
||||
let retain_historic_states = self.chain_config.reconstruct_historic_states;
|
||||
self.pending_io_batch.push(
|
||||
store
|
||||
.init_anchor_info(
|
||||
weak_subj_block.parent_root(),
|
||||
weak_subj_block.slot(),
|
||||
weak_subj_slot,
|
||||
retain_historic_states,
|
||||
)
|
||||
.map_err(|e| format!("Failed to initialize anchor info: {:?}", e))?,
|
||||
);
|
||||
|
||||
let (_, updated_builder) = self.set_genesis_state(genesis_state)?;
|
||||
self = updated_builder;
|
||||
|
||||
@@ -541,20 +558,6 @@ where
|
||||
"Stored frozen block roots at skipped slots"
|
||||
);
|
||||
|
||||
// Write the anchor to memory before calling `put_state` otherwise hot hdiff can't store
|
||||
// states that do not align with the `start_slot` grid.
|
||||
let retain_historic_states = self.chain_config.reconstruct_historic_states;
|
||||
self.pending_io_batch.push(
|
||||
store
|
||||
.init_anchor_info(
|
||||
weak_subj_block.parent_root(),
|
||||
weak_subj_block.slot(),
|
||||
weak_subj_slot,
|
||||
retain_historic_states,
|
||||
)
|
||||
.map_err(|e| format!("Failed to initialize anchor info: {:?}", e))?,
|
||||
);
|
||||
|
||||
// Write the state, block and blobs non-atomically, it doesn't matter if they're forgotten
|
||||
// about on a crash restart.
|
||||
store
|
||||
|
||||
Reference in New Issue
Block a user