From ce5d66703af06479be9c25ddf25b386e2cbf9368 Mon Sep 17 00:00:00 2001 From: Lucas Meier Date: Wed, 13 Nov 2024 12:37:49 -0700 Subject: [PATCH] Don't touch uninitialized storage for version safeguard This prevents an edge case where PD would crash if starting before the very first genesis. Not touching storage in that case will prevent nodes running continuously from genesis from benefitting from the safeguard, but an upgrade has already happened on mainnet, and so we don't care about not having the safeguard in this case. --- crates/core/app/src/app_version/component.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/crates/core/app/src/app_version/component.rs b/crates/core/app/src/app_version/component.rs index 52af54cd6c..ddc5f8c946 100644 --- a/crates/core/app/src/app_version/component.rs +++ b/crates/core/app/src/app_version/component.rs @@ -110,6 +110,11 @@ async fn write_app_version_safeguard(s: &mut S, x: u64) -> anyhow /// This will also result in the current app version being stored, so that future /// calls to this function will be checked against this state. pub async fn assert_latest_app_version(s: Storage) -> anyhow::Result<()> { + // If the storage is not initialized, avoid touching it at all, + // to avoid complaints about it already being initialized before the first genesis. + if s.latest_version() == u64::MAX { + return Ok(()); + } let mut delta = StateDelta::new(s.latest_snapshot()); let found = read_app_version_safeguard(&delta).await?; check_version(CheckContext::Running, APP_VERSION, found)?;