Skip to content

Commit

Permalink
Log the running and initial disk database format versions on startup
Browse files Browse the repository at this point in the history
  • Loading branch information
teor2345 committed Jun 25, 2023
1 parent 2dbc6ce commit d7572cb
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 13 deletions.
16 changes: 9 additions & 7 deletions zebra-state/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use regex::Regex;

// For doc comment links
#[allow(unused_imports)]
use crate::config::{database_format_version_in_code, database_format_version_on_disk};
use crate::config::{self, Config};

pub use zebra_chain::transparent::MIN_TRANSPARENT_COINBASE_MATURITY;

Expand Down Expand Up @@ -37,9 +37,9 @@ pub const MAX_BLOCK_REORG_HEIGHT: u32 = MIN_TRANSPARENT_COINBASE_MATURITY - 1;
/// - we previously added compatibility code, and
/// - it's available in all supported Zebra versions.
///
/// Use [`database_format_version_in_code()`] or [`database_format_version_on_disk()`]
/// to get the full semantic format version.
pub const DATABASE_FORMAT_VERSION: u64 = 25;
/// Use [`config::database_format_version_in_code()`] or
/// [`config::database_format_version_on_disk()`] to get the full semantic format version.
pub(crate) const DATABASE_FORMAT_VERSION: u64 = 25;

/// The database format minor version, incremented each time the on-disk database format has a
/// significant data format change.
Expand All @@ -48,14 +48,16 @@ pub const DATABASE_FORMAT_VERSION: u64 = 25;
/// - adding new column families,
/// - changing the format of a column family in a compatible way, or
/// - breaking changes with compatibility code in all supported Zebra versions.
pub const DATABASE_FORMAT_MINOR_VERSION: u64 = 0;
pub(crate) const DATABASE_FORMAT_MINOR_VERSION: u64 = 0;

/// The database format patch version, incremented each time the on-disk database format has a
/// significant format compatibility fix.
pub const DATABASE_FORMAT_PATCH_VERSION: u64 = 2;
pub(crate) const DATABASE_FORMAT_PATCH_VERSION: u64 = 2;

/// The name of the file containing the minor and patch database versions.
pub const DATABASE_FORMAT_VERSION_FILE_NAME: &str = "version";
///
/// Use [`Config::version_file_path()`] to get the path to this file.
pub(crate) const DATABASE_FORMAT_VERSION_FILE_NAME: &str = "version";

/// The maximum number of blocks to check for NU5 transactions,
/// before we assume we are on a pre-NU5 legacy chain.
Expand Down
5 changes: 4 additions & 1 deletion zebra-state/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ mod service;
#[cfg(test)]
mod tests;

pub use config::{check_and_delete_old_databases, Config};
pub use config::{
check_and_delete_old_databases, database_format_version_in_code,
database_format_version_on_disk, Config,
};
pub use constants::MAX_BLOCK_REORG_HEIGHT;
pub use error::{
BoxError, CloneError, CommitSemanticallyVerifiedError, DuplicateNullifierError,
Expand Down
28 changes: 24 additions & 4 deletions zebrad/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ use abscissa_core::{
use semver::{BuildMetadata, Version};

use zebra_network::constants::PORT_IN_USE_ERROR;
use zebra_state::constants::{DATABASE_FORMAT_VERSION, LOCK_FILE_ERROR};
use zebra_state::{
constants::LOCK_FILE_ERROR, database_format_version_in_code, database_format_version_on_disk,
};

use crate::{
commands::EntryPoint,
Expand Down Expand Up @@ -260,13 +262,31 @@ impl Application for ZebradApp {
// collect the common metadata for the issue URL and panic report,
// skipping any env vars that aren't present

// reads state disk version file, doesn't open RocksDB database
let disk_db_version =
match database_format_version_on_disk(&config.state, config.network.network) {
Ok(Some(version)) => version.to_string(),
Ok(None) => "creating new database".to_string(),
Err(error) => {
let mut error = format!("error: {error:?}");
error.truncate(100);
error
}
};

let app_metadata = vec![
// cargo or git tag + short commit
// build-time constant: cargo or git tag + short commit
("version", build_version().to_string()),
// config
("Zcash network", config.network.network.to_string()),
// constants
("state version", DATABASE_FORMAT_VERSION.to_string()),
// code constant
(
"running state version",
database_format_version_in_code().to_string(),
),
// state disk file, doesn't open database
("initial disk state version", disk_db_version),
// build-time constant
("features", env!("VERGEN_CARGO_FEATURES").to_string()),
];

Expand Down
2 changes: 1 addition & 1 deletion zebrad/tests/acceptance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2089,7 +2089,7 @@ fn zebra_state_conflict() -> Result<()> {
dir_conflict_full.push("state");
dir_conflict_full.push(format!(
"v{}",
zebra_state::constants::DATABASE_FORMAT_VERSION
zebra_state::database_format_version_in_code().major,
));
dir_conflict_full.push(config.network.network.to_string().to_lowercase());
format!(
Expand Down

0 comments on commit d7572cb

Please sign in to comment.