Skip to content

Commit 33615ea

Browse files
committed
Document migration better
1 parent e6fb686 commit 33615ea

File tree

2 files changed

+191
-121
lines changed

2 files changed

+191
-121
lines changed

beacon_node/beacon_chain/src/migrate.rs

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,9 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> BackgroundMigrator<E, Ho
533533
if state_summaries_dag_roots.len() > 1 {
534534
warn!(
535535
log,
536-
"Prune state summaries dag found more than one root";
536+
"State summaries DAG found more than one root";
537+
"location" => "pruning",
538+
"new_finalized_state_root" => ?new_finalized_state_root,
537539
"state_summaries_dag_roots" => ?state_summaries_dag_roots
538540
);
539541
}
@@ -586,11 +588,6 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> BackgroundMigrator<E, Ho
586588
let newly_finalized_blocks = state_summaries_dag
587589
.blocks_of_states(newly_finalized_state_roots.iter())
588590
.map_err(|e| PruningError::SummariesDagError("blocks of newly finalized", e))?;
589-
let newly_finalized_blocks_min_slot = *newly_finalized_blocks
590-
.iter()
591-
.map(|(_, slot)| slot)
592-
.min()
593-
.ok_or(PruningError::EmptyFinalizedBlocks)?;
594591

595592
// Compute the set of finalized state roots that we must keep to make the dynamic HDiff system
596593
// work.
@@ -615,15 +612,15 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> BackgroundMigrator<E, Ho
615612
// \---[3]--|-----------------[4]
616613
// |
617614

