@@ -454,7 +454,7 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> BackgroundMigrator<E, Ho
454
454
/// space.
455
455
fn prune_hot_db (
456
456
store : Arc < HotColdDB < E , Hot , Cold > > ,
457
- new_finalized_state_hash : Hash256 ,
457
+ new_finalized_state_root : Hash256 ,
458
458
new_finalized_state : & BeaconState < E > ,
459
459
new_finalized_checkpoint : Checkpoint ,
460
460
log : & Logger ,
@@ -482,7 +482,7 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> BackgroundMigrator<E, Ho
482
482
log,
483
483
"Starting database pruning" ;
484
484
"new_finalized_checkpoint" => ?new_finalized_checkpoint,
485
- "new_finalized_state_hash " => ?new_finalized_state_hash ,
485
+ "new_finalized_state_root " => ?new_finalized_state_root ,
486
486
) ;
487
487
488
488
let state_summaries_dag = {
@@ -527,8 +527,8 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> BackgroundMigrator<E, Ho
527
527
. map_err ( |e| PruningError :: SummariesDagError ( "creating StateSumariesDAG" , e) ) ?
528
528
} ;
529
529
530
- // To debug faulty trees log unexpected that have more than one root. These trees may not
531
- // result in an error, as may not be queried in the codepaths below.
530
+ // To debug faulty trees log if we unexpectedly have more than one root. These trees may not
531
+ // result in an error, as they may not be queried in the codepaths below.
532
532
let state_summaries_dag_roots = state_summaries_dag. tree_roots ( ) ;
533
533
if state_summaries_dag_roots. len ( ) > 1 {
534
534
warn ! (
@@ -538,14 +538,14 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> BackgroundMigrator<E, Ho
538
538
) ;
539
539
}
540
540
541
- // `new_finalized_state_hash ` is the *state at the slot of the finalized epoch*,
541
+ // `new_finalized_state_root ` is the *state at the slot of the finalized epoch*,
542
542
// rather than the state of the latest finalized block. These two values will only
543
543
// differ when the first slot of the finalized epoch is a skip slot.
544
544
let finalized_and_descendant_state_roots_of_finalized_checkpoint =
545
545
HashSet :: < Hash256 > :: from_iter (
546
- std:: iter:: once ( new_finalized_state_hash ) . chain (
546
+ std:: iter:: once ( new_finalized_state_root ) . chain (
547
547
state_summaries_dag
548
- . descendants_of ( & new_finalized_state_hash )
548
+ . descendants_of ( & new_finalized_state_root )
549
549
. map_err ( |e| {
550
550
PruningError :: SummariesDagError ( "state summaries descendants_of" , e)
551
551
} ) ?,
@@ -554,7 +554,8 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> BackgroundMigrator<E, Ho
554
554
555
555
// Collect all `latest_block_roots` of the
556
556
// finalized_and_descendant_state_roots_of_finalized_checkpoint set. Includes the finalized
557
- // block as `new_finalized_state_hash` always has a latest block root the finalized block.
557
+ // block as `new_finalized_state_root` always has a latest block root equal to the finalized
558
+ // block.
558
559
let finalized_and_descendant_block_roots_of_finalized_checkpoint =
559
560
HashSet :: < Hash256 > :: from_iter (
560
561
state_summaries_dag
@@ -573,7 +574,7 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> BackgroundMigrator<E, Ho
573
574
574
575
// Note: ancestors_of includes the finalized state root
575
576
let newly_finalized_state_summaries = state_summaries_dag
576
- . ancestors_of ( new_finalized_state_hash )
577
+ . ancestors_of ( new_finalized_state_root )
577
578
. map_err ( |e| PruningError :: SummariesDagError ( "state summaries ancestors_of" , e) ) ?;
578
579
let newly_finalized_state_roots = newly_finalized_state_summaries
579
580
. iter ( )
@@ -629,30 +630,29 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> BackgroundMigrator<E, Ho
629
630
}
630
631
}
631
632
632
- for block in state_summaries_dag. iter_blocks ( ) {
633
- let ( block_root, slot) = block;
634
-
633
+ for ( block_root, slot) in state_summaries_dag. iter_blocks ( ) {
635
634
// Blocks both finalized and unfinalized are in the same DB column. We must only
636
635
// prune blocks from abandoned forks. Note that block pruning and state pruning differ.
637
636
// The blocks DB column is shared for hot and cold data, while the states have different
638
637
// columns. Thus, we only prune unviable blocks or from abandoned forks.
639
638
let should_prune = if finalized_and_descendant_block_roots_of_finalized_checkpoint
640
639
. contains ( & block_root)
641
640
{
642
- // Keep unfinalized blocks descendant of finalized checkpoint + finalized block itself
643
- // Note that we anchor this set on the finalied checkpoint instead of the finalized
644
- // block. A diagram above shows a relevant example.
641
+ // Keep unfinalized blocks descendant of finalized checkpoint + finalized block
642
+ // itself Note that we anchor this set on the finalized checkpoint instead of the
643
+ // finalized block. A diagram above shows a relevant example.
645
644
false
646
- } else if newly_finalized_blocks. contains ( & block ) {
645
+ } else if newly_finalized_blocks. contains ( & ( block_root , slot ) ) {
647
646
// Keep recently finalized blocks
648
647
false
649
648
} else if slot < newly_finalized_states_min_slot {
650
649
// Keep recently finalized blocks that we know are canonical. Blocks with slots <
651
650
// that `newly_finalized_blocks_min_slot` we don't have canonical information so we
652
651
// assume they are part of the finalized pruned chain
653
652
//
654
- // Pruning those risks breaking the DB by deleting canonical blocks once the HDiff
655
- // grid advances. If the pruning routine is correct this condition should never hit.
653
+ // Pruning these would risk breaking the DB by deleting canonical blocks once the
654
+ // HDiff grid advances. If the pruning routine is correct this condition should
655
+ // never be hit.
656
656
false
657
657
} else {
658
658
// Everything else, prune
@@ -685,10 +685,10 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> BackgroundMigrator<E, Ho
685
685
// Don't log the full `states_to_prune` in the log statement above as it can result in a
686
686
// single log line of +1Kb and break logging setups.
687
687
for block_root in & blocks_to_prune {
688
- debug ! ( log, "block to prune " ; "block_root" => ?block_root) ;
688
+ debug ! ( log, "Pruning block " ; "block_root" => ?block_root) ;
689
689
}
690
690
for ( slot, state_root) in & states_to_prune {
691
- debug ! ( log, "state to prune " ; "state_root" => ?state_root, "slot" => slot) ;
691
+ debug ! ( log, "Pruning state " ; "state_root" => ?state_root, "slot" => slot) ;
692
692
}
693
693
694
694
let mut batch: Vec < StoreOp < E > > = blocks_to_prune
@@ -709,6 +709,7 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> BackgroundMigrator<E, Ho
709
709
710
710
// Prune sync committee branches of non-checkpoint canonical finalized blocks
711
711
Self :: prune_non_checkpoint_sync_committee_branches ( & newly_finalized_blocks, & mut batch) ;
712
+
712
713
// Prune all payloads of the canonical finalized blocks
713
714
if store. get_config ( ) . prune_payloads {
714
715
Self :: prune_finalized_payloads ( & newly_finalized_blocks, & mut batch) ;
0 commit comments