From 853753f081bc3b25849ed384c3215de2940b5610 Mon Sep 17 00:00:00 2001 From: teor Date: Thu, 21 Sep 2023 13:19:55 +1000 Subject: [PATCH] Move check_max_on_disk_height() into the format checks --- .../finalized_state/disk_format/upgrade.rs | 3 ++- .../src/service/finalized_state/zebra_db.rs | 20 +++++++++---------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/zebra-state/src/service/finalized_state/disk_format/upgrade.rs b/zebra-state/src/service/finalized_state/disk_format/upgrade.rs index caa21c47bc1..60afb6964e4 100644 --- a/zebra-state/src/service/finalized_state/disk_format/upgrade.rs +++ b/zebra-state/src/service/finalized_state/disk_format/upgrade.rs @@ -558,7 +558,8 @@ impl DbFormatChange { let mut results = Vec::new(); // Check the entire format before returning any errors. - // + results.push(db.check_max_on_disk_tip_height()); + // This check can be run before the upgrade, but the upgrade code is finished, so we don't // run it early any more. (If future code changes accidentally make it depend on the // upgrade, they would accidentally break compatibility with older Zebra cached states.) diff --git a/zebra-state/src/service/finalized_state/zebra_db.rs b/zebra-state/src/service/finalized_state/zebra_db.rs index 34fbe6a5574..dfd1e32d7ef 100644 --- a/zebra-state/src/service/finalized_state/zebra_db.rs +++ b/zebra-state/src/service/finalized_state/zebra_db.rs @@ -141,9 +141,6 @@ impl ZebraDb { if let Some(format_change_handle) = self.format_change_handle.as_mut() { format_change_handle.check_for_panics(); } - - // This check doesn't panic, but we want to check it regularly anyway. - self.check_max_on_disk_tip_height(); } /// Shut down the database, cleaning up background tasks and ephemeral data. @@ -178,17 +175,20 @@ impl ZebraDb { /// # Logs an Error /// /// If Zebra is storing block heights that are close to [`MAX_ON_DISK_HEIGHT`]. - fn check_max_on_disk_tip_height(&self) { + pub(crate) fn check_max_on_disk_tip_height(&self) -> Result<(), String> { if let Some((tip_height, tip_hash)) = self.tip() { if tip_height.0 > MAX_ON_DISK_HEIGHT.0 / 2 { - error!( - ?tip_height, - ?tip_hash, - ?MAX_ON_DISK_HEIGHT, - "unexpectedly large tip height, database format upgrade required", - ); + let err = Err(format!( + "unexpectedly large tip height, database format upgrade required: \ + tip height: {tip_height:?}, tip hash: {tip_hash:?}, \ + max height: {MAX_ON_DISK_HEIGHT:?}" + )); + error!(?err); + return err; } } + + Ok(()) } }