618-
for (slot, summaries) in state_summaries_dag.summaries_by_slot_ascending() {
619-
for (state_root, _) in summaries {
615+
for (_, summaries) in state_summaries_dag.summaries_by_slot_ascending() {
616+
for (state_root, summary) in summaries {
620617
let should_prune = if finalized_and_descendant_state_roots_of_finalized_checkpoint
621618
.contains(&state_root)
622619
{
623620
// This state is a viable descendant of the finalized checkpoint, so does not
624621
// conflict with finality and can be built on or become a head
625622
false
626-
} else if required_finalized_diff_state_slots.contains(&slot) {
623+
} else if required_finalized_diff_state_slots.contains(&summary.slot) {
627624
// Keep this state and diff as it's necessary for the finalized portion of the
628625
// HDiff links. `required_finalized_diff_state_slots` tracks the set of slots on
629626
// each diff layer, and by checking `newly_finalized_state_roots` which only
@@ -638,11 +635,11 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> BackgroundMigrator<E, Ho
638635
//
639636
// /-----o----
640637
// o-------o------/-------o----
641-
if slot < newly_finalized_states_min_slot
638+
if summary.slot < newly_finalized_states_min_slot
642639
|| newly_finalized_state_roots.contains(&state_root)
643640
{
644641
// Track kept summaries to debug hdiff inconsistencies with "Extra pruning information"
645-
kept_summaries_for_hdiff.push((state_root, slot));
642+
kept_summaries_for_hdiff.push((state_root, summary.slot));
646643
false
647644
} else {
648645
true
@@ -655,12 +652,12 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> BackgroundMigrator<E, Ho
655652
if should_prune {
656653
// States are migrated into the cold DB in the migrate step. All hot states
657654
// prior to finalized can be pruned from the hot DB columns
658-
states_to_prune.insert((slot, state_root));
655+
states_to_prune.insert((summary.slot, state_root));
659656
}
660657
}
661658
}
662659

663-
for (block_root, slot) in state_summaries_dag.iter_blocks() {
660+
for (block_root, block_slot) in state_summaries_dag.iter_blocks() {
664661
// Blocks both finalized and unfinalized are in the same DB column. We must only
665662
// prune blocks from abandoned forks. Note that block pruning and state pruning differ.
666663
// The blocks DB column is shared for hot and cold data, while the states have different
@@ -672,10 +669,12 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> BackgroundMigrator<E, Ho
672669
// itself Note that we anchor this set on the finalized checkpoint instead of the
673670
// finalized block. A diagram above shows a relevant example.
674671
false
675-
} else if newly_finalized_blocks.contains(&(block_root, slot)) {
672+
} else if newly_finalized_blocks.contains(&(block_root, block_slot)) {
676673
// Keep recently finalized blocks
677674
false
678-
} else if slot < newly_finalized_blocks_min_slot {
675+
} else if block_slot < newly_finalized_states_min_slot {
676+
// Note: newly_finalized_states_min_slot == newly_finalized_blocks_min_slot
677+
//
679678
// Keep recently finalized blocks that we know are canonical. Blocks with slots <
680679
// that `newly_finalized_blocks_min_slot` we don't have canonical information so we
681680
// assume they are part of the finalized pruned chain
@@ -702,26 +701,37 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> BackgroundMigrator<E, Ho
702701
log,
703702
"Extra pruning information";
704703
"new_finalized_checkpoint" => ?new_finalized_checkpoint,
704+
"new_finalized_state_root" => ?new_finalized_state_root,
705705
"newly_finalized_blocks" => newly_finalized_blocks.len(),
706706
"newly_finalized_state_roots" => newly_finalized_state_roots.len(),
707-
"newly_finalized_blocks_min_slot" => newly_finalized_blocks_min_slot,
708707
"newly_finalized_states_min_slot" => newly_finalized_states_min_slot,
709708
"required_finalized_diff_state_slots" => ?required_finalized_diff_state_slots,
710709
"kept_summaries_for_hdiff" => ?kept_summaries_for_hdiff,
711710
"state_summaries_count" => state_summaries_dag.summaries_count(),
712711
"state_summaries_dag_roots" => ?state_summaries_dag_roots,
713712
"finalized_and_descendant_state_roots_of_finalized_checkpoint" => finalized_and_descendant_state_roots_of_finalized_checkpoint.len(),
714-
"finalized_and_descendant_state_roots_of_finalized_checkpoint" => finalized_and_descendant_state_roots_of_finalized_checkpoint.len(),
715713
"blocks_to_prune" => blocks_to_prune.len(),
716714
"states_to_prune" => states_to_prune.len(),
717715
);
718716
// Don't log the full `states_to_prune` in the log statement above as it can result in a
719-
// single log line of +1Kb and break logging setups.
717+
// single log line of +1Kb and break logging setups. Log `new_finalized_state_root` as a
718+
// prunning ID to trace these individual logs to the above "Extra pruning information"
720719
for block_root in &blocks_to_prune {
721-
debug!(log, "Pruning block"; "block_root" => ?block_root);
720+
debug!(
721+
log,
722+
"Pruning block";
723+
"new_finalized_state_root" => ?new_finalized_state_root,
724+
"block_root" => ?block_root
725+
);
722726
}
723727
for (slot, state_root) in &states_to_prune {
724-
debug!(log, "Pruning hot state"; "state_root" => ?state_root, "slot" => slot);
728+
debug!(
729+
log,
730+
"Pruning hot state";
731+
"new_finalized_state_root" => ?new_finalized_state_root,
732+
"state_root" => ?state_root,
733+
"slot" => slot
734+
);
725735
}
726736

727737
let mut batch: Vec<StoreOp<E>> = blocks_to_prune
@@ -750,7 +760,11 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> BackgroundMigrator<E, Ho
750760

751761
store.do_atomically_with_block_and_blobs_cache(batch)?;
752762

753-
debug!(log, "Database pruning complete");
763+
debug!(
764+
log,
765+
"Database pruning complete";
766+
"new_finalized_state_root" => ?new_finalized_state_root,
767+
);
754768

755769
Ok(PruningOutcome::Successful {
756770
// TODO(hdiff): approximation of the previous finalized checkpoint. Only used in the

0 commit comments

Comments
 (0)