Skip to content

Commit

Permalink
app(safeguard): collapse match statement and propagate changes
Browse files Browse the repository at this point in the history
  • Loading branch information
erwanor committed Dec 9, 2024
1 parent f10a497 commit 96e7e27
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
7 changes: 4 additions & 3 deletions crates/bin/pd/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ use pd::{
join::network_join,
},
};
use penumbra_app::app_version::assert_latest_app_version;
use penumbra_app::SUBSTORE_PREFIXES;
use penumbra_app::app_version::check_and_update_app_version;
use penumbra_app::{APP_VERSION, SUBSTORE_PREFIXES};
use rand::Rng;
use rand_core::OsRng;
use tendermint_config::net::Address as TendermintAddress;
Expand Down Expand Up @@ -103,9 +103,10 @@ async fn main() -> anyhow::Result<()> {
.context(
"Unable to initialize RocksDB storage - is there another `pd` process running?",
)?;
assert_latest_app_version(storage.clone()).await?;
check_and_update_app_version(storage.clone()).await?;

tracing::info!(
APP_VERSION,
?abci_bind,
?grpc_bind,
?grpc_auto_https,
Expand Down
2 changes: 1 addition & 1 deletion crates/core/app/src/app_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ pub const APP_VERSION: u64 = 8;
cfg_if::cfg_if! {
if #[cfg(feature="component")] {
mod component;
pub use component::{assert_latest_app_version, migrate_app_version};
pub use component::{check_and_update_app_version, migrate_app_version};
}
}
11 changes: 7 additions & 4 deletions crates/core/app/src/app_version/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,14 @@ enum CheckContext {
Migration,
}

/// Check that the expected version matches the found version, if it set.
/// This will return an error if the versions do not match.
fn check_version(ctx: CheckContext, expected: u64, found: Option<u64>) -> anyhow::Result<()> {
let found = match (expected, found) {
(x, Some(y)) if x != y => y,
_ => return Ok(()),
};
let found = found.unwrap_or(expected);
if found == expected {
return Ok(());
}

match ctx {
CheckContext::Running => {
let expected_name = version_to_software_version(expected);
Expand Down

0 comments on commit 96e7e27

Please sign in to comment.