Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: release storage locks on testnet76 migration #4431

Merged
merged 1 commit into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 5 additions & 12 deletions crates/bin/pd/src/migrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,22 +62,12 @@ impl Migration {
);
let rocksdb_dir = pd_home.join("rocksdb");
let storage = Storage::load(rocksdb_dir, SUBSTORE_PREFIXES.to_vec()).await?;
let export_state = storage.latest_snapshot();
let root_hash = export_state.root_hash().await.expect("can get root hash");
let height = export_state
.get_block_height()
.await
.expect("can get block height");

tracing::debug!(pre_migration_root_hash = ?root_hash, current_height = ?height, ?force,
"determining if the chain is halted and the migration is allowed to run");

ensure!(
export_state.is_chain_halted().await || force,
storage.latest_snapshot().is_chain_halted().await || force,
"to run a migration, the chain halt bit must be set to `true` or use the `--force` cli flag"
);
tracing::info!("started migration");

tracing::info!(pre_migration_root_hash = ?root_hash, pre_upgrade_height = ?height, ?self, "started migration");
match self {
Migration::ReadyToStart => {
reset_halt_bit::migrate(storage, pd_home, genesis_start).await?;
Expand All @@ -86,12 +76,15 @@ impl Migration {
Migration::SimpleMigration => {
simple::migrate(storage, pd_home.clone(), genesis_start).await?
}

Migration::Testnet72 => {
testnet72::migrate(storage, pd_home.clone(), genesis_start).await?
}

Migration::Testnet74 => {
testnet74::migrate(storage, pd_home.clone(), genesis_start).await?
}

Migration::Testnet76 => {
testnet76::migrate(storage, pd_home.clone(), genesis_start).await?
}
Expand Down
22 changes: 10 additions & 12 deletions crates/bin/pd/src/migrate/testnet76.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use futures::TryStreamExt;
use jmt::RootHash;
use pbjson_types::Any;
use penumbra_app::app::StateReadExt as _;
use penumbra_app::SUBSTORE_PREFIXES;
use penumbra_asset::Balance;
use penumbra_auction::auction::dutch::DutchAuction;
use penumbra_proto::{DomainType, StateReadProto, StateWriteProto};
Expand Down Expand Up @@ -85,18 +84,22 @@ pub async fn migrate(
genesis_start: Option<tendermint::time::Time>,
) -> anyhow::Result<()> {
// Setup:
let export_state = storage.latest_snapshot();
let root_hash = export_state.root_hash().await.expect("can get root hash");
let initial_state = storage.latest_snapshot();
let chain_id = initial_state.get_chain_id().await?;
let root_hash = initial_state
.root_hash()
.await
.expect("chain state has a root hash");
let pre_upgrade_root_hash: RootHash = root_hash.into();
let pre_upgrade_height = export_state
let pre_upgrade_height = initial_state
.get_block_height()
.await
.expect("can get block height");
.expect("chain state has a block height");
let post_upgrade_height = pre_upgrade_height.wrapping_add(1);

// 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);
let mut delta = StateDelta::new(initial_state);
let (migration_duration, post_upgrade_root_hash) = {
let start_time = std::time::SystemTime::now();

Expand All @@ -109,23 +112,18 @@ 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");
tracing::info!(?post_upgrade_root_hash, "post-migration root hash");

(
start_time.elapsed().expect("start time not set"),
post_upgrade_root_hash,
)
};

storage.release().await;
let rocksdb_dir = pd_home.join("rocksdb");
let storage = Storage::load(rocksdb_dir, SUBSTORE_PREFIXES.to_vec()).await?;
let migrated_state = storage.latest_snapshot();

// 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.
let chain_id = migrated_state.get_chain_id().await?;
let app_state = penumbra_app::genesis::Content {
chain_id,
..Default::default()
Expand Down
Loading