Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

draft hotfix for chain halt #4995

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 13 additions & 25 deletions crates/core/component/dex/src/component/position_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ impl<T: StateRead + ?Sized> PositionRead for T {}
pub trait PositionManager: StateWrite + PositionRead {
/// Close a position by id, removing it from the state.
///
/// If the position is already closed, this is a no-op.
/// If the position is not currently opened, this method is a no-op
///
/// # Errors
///
Expand All @@ -177,36 +177,24 @@ pub trait PositionManager: StateWrite + PositionRead {
.ok_or_else(|| anyhow::anyhow!("could not find position {} to close", id))?
.tap(|lp| tracing::trace!(prev_state = ?lp, "retrieved previous lp state"));

anyhow::ensure!(
matches!(
prev_state.state,
position::State::Opened | position::State::Closed,
),
"attempted to close a position with state {:?}, expected Opened or Closed",
prev_state.state
);
if prev_state.state == position::State::Opened {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK, inner logic gated on valid state antecedent.

let new_state = {
let mut new_state = prev_state.clone();
new_state.state = position::State::Closed;
new_state
};

// Optimization: skip state update if the position is already closed.
// This can happen if the position was queued for closure and premptively
// closed by the DEX engine during execution (e.g. auto-closing).
if prev_state.state == position::State::Closed {
self.update_position(id, Some(prev_state), new_state)
.await?;
self.record_proto(event::EventPositionClose { position_id: *id }.to_proto());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK. no change to the inner logic block.

} else {
tracing::debug!(
?id,
"position is already closed so we can skip state updates"
?prev_state.state,
"position is not currently open, skipping"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK. short-circuit.

);
return Ok(());
}

let new_state = {
let mut new_state = prev_state.clone();
new_state.state = position::State::Closed;
new_state
};

self.update_position(id, Some(prev_state), new_state)
.await?;
self.record_proto(event::EventPositionClose { position_id: *id }.to_proto());

Ok(())
}

Expand Down
Loading