From 42d87cd0024e8606f3eb981cb6bf4ced0c6f9d49 Mon Sep 17 00:00:00 2001 From: teor Date: Thu, 21 Sep 2023 13:20:33 +1000 Subject: [PATCH] Move spawn_format_change() into its own method --- .../src/service/finalized_state/zebra_db.rs | 38 +++++++++++-------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/zebra-state/src/service/finalized_state/zebra_db.rs b/zebra-state/src/service/finalized_state/zebra_db.rs index dfd1e32d7ef..687c7afb9e3 100644 --- a/zebra-state/src/service/finalized_state/zebra_db.rs +++ b/zebra-state/src/service/finalized_state/zebra_db.rs @@ -45,6 +45,9 @@ pub struct ZebraDb { // // This configuration cannot be modified after the database is initialized, // because some clones would have different values. + // + /// Should format upgrades and format checks be skipped for this instance? + /// Only used in test code. debug_skip_format_upgrades: bool, // Owned State @@ -88,24 +91,31 @@ impl ZebraDb { db: DiskDb::new(config, network), }; - db.check_max_on_disk_tip_height(); + db.spawn_format_change(config, network, format_change); - // We have to get this height before we spawn the upgrade task, because threads can take - // a while to start, and new blocks can be committed as soon as we return from this method. - let initial_tip_height = db.finalized_tip_height(); + db + } + /// Launch any required format changes or format checks, and store their thread handle. + pub fn spawn_format_change( + &mut self, + config: &Config, + network: Network, + format_change: DbFormatChange, + ) { // Always do format upgrades & checks in production code. - if cfg!(test) && db.debug_skip_format_upgrades { - return db; + if cfg!(test) && self.debug_skip_format_upgrades { + return; } - // Launch any required format changes or format checks, - // and put their handle in the database. - // - // `upgrade_db` is a special clone of the database, which can't be used to shut down + // We have to get this height before we spawn the upgrade task, because threads can take + // a while to start, and new blocks can be committed as soon as we return from this method. + let initial_tip_height = self.finalized_tip_height(); + + // `upgrade_db` is a special clone of this database, which can't be used to shut down // the upgrade task. (Because the task hasn't been launched yet, - // `db.format_change_handle` is always None.) - let upgrade_db = db.clone(); + // its `db.format_change_handle` is always None.) + let upgrade_db = self.clone(); // TODO: // - should debug_stop_at_height wait for the upgrade task to finish? @@ -118,9 +128,7 @@ impl ZebraDb { upgrade_db, ); - db.format_change_handle = Some(format_change_handle); - - db + self.format_change_handle = Some(format_change_handle); } /// Returns the configured network for this database.