Skip to content

Commit

Permalink
Address PR review
Browse files Browse the repository at this point in the history
  • Loading branch information
zbuc committed May 1, 2024
1 parent eeeabe2 commit 55ecee6
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions crates/bin/pd/src/migrate/testnet74.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,25 @@
//! Contains functions related to the migration script of Testnet72
//! Contains functions related to the migration script of Testnet74
use anyhow;
use cnidarium::{EscapedByteSlice, Snapshot, StateDelta, StateRead, StateWrite, Storage};
use futures::StreamExt as _;
use jmt::RootHash;
use penumbra_app::app::StateReadExt as _;
use penumbra_app::SUBSTORE_PREFIXES;
use penumbra_app::{app::StateReadExt as _, SUBSTORE_PREFIXES};
use penumbra_dex::SwapExecution;
use penumbra_num::Amount;
use penumbra_proto::penumbra::core::component as pb;
use penumbra_proto::StateWriteProto;
use penumbra_proto::{penumbra::core::component as pb, StateReadProto, StateWriteProto};
use penumbra_sct::component::clock::{EpochManager, EpochRead};
use prost::Message;
use std::path::PathBuf;

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

/// 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<()> {
let mut stream = delta.prefix_raw("dex/arb_execution/");
let mut stream = delta.prefix_proto("dex/arb_execution/");
while let Some(r) = stream.next().await {
let (key, swap_ex_bytes) = r?;
let mut swap_ex: SwapExecution =
pb::dex::v1::SwapExecution::decode(swap_ex_bytes.as_slice())?.try_into()?;
let (key, swap_ex_proto): (String, pb::dex::v1::SwapExecution) = r?;
let mut swap_ex: SwapExecution = swap_ex_proto.try_into()?;
swap_ex.output = swap_ex
.input
.asset_id
Expand All @@ -34,6 +30,11 @@ async fn fix_arb_execution_outputs(delta: &mut StateDelta<Snapshot>) -> anyhow::
}

/// Update the ordering of liquidity position indices to return in descending order (see #4189)
///
/// Lookups for liquidity positions based on starting asset were ordered backwards
/// and returning the positions with the least liquidity first. This migration
/// needs to modify the keys stored under the JMT `dex/ra/` prefix key to reverse
/// the ordering of the existing data.
async fn update_lp_index_order(delta: &mut StateDelta<Snapshot>) -> anyhow::Result<()> {
let prefix_key = "dex/ra/".as_bytes();
tracing::trace!(prefix_key = ?EscapedByteSlice(&prefix_key), "updating liquidity position indices");
Expand Down Expand Up @@ -68,15 +69,20 @@ async fn update_lp_index_order(delta: &mut StateDelta<Snapshot>) -> anyhow::Resu
}

/// Run the full migration, given an export path and a start time for genesis.
///
/// This migration script is responsible for:
///
/// - Updating the ordering of liquidity position indices to return in descending order (see #4189)
/// - 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/`
pub async fn migrate(
path_to_export: PathBuf,
genesis_start: Option<tendermint::time::Time>,
) -> anyhow::Result<()> {
// Lookups for liquidity positions based on starting asset were ordered backwards
// and returning the positions with the least liquidity first. This migration
// needs to modify the keys stored under the JMT `dex/ra/` prefix key to reverse
// the ordering of the existing data.

// Setup:
let rocksdb_dir = path_to_export.join("rocksdb");
let storage = Storage::load(rocksdb_dir.clone(), SUBSTORE_PREFIXES.to_vec()).await?;
Expand Down

0 comments on commit 55ecee6

Please sign in to comment.