Skip to content

Commit

Permalink
dex: avoid chain halts in case of arb failures (#3897)
Browse files Browse the repository at this point in the history
In #3893 we encountered a bug in arb search logic that caused a chain
halt. While that bug shouldn't exist, it also shouldn't have stopped the
entire chain. Rather, we should continue operating without performing
arbitrage.

This commit does not fix the bug in #3893, but it does mean that the
effect of that bug is just to stop arb from occurring rather than
halting the chain.
  • Loading branch information
hdevalence authored Feb 27, 2024
1 parent bc4b854 commit b751dda
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions crates/core/component/dex/src/component/dex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ use anyhow::Result;
use async_trait::async_trait;
use cnidarium::{StateRead, StateWrite};
use cnidarium_component::Component;
use penumbra_asset::{asset, STAKING_TOKEN_ASSET_ID};
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;
Expand Down Expand Up @@ -68,7 +69,7 @@ impl Component for Dex {
}

// Then, perform arbitrage:
let arb_burn = state
let arb_burn = match state
.arbitrage(
*STAKING_TOKEN_ASSET_ID,
vec![
Expand Down Expand Up @@ -100,7 +101,18 @@ impl Component for Dex {
],
)
.await
.expect("must be able to process arbitrage");
{
Ok(v) => v,
Err(e) => {
// The arbitrage search should not error, but if it does, we should
// simply not perform arbitrage, rather than halting the entire chain.
tracing::warn!(?e, "error processing arbitrage, this is a bug");
Value {
amount: Amount::zero(),
asset_id: *STAKING_TOKEN_ASSET_ID,
}
}
};

if arb_burn.amount != 0u64.into() {
// TODO: hack to avoid needing an asset cache for nice debug output
Expand Down

0 comments on commit b751dda

Please sign in to comment.