Skip to content

Commit

Permalink
dex: 🌸 apply "fix chain halt in testnet 68" to main (#3950)
Browse files Browse the repository at this point in the history
Testnet 68 halted at height 100736, with an `.expect` here:


https://github.com/penumbra-zone/penumbra/blob/1c99e24ad5cf1ecc2855849d66221ecec25f9235/crates/core/component/dex/src/component/dex.rs#L66

This hit an error bubbled up from here:


https://github.com/penumbra-zone/penumbra/blob/1c99e24ad5cf1ecc2855849d66221ecec25f9235/crates/core/component/dex/src/component/router/route_and_fill.rs#L277

The error occurs in this method, which is only ever used at that
callsite:


https://github.com/penumbra-zone/penumbra/blob/1c99e24ad5cf1ecc2855849d66221ecec25f9235/crates/core/component/dex/src/swap_execution.rs#L18

It's a little unclear why that method has double fallibility.
Unfortunately, the answer may not be easily determined. It was added
here


9cd566d

which indicates that there was previously an infallible `max_price`, but
that code isn't included in the commit; the previous reference to an
infallible `max_price` was added in this commit


b4b2635

which doesn't have the impl either, so presumably it got mangled during
rebasing.

In any case, removing the double fallibility, as in this commit, allows
committing block 100736 on testnet 68, which I verified by running this
code against a local copy of a state snapshot.

Co-authored-by: Henry de Valence <[email protected]>
  • Loading branch information
cratelyn and hdevalence authored Mar 5, 2024
1 parent c307fc2 commit 98c42d8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ pub trait RouteAndFill: StateWrite + Sized {
}

// Ensure that we've actually executed, or else bail out.
let Some(accurate_max_price) = execution.max_price()? else {
let Some(accurate_max_price) = execution.max_price() else {
tracing::debug!("no traces in execution, exiting route_and_fill");
break;
};
Expand Down
8 changes: 4 additions & 4 deletions crates/core/component/dex/src/swap_execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ pub struct SwapExecution {

impl SwapExecution {
/// Returns the price of the latest execution trace.
pub fn max_price(&self) -> Result<Option<U128x128>> {
pub fn max_price(&self) -> Option<U128x128> {
let Some((input, output)) = self.traces.last().and_then(|trace| {
let input = trace.first()?;
let output = trace.last()?;
Some((input, output))
}) else {
return Ok(None);
return None;
};

let price = U128x128::ratio(input.amount, output.amount)?;
Ok(Some(price))
let price = U128x128::ratio(input.amount, output.amount).ok()?;
Some(price)
}
}

Expand Down

0 comments on commit 98c42d8

Please sign in to comment.