-
Notifications
You must be signed in to change notification settings - Fork 313
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
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
/// | ||
|
@@ -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 { | ||
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()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(()) | ||
} | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.