zebra_state/service/finalized_state/disk_format/upgrade/
no_migration.rs

1//! An implementation of [`DiskFormatUpgrade`] for marking the database as upgraded to a new format version.
2
3use crossbeam_channel::Receiver;
4
5use semver::Version;
6use zebra_chain::block::Height;
7
8use crate::service::finalized_state::ZebraDb;
9
10use super::{CancelFormatChange, DiskFormatUpgrade};
11
12/// Implements [`DiskFormatUpgrade`] for in-place upgrades that do not involve any migration
13/// of existing data into the new format.
14pub struct NoMigration {
15    description: &'static str,
16    version: Version,
17}
18
19impl NoMigration {
20    /// Creates a new instance of the [`NoMigration`] upgrade.
21    pub fn new(description: &'static str, version: Version) -> Self {
22        Self {
23            description,
24            version,
25        }
26    }
27}
28
29impl DiskFormatUpgrade for NoMigration {
30    fn version(&self) -> Version {
31        self.version.clone()
32    }
33
34    fn description(&self) -> &'static str {
35        self.description
36    }
37
38    #[allow(clippy::unwrap_in_result)]
39    fn run(
40        &self,
41        _initial_tip_height: Height,
42        _db: &ZebraDb,
43        _cancel_receiver: &Receiver<CancelFormatChange>,
44    ) -> Result<(), CancelFormatChange> {
45        Ok(())
46    }
47
48    fn needs_migration(&self) -> bool {
49        false
50    }
51}