Skip to content

Commit

Permalink
fix: release storage locks on testnet76 migration
Browse files Browse the repository at this point in the history
Refs #4430.
  • Loading branch information
conorsch committed May 21, 2024
1 parent 3f39c06 commit 613d0f8
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions crates/bin/pd/src/migrate/testnet76.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Contains functions related to the migration script of Testnet74
use anyhow;
use anyhow::Context;
use cnidarium::{Snapshot, StateDelta, Storage};
use futures::TryStreamExt;
use jmt::RootHash;
Expand Down Expand Up @@ -63,11 +63,13 @@ async fn heal_auction_vcb(delta: &mut StateDelta<Snapshot>) -> anyhow::Result<()
Ok(())
}

#[instrument(skip_all)]
async fn write_shielded_pool_params(delta: &mut StateDelta<Snapshot>) -> anyhow::Result<()> {
delta.put_shielded_pool_params(ShieldedPoolParameters::default());
Ok(())
}

#[instrument(skip_all)]
async fn write_fmd_params(delta: &mut StateDelta<Snapshot>) -> anyhow::Result<()> {
delta.put_previous_fmd_parameters(FmdParameters::default());
delta.put_current_fmd_parameters(FmdParameters::default());
Expand All @@ -94,6 +96,7 @@ pub async fn migrate(
.expect("can get block height");
let post_upgrade_height = pre_upgrade_height.wrapping_add(1);

tracing::debug!("initializing StateDelta");
// We initialize a `StateDelta` and start by reaching into the JMT for all entries matching the
// swap execution prefix. Then, we write each entry to the nv-storage.
let mut delta = StateDelta::new(export_state);
Expand All @@ -110,7 +113,6 @@ pub async fn migrate(
delta.put_block_height(0u64);
let post_upgrade_root_hash = storage.commit_in_place(delta).await?;
tracing::info!(?post_upgrade_root_hash, "post-upgrade root hash");

(
start_time.elapsed().expect("start time not set"),
post_upgrade_root_hash,
Expand All @@ -119,13 +121,16 @@ pub async fn migrate(

storage.release().await;
let rocksdb_dir = pd_home.join("rocksdb");
let storage = Storage::load(rocksdb_dir, SUBSTORE_PREFIXES.to_vec()).await?;
// FAILS HERE. Why?
let storage = Storage::load(rocksdb_dir, SUBSTORE_PREFIXES.to_vec()).await
.context("failed to reload state after writing")?;
let migrated_state = storage.latest_snapshot();
storage.release().await;

// The migration is complete, now we need to generate a genesis file. To do this, we need
// to lookup a validator view from the chain, and specify the post-upgrade app hash and
// initial height.
tracing::debug!("looking up chain id on new copy of state");
let chain_id = migrated_state.get_chain_id().await?;
let app_state = penumbra_app::genesis::Content {
chain_id,
Expand Down

0 comments on commit 613d0f8

Please sign in to comment.