Skip to content

Commit 1cf4098

Browse files
committed
Hierarchical state diffs in hot DB (#6750)
Squashed commit of the following: commit 629fa73 Author: Michael Sproul <[email protected]> Date: Sat Jun 14 12:58:45 2025 +1000 Tweak hdiff size metric buckets commit 9c8e58c Author: Michael Sproul <[email protected]> Date: Fri Jun 13 17:16:27 2025 +1000 Metric for hdiff sizes commit 707557a Author: Michael Sproul <[email protected]> Date: Wed Jun 11 15:36:18 2025 +1000 Clean up hdiff timing metrics commit 22f7f73 Merge: 9e77f82 8c6abc0 Author: Michael Sproul <[email protected]> Date: Wed Jun 11 14:36:04 2025 +1000 Merge remote-tracking branch 'origin/unstable' into tree-states-hot-rebase commit 9e77f82 Author: Michael Sproul <[email protected]> Date: Mon Jun 2 17:31:17 2025 +1000 Remove FIXMEs/mess commit 4913987 Merge: 80a5353 ae30480 Author: Michael Sproul <[email protected]> Date: Mon Jun 2 17:13:35 2025 +1000 Merge remote-tracking branch 'origin/unstable' into tree-states-hot-rebase commit 80a5353 Author: Michael Sproul <[email protected]> Date: Thu May 29 17:28:49 2025 +1000 Remove some stale FIXMEs/typos commit bb23f2a Author: Michael Sproul <[email protected]> Date: Thu May 29 16:30:35 2025 +1000 Add a new test and fix split loading commit 6094e23 Author: Michael Sproul <[email protected]> Date: Thu May 29 15:50:45 2025 +1000 Clean up test assert commit 06c2632 Author: Michael Sproul <[email protected]> Date: Thu May 29 15:33:46 2025 +1000 Typo fix commit 064115c Author: Michael Sproul <[email protected]> Date: Thu May 29 13:49:25 2025 +1000 Fix DB manager downgrade commit 03fece6 Author: Michael Sproul <[email protected]> Date: Thu May 29 12:35:37 2025 +1000 Skip migrating pre-split states in downgrade commit f0823fe Merge: bc47fd6 0ddf9a9 Author: Michael Sproul <[email protected]> Date: Thu May 29 09:12:39 2025 +1000 Merge remote-tracking branch 'origin/unstable' into tree-states-hot-rebase commit bc47fd6 Author: Michael Sproul <[email protected]> Date: Wed May 28 16:50:24 2025 +1000 Avoid putting pre-split states in the state cache commit 5fb55be Author: Michael Sproul <[email protected]> Date: Wed May 28 15:38:50 2025 +1000 Fix migration of dense diffs commit 9acb1cf Author: Michael Sproul <[email protected]> Date: Wed May 28 13:27:37 2025 +1000 Fix one schema test and add a new one that's broken :sunglasses: commit 78d0496 Author: Michael Sproul <[email protected]> Date: Wed May 28 10:56:45 2025 +1000 Rework store config and compatibility checks commit 8ebe1b2 Author: Michael Sproul <[email protected]> Date: Tue May 27 17:02:49 2025 +1000 Add test for get_ancestor_state_root commit b0191db Author: Michael Sproul <[email protected]> Date: Mon May 26 17:50:34 2025 +1000 Fix split slot migration commit 9800ab8 Author: Michael Sproul <[email protected]> Date: Mon May 26 16:34:05 2025 +1000 Attempt to fix archive node V24 upgrade commit 2485beb Author: Michael Sproul <[email protected]> Date: Thu May 22 17:03:06 2025 +1000 Add logging for downgrade commit d045796 Author: Michael Sproul <[email protected]> Date: Thu May 22 11:10:46 2025 +1000 Align hot grid to freezer when migrating archive nodes commit 444c1cd Author: Michael Sproul <[email protected]> Date: Wed May 21 15:23:11 2025 +1000 Add a test for states retained for hot diffs commit 5d8ddb6 Author: Michael Sproul <[email protected]> Date: Wed May 21 12:22:00 2025 +1000 Delete temporary states on migration commit a4f442c Author: Michael Sproul <[email protected]> Date: Tue May 20 17:47:53 2025 +1000 Clean up some more TODOs commit c39daf2 Author: Michael Sproul <[email protected]> Date: Tue May 20 17:41:31 2025 +1000 Correct V23 -> V24 in load_split comment commit c12dd1c Author: Michael Sproul <[email protected]> Date: Tue May 20 16:05:57 2025 +1000 Split hdiff metrics by hot/cold commit 1096565 Author: Michael Sproul <[email protected]> Date: Mon May 19 17:27:04 2025 +1000 Move legacy state storage code into migration file commit 6887ad7 Author: Michael Sproul <[email protected]> Date: Mon May 19 17:14:00 2025 +1000 Tweak comments in v24 migration commit b73cb1e Author: Michael Sproul <[email protected]> Date: Mon May 19 17:03:24 2025 +1000 Finish PruningCheckpoint thing commit b681648 Merge: f83b083 23ad833 Author: Michael Sproul <[email protected]> Date: Mon May 19 16:28:40 2025 +1000 Merge remote-tracking branch 'origin/unstable' into tree-states-hot-rebase commit f83b083 Author: Michael Sproul <[email protected]> Date: Mon May 19 16:27:03 2025 +1000 WIP remove pruning checkpoint commit 00ef82a Author: Michael Sproul <[email protected]> Date: Mon May 19 12:43:10 2025 +1000 Update comment/remove TODO commit c74913f Merge: 7d8343f 851ee2b Author: Michael Sproul <[email protected]> Date: Thu May 15 11:02:40 2025 +1000 Merge branch 'unstable' into tree-states-hot-rebase commit 7d8343f Author: Michael Sproul <[email protected]> Date: Thu May 8 14:59:10 2025 +1000 Use same hierarchy for hot and cold This is nice as it enables us to avoid recomputing diffs, we can just copy. commit e1475a1 Author: Michael Sproul <[email protected]> Date: Thu May 8 14:43:34 2025 +1000 Prevent split from changing during ancestor calc commit 8fa3665 Author: Michael Sproul <[email protected]> Date: Thu May 1 13:20:44 2025 +1000 Remove non-contiguous DAG checks commit 54ded28 Author: Michael Sproul <[email protected]> Date: Wed Apr 30 09:48:10 2025 +1000 Use 0u8 inside DiffBaseState::Snapshot commit 1184d72 Author: Michael Sproul <[email protected]> Date: Tue Apr 29 19:20:53 2025 +1000 More type-safe diff base state commit 088cfa0 Author: Michael Sproul <[email protected]> Date: Tue Apr 29 18:32:21 2025 +1000 Simplify migration logic commit fcbec47 Merge: 00fbd82 476f3a5 Author: Michael Sproul <[email protected]> Date: Tue Apr 15 11:05:18 2025 +1000 Merge branch 'unstable' into tree-states-hot-rebase commit 00fbd82 Author: hopinheimer <[email protected]> Date: Mon Apr 14 21:04:53 2025 -0400 Delete `transaction_mutex` in store (#7311) * remove from db * remove dependent code * clippy happy * fixing clippy issues commit 990ba80 Merge: f70e543 d96b731 Author: Michael Sproul <[email protected]> Date: Thu Apr 10 14:36:43 2025 +1000 Merge remote-tracking branch 'origin/unstable' into tree-states-hot-rebase commit f70e543 Author: Michael Sproul <[email protected]> Date: Thu Apr 10 13:14:58 2025 +1000 Fix anchor archives commit 8657b08 Author: Michael Sproul <[email protected]> Date: Thu Apr 10 12:46:21 2025 +1000 Add note about multiple DAG roots commit 74ebf8b Author: Michael Sproul <[email protected]> Date: Mon Apr 7 17:04:36 2025 +1000 Fix clippy and tests commit fcc96a1 Merge: 9151436 70850fe Author: Michael Sproul <[email protected]> Date: Mon Apr 7 17:00:29 2025 +1000 Merge remote-tracking branch 'origin/unstable' into tree-states-hot-rebase commit 9151436 Author: Michael Sproul <[email protected]> Date: Thu Apr 3 13:54:31 2025 +1100 Fix test OOM issues on tree-states-hot (#7176) * Try rebasing * Heaptrack * Try to prevent and detect circular references * Don't use StateRootsIterator in get_ancestor_state_root * Skip one slot in get_ancestor_state_root * Heaptrack clippy fix * Fix store test * Log diff base state root * Jump by slots per historical vector * Maybe ok fix for test * get_ancestor_state_root * lint * Implement downgrade from v24 * Better on state write * Log on ws test chain dump * Fix WSS tests * Tweak condition * Revert "Heaptrack" This reverts commit f69c38c. * Reduce diff * Use debug repr * Spelling --------- Co-authored-by: dapplion <[email protected]> commit b49272f Merge: 1c81c93 a322463 Author: Michael Sproul <[email protected]> Date: Tue Mar 18 15:58:59 2025 +1100 Merge remote-tracking branch 'origin/drop-headtracker' into tree-states-hot-rebase commit a322463 Author: Michael Sproul <[email protected]> Date: Tue Mar 18 15:53:20 2025 +1100 Fix compilation commit f4dd6fe Author: dapplion <[email protected]> Date: Mon Mar 17 14:56:15 2025 -0300 Clean up temporary flags on migration commit 1c81c93 Merge: 5b8680a 11cfa1c Author: Michael Sproul <[email protected]> Date: Thu Mar 13 17:00:39 2025 +1100 Merge remote-tracking branch 'origin/drop-headtracker' into tree-states-hot-rebase commit 11cfa1c Author: Michael Sproul <[email protected]> Date: Thu Mar 13 15:47:58 2025 +1100 Purge temporary states more, fixing bug commit 5b8680a Merge: 9f36dc8 b43c071 Author: Michael Sproul <[email protected]> Date: Thu Mar 13 14:51:20 2025 +1100 Merge remote-tracking branch 'origin/drop-headtracker' into tree-states-hot-rebase commit 9f36dc8 Author: dapplion <[email protected]> Date: Fri Mar 7 04:34:01 2025 -0300 Don't include massive lists in errors commit a1b45e6 Author: dapplion <[email protected]> Date: Fri Mar 7 04:33:25 2025 -0300 Persist states even if in cache commit b43c071 Merge: a613662 d60c24e Author: Michael Sproul <[email protected]> Date: Thu Mar 13 11:31:48 2025 +1100 Merge remote-tracking branch 'origin/unstable' into drop-headtracker commit a928d30 Author: Michael Sproul <[email protected]> Date: Tue Mar 11 16:49:37 2025 +1100 Fix merge snafu commit 3f23942 Merge: 4e74ed1 a613662 Author: Michael Sproul <[email protected]> Date: Tue Mar 11 15:56:37 2025 +1100 Merge remote-tracking branch 'origin/drop-headtracker' into tree-states-hot-rebase commit a613662 Merge: ebd05c7 1916a2a Author: Michael Sproul <[email protected]> Date: Tue Mar 11 15:15:04 2025 +1100 Merge remote-tracking branch 'origin/unstable' into drop-headtracker commit ebd05c7 Merge: d58d8ef b4e79ed Author: Michael Sproul <[email protected]> Date: Mon Mar 10 18:08:37 2025 +1100 Merge remote-tracking branch 'origin/unstable' into drop-headtracker commit 4e74ed1 Author: dapplion <[email protected]> Date: Fri Mar 7 02:12:12 2025 -0300 Fix wrapping sub commit ceb59e3 Author: dapplion <[email protected]> Date: Fri Mar 7 01:32:51 2025 -0300 Don't log extra diffs as roots commit f020adb Author: dapplion <[email protected]> Date: Fri Mar 7 01:05:33 2025 -0300 Store latest_block_slot in state summary commit ecb647f Author: dapplion <[email protected]> Date: Fri Mar 7 00:04:41 2025 -0300 Fix column prefix bug commit 36ab17c Author: dapplion <[email protected]> Date: Thu Mar 6 23:35:44 2025 -0300 Better traceability for hdiff errors commit 33615ea Author: dapplion <[email protected]> Date: Thu Mar 6 18:51:47 2025 -0300 Document migration better commit e6fb686 Author: dapplion <[email protected]> Date: Thu Mar 6 01:29:17 2025 -0300 Send it boy commit d58d8ef Author: dapplion <[email protected]> Date: Thu Mar 6 14:52:27 2025 -0300 Update tests commit f8dbda4 Author: dapplion <[email protected]> Date: Wed Mar 5 23:51:41 2025 -0300 Add more details to errors commit 8931141 Author: Michael Sproul <[email protected]> Date: Thu Mar 6 12:16:45 2025 +1100 Abolish temporary states concept commit abb3c3f Author: Michael Sproul <[email protected]> Date: Thu Feb 20 17:14:56 2025 +1100 Prevent deletion of payloads >= split slot commit 5cc266c Author: Michael Sproul <[email protected]> Date: Thu Feb 20 13:27:40 2025 +1100 Clean up DB migrations commit 7abbaeb Author: Michael Sproul <[email protected]> Date: Thu Feb 20 11:49:35 2025 +1100 Use descent from finality instead of viability commit 54010b0 Author: Lion - dapplion <[email protected]> Date: Wed Feb 19 02:49:19 2025 -0300 Update consensus/proto_array/src/proto_array.rs Co-authored-by: Michael Sproul <[email protected]> commit cf3b776 Author: Michael Sproul <[email protected]> Date: Tue Feb 18 14:59:03 2025 +1100 Correct assert in `revert_minority_fork_on_resume` commit 37be9ae Author: Michael Sproul <[email protected]> Date: Fri Feb 14 16:51:42 2025 +1100 Tweaks in `prune_hot_db`. commit f6786eb Author: Michael Sproul <[email protected]> Date: Fri Feb 14 15:46:41 2025 +1100 Tidy and document `migrate_database`. commit 1dc6d5e Merge: 7033656 6ab6eae Author: Michael Sproul <[email protected]> Date: Fri Feb 14 15:16:34 2025 +1100 Merge remote-tracking branch 'origin/unstable' into drop-headtracker commit 7033656 Author: Michael Sproul <[email protected]> Date: Fri Feb 14 15:16:13 2025 +1100 Fix compilation and remove error from `heads` commit b9d8ae7 Author: dapplion <[email protected]> Date: Tue Feb 4 16:15:05 2025 -0300 Fix nodes_without_children commit ed97b97 Author: dapplion <[email protected]> Date: Tue Feb 4 15:51:48 2025 -0300 Use slot clock in heads commit 12fa5a8 Author: Michael Sproul <[email protected]> Date: Tue Feb 4 10:58:06 2025 +1100 Remove some persisted head stuff commit 91eab38 Author: dapplion <[email protected]> Date: Mon Feb 3 20:50:39 2025 -0300 Deprecate block DAG for pruning commit e56299c Author: dapplion <[email protected]> Date: Mon Feb 3 19:50:02 2025 -0300 Annotate SummariesDagError error commit 979e43a Author: Michael Sproul <[email protected]> Date: Tue Feb 4 09:23:58 2025 +1100 Tweak logs commit 663dfd3 Author: dapplion <[email protected]> Date: Mon Feb 3 18:00:37 2025 -0300 Update tests commit 066f96a Author: dapplion <[email protected]> Date: Mon Feb 3 17:46:36 2025 -0300 Prevent very long log line commit c5b4293 Author: dapplion <[email protected]> Date: Mon Feb 3 17:39:22 2025 -0300 Prune descendants of finalized checkpoint not finalized block commit 28d7b74 Author: dapplion <[email protected]> Date: Mon Feb 3 16:38:51 2025 -0300 Add states descendants_of commit 10bbb2e Author: dapplion <[email protected]> Date: Mon Feb 3 16:17:52 2025 -0300 Log about multiple roots in dag tree commit 8c9a1b2 Author: dapplion <[email protected]> Date: Mon Jan 20 18:41:51 2025 +0700 Implement db schema upgrade and downgrade commit 8c15bab Author: dapplion <[email protected]> Date: Fri Jan 10 15:14:35 2025 +0800 Improve state summary dag compute logic commit be105d1 Author: dapplion <[email protected]> Date: Sat Dec 28 21:33:09 2024 +0800 Drop head tracker for summaries dag
1 parent d195fe8 commit 1cf4098

29 files changed

+2384
-759
lines changed

account_manager/src/validator/slashing_protection.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ pub fn cli_run<E: EthSpec>(
9090
let slashing_protection_database =
9191
SlashingDatabase::open_or_create(&slashing_protection_db_path).map_err(|e| {
9292
format!(
93-
"Unable to open database at {}: {:?}",
93+
"Unable to open slashing protection database at {}: {:?}",
9494
slashing_protection_db_path.display(),
9595
e
9696
)
@@ -198,7 +198,7 @@ pub fn cli_run<E: EthSpec>(
198198
let slashing_protection_database = SlashingDatabase::open(&slashing_protection_db_path)
199199
.map_err(|e| {
200200
format!(
201-
"Unable to open database at {}: {:?}",
201+
"Unable to open slashing protection database at {}: {:?}",
202202
slashing_protection_db_path.display(),
203203
e
204204
)

beacon_node/beacon_chain/src/beacon_chain.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ use std::time::Duration;
122122
use store::iter::{BlockRootsIterator, ParentRootBlockIterator, StateRootsIterator};
123123
use store::{
124124
BlobSidecarListFromRoot, DatabaseBlock, Error as DBError, HotColdDB, HotStateSummary,
125-
KeyValueStore, KeyValueStoreOp, StoreItem, StoreOp,
125+
KeyValueStoreOp, StoreItem, StoreOp,
126126
};
127127
use task_executor::{ShutdownReason, TaskExecutor};
128128
use tokio_stream::Stream;
@@ -4012,8 +4012,6 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
40124012
ops.push(StoreOp::PutBlock(block_root, signed_block.clone()));
40134013
ops.push(StoreOp::PutState(block.state_root(), &state));
40144014

4015-
let txn_lock = self.store.hot_db.begin_rw_transaction();
4016-
40174015
if let Err(e) = self.store.do_atomically_with_block_and_blobs_cache(ops) {
40184016
error!(
40194017
msg = "Restoring fork choice from disk",
@@ -4025,7 +4023,6 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
40254023
.err()
40264024
.unwrap_or(e.into()));
40274025
}
4028-
drop(txn_lock);
40294026

40304027
// The fork choice write-lock is dropped *after* the on-disk database has been updated.
40314028
// This prevents inconsistency between the two at the expense of concurrency.
@@ -6739,13 +6736,22 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
67396736
#[allow(clippy::type_complexity)]
67406737
pub fn chain_dump(
67416738
&self,
6739+
) -> Result<Vec<BeaconSnapshot<T::EthSpec, BlindedPayload<T::EthSpec>>>, Error> {
6740+
self.chain_dump_from_slot(Slot::new(0))
6741+
}
6742+
6743+
/// As for `chain_dump` but dumping only the portion of the chain newer than `from_slot`.
6744+
#[allow(clippy::type_complexity)]
6745+
pub fn chain_dump_from_slot(
6746+
&self,
6747+
from_slot: Slot,
67426748
) -> Result<Vec<BeaconSnapshot<T::EthSpec, BlindedPayload<T::EthSpec>>>, Error> {
67436749
let mut dump = vec![];
67446750

67456751
let mut prev_block_root = None;
67466752
let mut prev_beacon_state = None;
67476753

6748-
for res in self.forwards_iter_block_roots(Slot::new(0))? {
6754+
for res in self.forwards_iter_block_roots(from_slot)? {
67496755
let (beacon_block_root, _) = res?;
67506756

67516757
// Do not include snapshots at skipped slots.

beacon_node/beacon_chain/src/block_verification.rs

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ use std::fmt::Debug;
8989
use std::fs;
9090
use std::io::Write;
9191
use std::sync::Arc;
92-
use store::{Error as DBError, HotStateSummary, KeyValueStore, StoreOp};
92+
use store::{Error as DBError, KeyValueStore};
9393
use strum::AsRefStr;
9494
use task_executor::JoinHandle;
9595
use tracing::{debug, error};
@@ -1461,28 +1461,19 @@ impl<T: BeaconChainTypes> ExecutionPendingBlock<T> {
14611461
// processing, but we get early access to it.
14621462
let state_root = state.update_tree_hash_cache()?;
14631463

1464-
// Store the state immediately.
1465-
let txn_lock = chain.store.hot_db.begin_rw_transaction();
1464+
// Store the state immediately. States are ONLY deleted on finalization pruning, so
1465+
// we won't have race conditions where we should have written a state and didn't.
14661466
let state_already_exists =
14671467
chain.store.load_hot_state_summary(&state_root)?.is_some();
14681468

1469-
let state_batch = if state_already_exists {
1469+
if state_already_exists {
14701470
// If the state exists, we do not need to re-write it.
1471-
vec![]
14721471
} else {
1473-
vec![if state.slot() % T::EthSpec::slots_per_epoch() == 0 {
1474-
StoreOp::PutState(state_root, &state)
1475-
} else {
1476-
StoreOp::PutStateSummary(
1477-
state_root,
1478-
HotStateSummary::new(&state_root, &state)?,
1479-
)
1480-
}]
1472+
// Recycle store codepath to create a state summary and store the state / diff
1473+
let mut ops = vec![];
1474+
chain.store.store_hot_state(&state_root, &state, &mut ops)?;
1475+
chain.store.hot_db.do_atomically(ops)?;
14811476
};
1482-
chain
1483-
.store
1484-
.do_atomically_with_block_and_blobs_cache(state_batch)?;
1485-
drop(txn_lock);
14861477

14871478
state_root
14881479
};

beacon_node/beacon_chain/src/builder.rs

Lines changed: 45 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ use store::{Error as StoreError, HotColdDB, ItemStore, KeyValueStoreOp};
4040
use task_executor::{ShutdownReason, TaskExecutor};
4141
use tracing::{debug, error, info};
4242
use types::{
43-
BeaconBlock, BeaconState, BlobSidecarList, ChainSpec, Checkpoint, DataColumnSidecarList, Epoch,
44-
EthSpec, FixedBytesExtended, Hash256, Signature, SignedBeaconBlock, Slot,
43+
BeaconBlock, BeaconState, BlobSidecarList, ChainSpec, DataColumnSidecarList, Epoch, EthSpec,
44+
FixedBytesExtended, Hash256, Signature, SignedBeaconBlock, Slot,
4545
};
4646

4747
/// An empty struct used to "witness" all the `BeaconChainTypes` traits. It has no user-facing
@@ -360,21 +360,29 @@ where
360360
}
361361

362362
/// Starts a new chain from a genesis state.
363-
pub fn genesis_state(mut self, beacon_state: BeaconState<E>) -> Result<Self, String> {
363+
pub fn genesis_state(mut self, mut beacon_state: BeaconState<E>) -> Result<Self, String> {
364364
let store = self.store.clone().ok_or("genesis_state requires a store")?;
365365

366-
let (genesis, updated_builder) = self.set_genesis_state(beacon_state)?;
367-
self = updated_builder;
368-
369-
// Stage the database's metadata fields for atomic storage when `build` is called.
366+
// Initialize anchor info before attempting to write the genesis state.
370367
// Since v4.4.0 we will set the anchor with a dummy state upper limit in order to prevent
371368
// historic states from being retained (unless `--reconstruct-historic-states` is set).
372369
let retain_historic_states = self.chain_config.reconstruct_historic_states;
370+
let genesis_beacon_block = genesis_block(&mut beacon_state, &self.spec)?;
373371
self.pending_io_batch.push(
374372
store
375-
.init_anchor_info(genesis.beacon_block.message(), retain_historic_states)
373+
.init_anchor_info(
374+
genesis_beacon_block.parent_root(),
375+
genesis_beacon_block.slot(),
376+
Slot::new(0),
377+
retain_historic_states,
378+
)
376379
.map_err(|e| format!("Failed to initialize genesis anchor: {:?}", e))?,
377380
);
381+
382+
let (genesis, updated_builder) = self.set_genesis_state(beacon_state)?;
383+
self = updated_builder;
384+
385+
// Stage the database's metadata fields for atomic storage when `build` is called.
378386
self.pending_io_batch.push(
379387
store
380388
.init_blob_info(genesis.beacon_block.slot())
@@ -499,6 +507,13 @@ where
499507
}
500508
}
501509

510+
debug!(
511+
slot = %weak_subj_slot,
512+
state_root = ?weak_subj_state_root,
513+
block_root = ?weak_subj_block_root,
514+
"Storing split from weak subjectivity state"
515+
);
516+
502517
// Set the store's split point *before* storing genesis so that genesis is stored
503518
// immediately in the freezer DB.
504519
store.set_split(weak_subj_slot, weak_subj_state_root, weak_subj_block_root);
@@ -519,6 +534,26 @@ where
519534
.cold_db
520535
.do_atomically(block_root_batch)
521536
.map_err(|e| format!("Error writing frozen block roots: {e:?}"))?;
537+
debug!(
538+
from = %weak_subj_block.slot(),
539+
to_excl = %weak_subj_state.slot(),
540+
block_root = ?weak_subj_block_root,
541+
"Stored frozen block roots at skipped slots"
542+
);
543+
544+
// Write the anchor to memory before calling `put_state` otherwise hot hdiff can't store
545+
// states that do not align with the `start_slot` grid.
546+
let retain_historic_states = self.chain_config.reconstruct_historic_states;
547+
self.pending_io_batch.push(
548+
store
549+
.init_anchor_info(
550+
weak_subj_block.parent_root(),
551+
weak_subj_block.slot(),
552+
weak_subj_slot,
553+
retain_historic_states,
554+
)
555+
.map_err(|e| format!("Failed to initialize anchor info: {:?}", e))?,
556+
);
522557

523558
// Write the state, block and blobs non-atomically, it doesn't matter if they're forgotten
524559
// about on a crash restart.
@@ -529,6 +564,8 @@ where
529564
weak_subj_state.clone(),
530565
)
531566
.map_err(|e| format!("Failed to set checkpoint state as finalized state: {:?}", e))?;
567+
// Note: post hot hdiff must update the anchor info before attempting to put_state otherwise
568+
// the write will fail if the weak_subj_slot is not aligned with the snapshot moduli.
532569
store
533570
.put_state(&weak_subj_state_root, &weak_subj_state)
534571
.map_err(|e| format!("Failed to store weak subjectivity state: {e:?}"))?;
@@ -558,13 +595,7 @@ where
558595
// Stage the database's metadata fields for atomic storage when `build` is called.
559596
// This prevents the database from restarting in an inconsistent state if the anchor
560597
// info or split point is written before the `PersistedBeaconChain`.
561-
let retain_historic_states = self.chain_config.reconstruct_historic_states;
562598
self.pending_io_batch.push(store.store_split_in_batch());
563-
self.pending_io_batch.push(
564-
store
565-
.init_anchor_info(weak_subj_block.message(), retain_historic_states)
566-
.map_err(|e| format!("Failed to initialize anchor info: {:?}", e))?,
567-
);
568599
self.pending_io_batch.push(
569600
store
570601
.init_blob_info(weak_subj_block.slot())
@@ -576,13 +607,6 @@ where
576607
.map_err(|e| format!("Failed to initialize data column info: {:?}", e))?,
577608
);
578609

579-
// Store pruning checkpoint to prevent attempting to prune before the anchor state.
580-
self.pending_io_batch
581-
.push(store.pruning_checkpoint_store_op(Checkpoint {
582-
root: weak_subj_block_root,
583-
epoch: weak_subj_state.slot().epoch(E::slots_per_epoch()),
584-
}));
585-
586610
let snapshot = BeaconSnapshot {
587611
beacon_block_root: weak_subj_block_root,
588612
beacon_block: Arc::new(weak_subj_block),

beacon_node/beacon_chain/src/historical_blocks.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
151151

152152
// Store block roots, including at all skip slots in the freezer DB.
153153
for slot in (block.slot().as_u64()..prev_block_slot.as_u64()).rev() {
154+
debug!(%slot, ?block_root, "Storing frozen block to root mapping");
154155
cold_batch.push(KeyValueStoreOp::PutKeyValue(
155156
DBColumn::BeaconBlockRoots,
156157
slot.to_be_bytes().to_vec(),

0 commit comments

Comments
 (0)