deepbook: add cancel_live_order(s) graceful cancel APIs (DBU-349)#952
Merged
deepbook: add cancel_live_order(s) graceful cancel APIs (DBU-349)#952
Conversation
Adds `cancel_live_order` and `cancel_live_orders` on `Pool`. Both no-op when an order id is not in the balance manager's `account_open_orders` (already filled, cancelled, expired-and-swept, or not owned by this BM), instead of aborting with `big_vector::ENotFound` like `cancel_order` / `cancel_orders` do today. Existing entrypoints are unchanged (no ABI break). Authorization stays strict: orders in `account.open_orders()` belong to that BM by construction, so the live path still routes through `cancel_order` and its `EInvalidOrderBalanceManager` assert. The batch variant snapshots `account_open_orders` once and removes ids from the local copy as it cancels them, so duplicate ids in the input vector miss the second `contains` check instead of aborting. Tests cover: live cancel, already-filled skip (single + batch), unknown id no-op, and duplicate ids in the input vector. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
cancel_live_order(order_id)andcancel_live_orders(order_ids)onPool. Both no-op when an id is not in the balance manager'saccount_open_orders(already filled, cancelled, expired-and-swept, or not owned by this BM), instead of aborting withbig_vector::ENotFoundlikecancel_order/cancel_ordersdo today.cancel_order/cancel_ordersare unchanged — graceful behavior is opt-in via the new functions, no ABI break.Key decisions
account.open_orders()belong to that BM by construction (state/account.move:161), so the live path still routes throughcancel_orderand itsEInvalidOrderBalanceManagerassert. An id owned by a different BM falls through thecontainscheck and is silently skipped — matches the graceful intent without weakening any guard.cancel_live_orderssnapshotsaccount_open_ordersonce and removes ids from the local copy as it cancels them. This handles duplicate ids in the input vector naturally — the second occurrence misses the localcontainscheck instead of aborting in the underlyingcancel_order.account.open_orders(), the graceful variants route it throughcancel_order(which handles expiry insideprocess_cancel). They do not silently drop expired orders.OrderCanceledevent is emitted for them. Successful cancels emit the existingOrderCanceledevent via the unchangedcancel_orderpath.Test plan
cancel_live_order_succeeds_for_live_order— happy path on a single live ordercancel_live_order_skips_filled_order— single id that was filled by a crossing taker is silently skippedcancel_live_order_noop_for_unknown_id— never-placed id is a no-opcancel_live_orders_skips_filled_in_batch— mixed batch (one filled, one live); filled is skipped, live is cancelledcancel_live_orders_handles_duplicate_ids—[id, id]does not abort on the second passtest_cancel_orders_*,test_cancel_all_orders_*,test_place_and_cancel_*,test_self_matching_cancel_*🤖 Generated with Claude Code