Skip to content

Commit

Permalink
Move check_max_on_disk_height() into the format checks
Browse files Browse the repository at this point in the history
  • Loading branch information
teor2345 committed Sep 21, 2023
1 parent c9bec2c commit 853753f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.)
Expand Down
20 changes: 10 additions & 10 deletions zebra-state/src/service/finalized_state/zebra_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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(())
}
}

Expand Down

0 comments on commit 853753f

Please sign in to comment.