From f733274cb9195cf2531faae355bdb87cea96661a Mon Sep 17 00:00:00 2001 From: Erwan Or Date: Thu, 30 May 2024 23:00:59 -0400 Subject: [PATCH] dex(eviction): parse position id from index key --- .../component/dex/src/component/eviction_manager.rs | 11 ++++++++--- crates/core/component/dex/src/state_key.rs | 7 +++++++ repro.sh | 6 ------ 3 files changed, 15 insertions(+), 9 deletions(-) delete mode 100755 repro.sh diff --git a/crates/core/component/dex/src/component/eviction_manager.rs b/crates/core/component/dex/src/component/eviction_manager.rs index bf9e96fdf6..c4fa13f156 100644 --- a/crates/core/component/dex/src/component/eviction_manager.rs +++ b/crates/core/component/dex/src/component/eviction_manager.rs @@ -6,7 +6,6 @@ use std::collections::BTreeSet; use crate::state_key::eviction_queue; use anyhow::Result; use cnidarium::StateWrite; -use penumbra_proto::DomainType; use tracing::instrument; use crate::{component::PositionManager, DirectedTradingPair, TradingPair}; @@ -84,13 +83,19 @@ pub(crate) trait EvictionManager: StateWrite { let overhead_ab = stream_ab .take(overhead_size as usize) - .and_then(|(_, raw_id)| async move { position::Id::decode(&*raw_id) }) + .and_then(|(k, _)| async move { + let raw_id = eviction_queue::inventory_index::parse_id_from_key(k)?; + Ok(position::Id(raw_id)) + }) .try_collect::>() .await?; let overhead_ba = stream_ba .take(overhead_size as usize) - .and_then(|(_, raw_id)| async move { position::Id::decode(&*raw_id) }) + .and_then(|(k, _)| async move { + let raw_id = eviction_queue::inventory_index::parse_id_from_key(k)?; + Ok(position::Id(raw_id)) + }) .try_collect::>() .await?; diff --git a/crates/core/component/dex/src/state_key.rs b/crates/core/component/dex/src/state_key.rs index bedde3a7f6..6f0747d8f8 100644 --- a/crates/core/component/dex/src/state_key.rs +++ b/crates/core/component/dex/src/state_key.rs @@ -222,6 +222,7 @@ pub(crate) mod eviction_queue { pub(crate) mod inventory_index { use crate::lp::position; use crate::DirectedTradingPair; + use anyhow::ensure; use penumbra_num::Amount; pub(crate) fn by_trading_pair(pair: &DirectedTradingPair) -> [u8; 107] { @@ -245,5 +246,11 @@ pub(crate) mod eviction_queue { full_key } + + pub(crate) fn parse_id_from_key(key: Vec) -> anyhow::Result<[u8; 32]> { + ensure!(key.len() == 155, "key must be 155 bytes"); + let k = &key[123..155]; + Ok(k.try_into()?) + } } } diff --git a/repro.sh b/repro.sh deleted file mode 100755 index f272016ab6..0000000000 --- a/repro.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env bash -cargo run --release --bin pcli -- --home localnet_config tx lp order sell 183.070325gn@1.000501gm -cargo run --release --bin pcli -- --home localnet_config tx lp order sell 200gn@1.000501gm -cargo run --release --bin pcli -- --home localnet_config tx lp order sell 2.013014gn@1.00502gm -cargo run --release --bin pcli -- --home localnet_config tx lp order sell 2.013014gn@3.19999penumbra -cargo run --release --bin pcli -- --home localnet_config tx lp order buy 2.013014gn@3.19999penumbra