@@ -8,7 +8,7 @@ use std::sync::{mpsc, Arc};
88use std:: thread;
99use std:: time:: { Duration , SystemTime , UNIX_EPOCH } ;
1010use store:: hot_cold_store:: { migrate_database, HotColdDBError } ;
11- use store:: { Error , ItemStore , StoreOp } ;
11+ use store:: { Error , ItemStore , Split , StoreOp } ;
1212pub use store:: { HotColdDB , MemoryStore } ;
1313use types:: { BeaconState , BeaconStateHash , Checkpoint , Epoch , EthSpec , Hash256 , Slot } ;
1414
@@ -319,19 +319,24 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> BackgroundMigrator<E, Ho
319319 }
320320 } ;
321321
322- match migrate_database (
322+ let split_prior_to_migration = match migrate_database (
323323 db. clone ( ) ,
324324 finalized_state_root. into ( ) ,
325325 finalized_block_root,
326326 & finalized_state,
327327 ) {
328- Ok ( ( ) ) => { }
328+ Ok ( split_change) => {
329+ // Migration run, return the split before the migration
330+ split_change. previous
331+ }
329332 Err ( Error :: HotColdDBError ( HotColdDBError :: FreezeSlotUnaligned ( slot) ) ) => {
330333 debug ! (
331334 log,
332335 "Database migration postponed, unaligned finalized block" ;
333336 "slot" => slot. as_u64( )
334337 ) ;
338+ // Migration did not run, return the current split info
339+ db. get_split_info ( )
335340 }
336341 Err ( e) => {
337342 warn ! (
@@ -348,6 +353,7 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> BackgroundMigrator<E, Ho
348353 finalized_state_root. into ( ) ,
349354 & finalized_state,
350355 notif. finalized_checkpoint ,
356+ split_prior_to_migration,
351357 log,
352358 ) {
353359 Ok ( PruningOutcome :: Successful {
@@ -457,6 +463,7 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> BackgroundMigrator<E, Ho
457463 new_finalized_state_root : Hash256 ,
458464 new_finalized_state : & BeaconState < E > ,
459465 new_finalized_checkpoint : Checkpoint ,
466+ split_prior_to_migration : Split ,
460467 log : & Logger ,
461468 ) -> Result < PruningOutcome , BeaconChainError > {
462469 let new_finalized_slot = new_finalized_checkpoint
@@ -483,6 +490,7 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> BackgroundMigrator<E, Ho
483490 "Starting database pruning" ;
484491 "new_finalized_checkpoint" => ?new_finalized_checkpoint,
485492 "new_finalized_state_root" => ?new_finalized_state_root,
493+ "split_prior_to_migration" => ?split_prior_to_migration,
486494 ) ;
487495
488496 let state_summaries_dag = {
@@ -521,13 +529,21 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> BackgroundMigrator<E, Ho
521529 // To debug faulty trees log if we unexpectedly have more than one root. These trees may not
522530 // result in an error, as they may not be queried in the codepaths below.
523531 let state_summaries_dag_roots = state_summaries_dag. tree_roots ( ) ;
524- if state_summaries_dag_roots. len ( ) > 1 {
532+ let state_summaries_dag_roots_post_split = state_summaries_dag_roots
533+ . iter ( )
534+ . filter ( |( _, s) | s. slot >= split_prior_to_migration. slot )
535+ . collect :: < Vec < _ > > ( ) ;
536+ // Because of the additional HDiffs kept for the grid prior to finalization the tree_roots
537+ // function will consider them roots. Those are expected. We just want to assert that the
538+ // relevant tree of states (post-split) is well-formed.
539+ if state_summaries_dag_roots_post_split. len ( ) > 1 {
525540 warn ! (
526541 log,
527542 "State summaries DAG found more than one root" ;
528543 "location" => "pruning" ,
529544 "new_finalized_state_root" => ?new_finalized_state_root,
530- "state_summaries_dag_roots" => ?state_summaries_dag_roots
545+ "split_prior_to_migration_slot" => split_prior_to_migration. slot,
546+ "state_summaries_dag_roots_post_split" => ?state_summaries_dag_roots_post_split
531547 ) ;
532548 }
533549
@@ -693,6 +709,7 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> BackgroundMigrator<E, Ho
693709 "Extra pruning information" ;
694710 "new_finalized_checkpoint" => ?new_finalized_checkpoint,
695711 "new_finalized_state_root" => ?new_finalized_state_root,
712+ "split_prior_to_migration" => ?split_prior_to_migration,
696713 "newly_finalized_blocks" => newly_finalized_blocks. len( ) ,
697714 "newly_finalized_state_roots" => newly_finalized_state_roots. len( ) ,
698715 "newly_finalized_states_min_slot" => newly_finalized_states_min_slot,
0 commit comments