Skip to content

Commit

Permalink
Read epoch from state when creating batch swap output
Browse files Browse the repository at this point in the history
This moves the epoch read directly to the route_and_fill method.
  • Loading branch information
cronokirby committed Apr 19, 2024
1 parent 873b1c7 commit d0f12bd
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,6 @@ mod tests {
trading_pair,
swap_flow,
0,
Epoch {
index: 0,
start_height: 0,
},
routing_params,
)
.await
Expand Down
3 changes: 0 additions & 3 deletions crates/core/component/dex/src/component/dex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use cnidarium_component::Component;
use penumbra_asset::{asset, Value, STAKING_TOKEN_ASSET_ID};
use penumbra_num::Amount;
use penumbra_proto::{StateReadProto, StateWriteProto};
use penumbra_sct::component::clock::EpochRead;
use tendermint::v0_37::abci;
use tracing::instrument;

Expand Down Expand Up @@ -56,7 +55,6 @@ impl Component for Dex {

// 2. For each batch swap during the block, calculate clearing prices and set in the JMT.

let current_epoch = state.get_current_epoch().await.expect("epoch is set");
let routing_params = state.routing_params().await.expect("dex params are set");

for (trading_pair, swap_flows) in state.swap_flows() {
Expand All @@ -69,7 +67,6 @@ impl Component for Dex {
.height
.try_into()
.expect("height is part of the end block data"),
current_epoch,
// Always include both ends of the target pair as fixed candidates.
routing_params
.clone()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use async_trait::async_trait;
use cnidarium::StateWrite;
use penumbra_asset::{asset, Value};
use penumbra_num::Amount;
use penumbra_sct::epoch::Epoch;
use penumbra_sct::component::clock::EpochRead;
use tracing::instrument;

use crate::{
Expand All @@ -24,14 +24,13 @@ use super::fill_route::FillError;
/// a block's batch swap flows.
#[async_trait]
pub trait HandleBatchSwaps: StateWrite + Sized {
#[instrument(skip(self, trading_pair, batch_data, block_height, epoch, params))]
#[instrument(skip(self, trading_pair, batch_data, block_height, params))]
async fn handle_batch_swaps(
self: &mut Arc<Self>,
trading_pair: TradingPair,
batch_data: SwapFlow,
// TODO: why not read these 2 from the state?
// This will be read from the ABCI request
block_height: u64,
epoch: Epoch,
params: RoutingParams,
) -> Result<()>
where
Expand Down Expand Up @@ -89,6 +88,7 @@ pub trait HandleBatchSwaps: StateWrite + Sized {
),
None => (0u64.into(), delta_2),
};
let epoch = self.get_current_epoch().await.expect("epoch is set");
let output_data = BatchSwapOutputData {
height: block_height,
epoch_starting_height: epoch.start_height,
Expand Down
9 changes: 0 additions & 9 deletions crates/core/component/dex/src/component/router/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use core::panic;
use futures::StreamExt;
use penumbra_asset::{asset, Value};
use penumbra_num::{fixpoint::U128x128, Amount};
use penumbra_sct::epoch::Epoch;
use rand_core::OsRng;
use std::sync::Arc;

Expand Down Expand Up @@ -1029,10 +1028,6 @@ async fn best_position_route_and_fill() -> anyhow::Result<()> {
trading_pair,
swap_flow,
0u32.into(),
Epoch {
index: 0,
start_height: 0,
},
routing_params,
)
.await
Expand Down Expand Up @@ -1179,10 +1174,6 @@ async fn multi_hop_route_and_fill() -> anyhow::Result<()> {
trading_pair,
swap_flow,
0u32.into(),
Epoch {
index: 0,
start_height: 0,
},
routing_params,
)
.await
Expand Down
9 changes: 0 additions & 9 deletions crates/core/component/dex/src/component/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use cnidarium::{ArcStateDeltaExt, StateDelta, TempStorage};
use futures::StreamExt;
use penumbra_asset::{asset, Value};
use penumbra_num::Amount;
use penumbra_sct::epoch::Epoch;
use rand_core::OsRng;

use crate::lp::action::PositionOpen;
Expand Down Expand Up @@ -637,10 +636,6 @@ async fn swap_execution_tests() -> anyhow::Result<()> {
trading_pair,
swap_flow,
0,
Epoch {
index: 0,
start_height: 0,
},
routing_params,
)
.await
Expand Down Expand Up @@ -754,10 +749,6 @@ async fn swap_execution_tests() -> anyhow::Result<()> {
trading_pair,
swap_flow,
0u32.into(),
Epoch {
index: 0,
start_height: 0,
},
routing_params,
)
.await
Expand Down

0 comments on commit d0f12bd

Please sign in to comment.