-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactors fix tree keys, cache genesis roots, and value balance upgra…
…des to use new trait
- Loading branch information
Showing
3 changed files
with
121 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
zebra-state/src/service/finalized_state/disk_format/upgrade/no_migration.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
//! An implementation of [`DiskFormatUpgrade`] for marking the database as upgraded to a new format version. | ||
use crossbeam_channel::Receiver; | ||
|
||
use semver::Version; | ||
use zebra_chain::block::Height; | ||
|
||
use crate::service::finalized_state::ZebraDb; | ||
|
||
use super::{CancelFormatChange, DiskFormatUpgrade}; | ||
|
||
/// Implements [`DiskFormatUpgrade`] for pruning duplicate Sapling and Orchard note commitment trees from database | ||
pub struct NoMigration { | ||
version: Version, | ||
} | ||
|
||
impl NoMigration { | ||
/// Creates a new instance of the [`NoMigration`] upgrade. | ||
pub fn new(major: u64, minor: u64, patch: u64) -> Self { | ||
Self { | ||
version: Version::new(major, minor, patch), | ||
} | ||
} | ||
} | ||
|
||
impl DiskFormatUpgrade for NoMigration { | ||
fn version(&self) -> Version { | ||
self.version.clone() | ||
} | ||
|
||
fn description(&self) -> &'static str { | ||
"no migration" | ||
} | ||
|
||
#[allow(clippy::unwrap_in_result)] | ||
fn run( | ||
&self, | ||
_initial_tip_height: Height, | ||
_db: &ZebraDb, | ||
_cancel_receiver: &Receiver<CancelFormatChange>, | ||
) -> Result<(), CancelFormatChange> { | ||
Ok(()) | ||
} | ||
|
||
fn needs_migration(&self) -> bool { | ||
false | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
zebra-state/src/service/finalized_state/disk_format/upgrade/tree_keys_and_caches_upgrade.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
//! Applies the [`fix_tree_key_type`] and [`cache_genesis_roots`] upgrades to the database. | ||
use crossbeam_channel::Receiver; | ||
|
||
use semver::Version; | ||
use zebra_chain::block::Height; | ||
|
||
use crate::service::finalized_state::ZebraDb; | ||
|
||
use super::{cache_genesis_roots, fix_tree_key_type, CancelFormatChange, DiskFormatUpgrade}; | ||
|
||
/// Implements [`DiskFormatUpgrade`] for updating the sprout and history tree key type from | ||
/// `Height` to the empty key `()` and the genesis note commitment trees to cache their roots | ||
pub struct FixTreeKeyTypeAndCacheGenesisRoots; | ||
|
||
impl DiskFormatUpgrade for FixTreeKeyTypeAndCacheGenesisRoots { | ||
fn version(&self) -> Version { | ||
Version::new(25, 3, 0) | ||
} | ||
|
||
fn description(&self) -> &'static str { | ||
"tree keys and caches upgrade" | ||
} | ||
|
||
#[allow(clippy::unwrap_in_result)] | ||
fn run( | ||
&self, | ||
initial_tip_height: Height, | ||
db: &ZebraDb, | ||
cancel_receiver: &Receiver<CancelFormatChange>, | ||
) -> Result<(), CancelFormatChange> { | ||
// It shouldn't matter what order these are run in. | ||
cache_genesis_roots::run(initial_tip_height, db, cancel_receiver)?; | ||
fix_tree_key_type::run(initial_tip_height, db, cancel_receiver)?; | ||
Ok(()) | ||
} | ||
|
||
#[allow(clippy::unwrap_in_result)] | ||
fn validate( | ||
&self, | ||
db: &ZebraDb, | ||
cancel_receiver: &Receiver<CancelFormatChange>, | ||
) -> Result<Result<(), String>, CancelFormatChange> { | ||
let results = [ | ||
cache_genesis_roots::detailed_check(db, cancel_receiver)?, | ||
fix_tree_key_type::detailed_check(db, cancel_receiver)?, | ||
]; | ||
|
||
let result = if results.iter().any(Result::is_err) { | ||
Err(format!("{results:?}")) | ||
} else { | ||
Ok(()) | ||
}; | ||
|
||
Ok(result) | ||
} | ||
} |