@@ -25,7 +25,9 @@ use crate::service::finalized_state::ZebraDb;
25
25
pub ( crate ) mod add_subtrees;
26
26
pub ( crate ) mod cache_genesis_roots;
27
27
pub ( crate ) mod fix_tree_key_type;
28
+ pub ( crate ) mod no_migration;
28
29
pub ( crate ) mod prune_trees;
30
+ pub ( crate ) mod tree_keys_and_caches_upgrade;
29
31
30
32
#[ cfg( not( feature = "indexer" ) ) ]
31
33
pub ( crate ) mod drop_tx_locs_by_spends;
@@ -72,15 +74,21 @@ pub trait DiskFormatUpgrade {
72
74
) -> Result < ( ) , CancelFormatChange > {
73
75
Ok ( ( ) )
74
76
}
77
+
78
+ /// Returns true if the [`DiskFormatUpgrade`] needs to run a migration on existing data in the db.
79
+ fn needs_migration ( & self ) -> bool {
80
+ true
81
+ }
75
82
}
76
83
77
84
fn format_upgrades ( ) -> Vec < Box < dyn DiskFormatUpgrade > > {
85
+ // Note: Disk format upgrades must be run in order.
78
86
vec ! [
79
87
Box :: new( prune_trees:: PruneTrees ) ,
80
88
Box :: new( add_subtrees:: AddSubtrees ) ,
81
- // TODO:
82
- // Box::new(cache_genesis_roots::CacheGenesisRoots),
83
- // Box::new(fix_tree_key_type::FixTreeKeyType ),
89
+ Box :: new ( tree_keys_and_caches_upgrade :: FixTreeKeyTypeAndCacheGenesisRoots ) ,
90
+ // Value balance upgrade
91
+ Box :: new( no_migration :: NoMigration :: new ( 26 , 0 , 0 ) ) ,
84
92
]
85
93
}
86
94
@@ -532,6 +540,11 @@ impl DbFormatChange {
532
540
continue ;
533
541
}
534
542
543
+ if !upgrade. needs_migration ( ) {
544
+ Self :: mark_as_upgraded_to ( db, & upgrade. version ( ) ) ;
545
+ continue ;
546
+ }
547
+
535
548
let timer = CodeTimer :: start ( ) ;
536
549
537
550
upgrade. prepare ( initial_tip_height, db, cancel_receiver, older_disk_version) ?;
@@ -553,32 +566,6 @@ impl DbFormatChange {
553
566
timer. finish ( module_path ! ( ) , line ! ( ) , upgrade. description ( ) ) ;
554
567
}
555
568
556
- // Sprout & history tree key formats, and cached genesis tree roots database upgrades.
557
-
558
- let version_for_tree_keys_and_caches =
559
- Version :: parse ( "25.3.0" ) . expect ( "Hardcoded version string should be valid." ) ;
560
-
561
- // Check if we need to do the upgrade.
562
- if older_disk_version < & version_for_tree_keys_and_caches {
563
- let timer = CodeTimer :: start ( ) ;
564
-
565
- // It shouldn't matter what order these are run in.
566
- cache_genesis_roots:: run ( initial_tip_height, db, cancel_receiver) ?;
567
- fix_tree_key_type:: run ( initial_tip_height, db, cancel_receiver) ?;
568
-
569
- // Before marking the state as upgraded, check that the upgrade completed successfully.
570
- cache_genesis_roots:: detailed_check ( db, cancel_receiver) ?
571
- . expect ( "database format is valid after upgrade" ) ;
572
- fix_tree_key_type:: detailed_check ( db, cancel_receiver) ?
573
- . expect ( "database format is valid after upgrade" ) ;
574
-
575
- // Mark the database as upgraded. Zebra won't repeat the upgrade anymore once the
576
- // database is marked, so the upgrade MUST be complete at this point.
577
- Self :: mark_as_upgraded_to ( db, & version_for_tree_keys_and_caches) ;
578
-
579
- timer. finish ( module_path ! ( ) , line ! ( ) , "tree keys and caches upgrade" ) ;
580
- }
581
-
582
569
let version_for_upgrading_value_balance_format =
583
570
Version :: parse ( "26.0.0" ) . expect ( "hard-coded version string should be valid" ) ;
584
571
@@ -587,14 +574,6 @@ impl DbFormatChange {
587
574
Self :: mark_as_upgraded_to ( db, & version_for_upgrading_value_balance_format)
588
575
}
589
576
590
- // # New Upgrades Usually Go Here
591
- //
592
- // New code goes above this comment!
593
- //
594
- // Run the latest format upgrade code after the other upgrades are complete,
595
- // then mark the format as upgraded. The code should check `cancel_receiver`
596
- // every time it runs its inner update loop.
597
-
598
577
info ! (
599
578
%newer_running_version,
600
579
"Zebra automatically upgraded the database format to:"
@@ -650,9 +629,6 @@ impl DbFormatChange {
650
629
results. push ( upgrade. validate ( db, cancel_receiver) ?) ;
651
630
}
652
631
653
- results. push ( cache_genesis_roots:: detailed_check ( db, cancel_receiver) ?) ;
654
- results. push ( fix_tree_key_type:: detailed_check ( db, cancel_receiver) ?) ;
655
-
656
632
// The work is done in the functions we just called.
657
633
timer. finish ( module_path ! ( ) , line ! ( ) , "format_validity_checks_detailed()" ) ;
658
634
0 commit comments