@@ -135,11 +135,11 @@ pub struct ManualFinalizationNotification {
135135}
136136
137137pub struct FinalizationNotification {
138- finalized_state_root : BeaconStateHash ,
139- finalized_checkpoint : Checkpoint ,
140- head_tracker : Arc < HeadTracker > ,
141- prev_migration : Arc < Mutex < PrevMigration > > ,
142- genesis_block_root : Hash256 ,
138+ pub finalized_state_root : BeaconStateHash ,
139+ pub finalized_checkpoint : Checkpoint ,
140+ pub head_tracker : Arc < HeadTracker > ,
141+ pub prev_migration : Arc < Mutex < PrevMigration > > ,
142+ pub genesis_block_root : Hash256 ,
143143}
144144
145145impl < E : EthSpec , Hot : ItemStore < E > , Cold : ItemStore < E > > BackgroundMigrator < E , Hot , Cold > {
@@ -306,96 +306,19 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> BackgroundMigrator<E, Ho
306306 notif : ManualFinalizationNotification ,
307307 log : & Logger ,
308308 ) {
309- let state_root = notif. state_root ;
310- let block_root = notif. checkpoint . root ;
311-
312- let manually_finalized_state = match db. get_state ( & state_root. into ( ) , None ) {
313- Ok ( Some ( state) ) => state,
314- other => {
315- error ! (
316- log,
317- "Manual migrator failed to load state" ;
318- "state_root" => ?state_root,
319- "error" => ?other
320- ) ;
321- return ;
322- }
309+ // We create a "dummy" prev migration
310+ let prev_migration = PrevMigration {
311+ epoch : Epoch :: new ( 1 ) ,
312+ epochs_per_migration : 2 ,
323313 } ;
324-
325- let old_finalized_checkpoint = match Self :: prune_abandoned_forks (
326- db. clone ( ) ,
327- notif. head_tracker ,
328- state_root,
329- & manually_finalized_state,
330- notif. checkpoint ,
331- notif. genesis_block_root ,
332- log,
333- ) {
334- Ok ( PruningOutcome :: Successful {
335- old_finalized_checkpoint,
336- } ) => old_finalized_checkpoint,
337- Ok ( PruningOutcome :: DeferredConcurrentHeadTrackerMutation ) => {
338- warn ! (
339- log,
340- "Pruning deferred because of a concurrent mutation" ;
341- "message" => "this is expected only very rarely!"
342- ) ;
343- return ;
344- }
345- Ok ( PruningOutcome :: OutOfOrderFinalization {
346- old_finalized_checkpoint,
347- new_finalized_checkpoint,
348- } ) => {
349- warn ! (
350- log,
351- "Ignoring out of order finalization request" ;
352- "old_finalized_epoch" => old_finalized_checkpoint. epoch,
353- "new_finalized_epoch" => new_finalized_checkpoint. epoch,
354- "message" => "this is expected occasionally due to a (harmless) race condition"
355- ) ;
356- return ;
357- }
358- Err ( e) => {
359- warn ! ( log, "Block pruning failed" ; "error" => ?e) ;
360- return ;
361- }
362- } ;
363-
364- match migrate_database (
365- db. clone ( ) ,
366- state_root. into ( ) ,
367- block_root,
368- & manually_finalized_state,
369- ) {
370- Ok ( ( ) ) => { }
371- Err ( Error :: HotColdDBError ( HotColdDBError :: FreezeSlotUnaligned ( slot) ) ) => {
372- debug ! (
373- log,
374- "Database migration postponed, unaligned finalized block" ;
375- "slot" => slot. as_u64( )
376- ) ;
377- }
378- Err ( e) => {
379- warn ! (
380- log,
381- "Database migration failed" ;
382- "error" => format!( "{:?}" , e)
383- ) ;
384- return ;
385- }
314+ let notif = FinalizationNotification {
315+ finalized_state_root : notif. state_root ,
316+ finalized_checkpoint : notif. checkpoint ,
317+ head_tracker : notif. head_tracker ,
318+ prev_migration : Arc :: new ( prev_migration. into ( ) ) ,
319+ genesis_block_root : notif. genesis_block_root ,
386320 } ;
387-
388- // Finally, compact the database so that new free space is properly reclaimed.
389- if let Err ( e) = Self :: run_compaction (
390- db,
391- old_finalized_checkpoint. epoch ,
392- notif. checkpoint . epoch ,
393- log,
394- ) {
395- warn ! ( log, "Database compaction failed" ; "error" => format!( "{:?}" , e) ) ;
396- }
397-
398- debug ! ( log, "Database consolidation complete" ) ;
321+ Self :: run_migration ( db, notif, log) ;
399322 }
400323
401324 /// Perform the actual work of `process_finalization`.
0 commit comments