Skip to content

Commit

Permalink
pd(migrate): add auction parameters to chain state for Testnet74
Browse files Browse the repository at this point in the history
  • Loading branch information
erwanor committed May 7, 2024
1 parent 6ee9cb4 commit 9f5dee3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
5 changes: 4 additions & 1 deletion crates/bin/pd/src/migrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ pub enum Migration {
/// Testnet-72 migration:
/// - Migrate `BatchSwapOutputData` to new protobuf, replacing epoch height with index.
Testnet72,
/// Testnet-74 migration: change liquidity positions to be ordered in descending order rather than ascending.
/// Testnet-74 migration:
/// - Update the base liquidity index to order routable pairs by descending liquidity
/// - Update arb executions to include the amount of filled input in the output
/// - Add `AuctionParameters` to the consensus state
Testnet74,
}

Expand Down
20 changes: 15 additions & 5 deletions crates/bin/pd/src/migrate/testnet74.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use cnidarium::{EscapedByteSlice, Snapshot, StateDelta, StateRead, StateWrite, S
use futures::StreamExt as _;
use jmt::RootHash;
use penumbra_app::{app::StateReadExt as _, SUBSTORE_PREFIXES};
use penumbra_auction::{params::AuctionParameters, StateWriteExt};
use penumbra_dex::SwapExecution;
use penumbra_num::Amount;
use penumbra_proto::{penumbra::core::component as pb, StateReadProto, StateWriteProto};
Expand All @@ -13,6 +14,13 @@ use std::path::PathBuf;

use crate::testnet::generate::TestnetConfig;

/// Writes the auction parameters to the chain state.
async fn write_auction_parameters(delta: &mut StateDelta<Snapshot>) -> anyhow::Result<()> {
let params = AuctionParameters {};
delta.put_auction_params(params);
Ok(())
}

/// Updates arb execution output amounts to include the input amount instead
/// of reporting only profit (see #3790).
async fn fix_arb_execution_outputs(delta: &mut StateDelta<Snapshot>) -> anyhow::Result<()> {
Expand Down Expand Up @@ -73,12 +81,11 @@ async fn update_lp_index_order(delta: &mut StateDelta<Snapshot>) -> anyhow::Resu
/// This migration script is responsible for:
///
/// - Updating the ordering of liquidity position indices to return in descending order (see #4189)
/// * JMT: `dex/ra/`
/// - Updating arb execution output amounts to include the input amount instead of reporting only profit (see #3790)
///
/// Affected JMT key prefixes:
///
/// - `dex/ra/`
/// - `dex/arb_execution/`
/// * JMT: `dex/arb_execution/`
/// - Add `AuctionParameters` to the chain state
/// * JMT: `dex/auction_parameters`
pub async fn migrate(
path_to_export: PathBuf,
genesis_start: Option<tendermint::time::Time>,
Expand Down Expand Up @@ -107,6 +114,9 @@ pub async fn migrate(
// Fix the arb execution output amounts.
fix_arb_execution_outputs(&mut delta).await?;

// Write auction parameters
write_auction_parameters(&mut delta).await?;

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");
Expand Down

0 comments on commit 9f5dee3

Please sign in to comment.