Skip to content

Short term cancel prioritization#3325

Open
Kefancao wants to merge 5 commits intomainfrom
kefan/short-term-cancel
Open

Short term cancel prioritization#3325
Kefancao wants to merge 5 commits intomainfrom
kefan/short-term-cancel

Conversation

@Kefancao
Copy link
Contributor

@Kefancao Kefancao commented Feb 19, 2026

Changelist

[Describe or list the changes made in this PR]

Test Plan

[Describe how this PR was tested (if applicable)]

Author/Reviewer Checklist

  • If this PR has changes that result in a different app state given the same prior state and transaction list, manually add the state-breaking label.
  • If the PR has breaking postgres changes to the indexer add the indexer-postgres-breaking label.
  • If this PR isn't state-breaking but has changes that modify behavior in PrepareProposal or ProcessProposal, manually add the label proposal-breaking.
  • If this PR is one of many that implement a specific feature, manually label them all feature:[feature-name].
  • If you wish to for mergify-bot to automatically create a PR to backport your change to a release branch, manually add the label backport/[branch-name].
  • Manually add any of the following labels: refactor, chore, bug.

Summary by CodeRabbit

  • New Features

    • Deferred order matching: matching now runs during proposal preparation, preventing same-block optimistic fills and allowing same-block cancellations to stop matches.
  • Tests

    • Many tests updated to reflect deferred matching: adjusted expected fills, shifted some off-chain message timing to next-block replay, and aligned test flows with the new matching semantics.
  • Chores

    • Added localnet test script for deferred matching, increased local testnet timeouts for debugging, and extended CI triggers for relevant branches.

@Kefancao Kefancao requested a review from a team as a code owner February 19, 2026 22:13
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 19, 2026

📝 Walkthrough

Walkthrough

Defers matching: short-term orders placed during CheckTx use PlaceOrderNoMatch and are queued; matching runs later during PrepareProposal via MatchAllCrossedOrders, which replays queued takers to populate operations for proposal construction.

Changes

Cohort / File(s) Summary
Prepare & Exec Mode
protocol/app/prepare/expected_keepers.go, protocol/lib/tx_mode.go
Added MatchAllCrossedOrders to PrepareClobKeeper expectations; allow ExecModePrepareProposal in AssertCheckTxMode.
Prepare proposal flow
protocol/app/prepare/prepare_proposal.go, protocol/app/prepare/prepare_proposal_test.go
Invoke MatchAllCrossedOrders during PrepareProposal after price updates; tests updated to maybe-expect the call and short-circuit on error.
MemClob interface & mocks
protocol/x/clob/types/memclob.go, protocol/mocks/MemClob.go, protocol/mocks/PrepareClobKeeper.go
Added PlaceOrderNoMatch and MatchAllCrossedOrders to MemClob interface; added corresponding mock methods.
MemClob core impl
protocol/x/clob/memclob/memclob.go
Added pendingMatchOrders state, implemented PlaceOrderNoMatch (deferred placement) and MatchAllCrossedOrders (replay matching); adjusted TX bytes handling, replay and panic recovery.
Keeper & orders
protocol/x/clob/keeper/orders.go, protocol/x/clob/keeper/orders_test.go
Added Keeper.MatchAllCrossedOrders; PlaceShortTermOrder now uses PlaceOrderNoMatch and returns zero optimistic fills; tests updated for deferred semantics.
Operations utilities
protocol/x/clob/types/operations_to_propose.go
Added HasShortTermOrderTxBytes helper to check stored short-term order tx bytes.
Tests & e2e updates
protocol/x/clob/*_test.go, protocol/x/clob/e2e/*
Extensive test and e2e changes: moved match expectations from in-block to PrepareCheckState/replay, adjusted expected fills, message timings, and ctx usage after block advance.
Scripts & localnet
protocol/scripts/localnet_test_deferred_matching.sh, protocol/testing/testnet-local/local.sh, protocol/testing/testnet-dev/dev.sh
Added localnet test script for deferred matching; increased local consensus timeout and slowed block time for local testing.
CI
.github/workflows/protocol-build-and-push.yml, .github/workflows/protocol-build-and-push-snapshot.yml
Added branch pattern kefan/short-term-cancel to workflow triggers.

Sequence Diagram(s)

sequenceDiagram
    participant Client as Client
    participant CheckTx as CheckTx
    participant Keeper as Keeper
    participant MemClob as MemClob
    participant Prepare as PrepareProposal

    Client->>CheckTx: Submit order tx
    CheckTx->>Keeper: PlaceShortTermOrder(tx)
    Keeper->>MemClob: PlaceOrderNoMatch(order)
    MemClob->>MemClob: Add to pendingMatchOrders
    MemClob-->>Keeper: OrderStatus (deferred)
    Keeper-->>CheckTx: CheckTx success

    Note over CheckTx,Prepare: Later in same block (proposal construction)

    Prepare->>Keeper: PrepareProposal
    Prepare->>Keeper: MatchAllCrossedOrders(ctx)
    Keeper->>MemClob: MatchAllCrossedOrders()
    MemClob->>MemClob: Remove pending orders, replay as takers (arrival order)
    MemClob->>MemClob: Execute matching, update book & tx bytes
    MemClob-->>Keeper: Matching results / Operations
    Keeper-->>Prepare: Operations populated for proposal
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~65 minutes

Possibly related PRs

Suggested labels

feature:optimistic_execution, pml

Suggested reviewers

  • jayy04
  • shrenujb

Poem

🐇 I held my hops and kept them neat,
Orders waiting, quiet and sweet,
When proposals rise and moonbeams call,
I MatchAllCrossedOrders — one and all,
Books settle softly, a rabbit's small feat.

🚥 Pre-merge checks | ❌ 3

❌ Failed checks (2 warnings, 1 inconclusive)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description is largely incomplete, containing only an empty template with no actual changelist, test plan, or details about the substantial deferred matching feature implementation. Fill in the Changelist with key changes (deferred matching, new methods, affected tests) and describe the Test Plan with testing methodology and any validation performed.
Docstring Coverage ⚠️ Warning Docstring coverage is 27.59% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'Short term cancel prioritization' is vague and does not clearly convey the primary changes related to deferred matching implementation. Consider a more specific title that captures the core change, such as 'Implement deferred matching for orders via PlaceOrderNoMatch and MatchAllCrossedOrders' or similar.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch kefan/short-term-cancel

Tip

Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In @.github/workflows/protocol-build-and-push-snapshot.yml:
- Line 9: Remove the temporary feature-branch trigger 'kefan/short-term-cancel'
from the workflow push triggers so main will no longer run snapshot jobs for
that personal branch; locate the push: branches: list in the GitHub Actions
workflow (the entry containing 'kefan/short-term-cancel') and delete that string
from the array so only intended branches (e.g., main, release/*, etc.) remain.

- main
- 'release/protocol/v[0-9]+.[0-9]+.x' # e.g. release/protocol/v0.1.x
- 'release/protocol/v[0-9]+.x' # e.g. release/protocol/v1.x
- 'kefan/short-term-cancel'
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Remove this feature-branch trigger before merging to main.

Adding a personal/feature branch (kefan/short-term-cancel) to this workflow's push triggers means every commit to that branch fires all four snapshot jobs in parallel — including the build-and-push-snapshot-staging job. This pushes unreviewed feature-branch images directly to the staging ECR environment on every push, which is both an operational risk (staging receives untested builds) and wasteful (4× build minutes per commit).

This trigger is clearly a temporary developer convenience and must be removed before this PR is merged to main, where it would be permanently embedded in the mainline workflow.

🛠️ Proposed fix
     branches:
       - main
       - 'release/protocol/v[0-9]+.[0-9]+.x'  # e.g. release/protocol/v0.1.x
       - 'release/protocol/v[0-9]+.x'  # e.g. release/protocol/v1.x
-      - 'kefan/short-term-cancel'
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- 'kefan/short-term-cancel'
branches:
- main
- 'release/protocol/v[0-9]+.[0-9]+.x' # e.g. release/protocol/v0.1.x
- 'release/protocol/v[0-9]+.x' # e.g. release/protocol/v1.x
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.github/workflows/protocol-build-and-push-snapshot.yml at line 9, Remove the
temporary feature-branch trigger 'kefan/short-term-cancel' from the workflow
push triggers so main will no longer run snapshot jobs for that personal branch;
locate the push: branches: list in the GitHub Actions workflow (the entry
containing 'kefan/short-term-cancel') and delete that string from the array so
only intended branches (e.g., main, release/*, etc.) remain.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
protocol/testing/testnet-dev/dev.sh (1)

232-233: This addition violates the explicit "DO NOT add more config modifications" directive on edit_config().

Lines 223–225 state:

# Note: DO NOT add more config modifications in this method. Use cmd/config.go to configure the default config values.

Since timeout_commit = 10s is dev-env-specific (not appropriate for cmd/config.go as a global default), the right approach here is to either:

  1. Apply the override in the calling site (create_validators/create_full_nodes) rather than inside edit_config, or
  2. Acknowledge the exception by updating the directive comment so future contributors aren't misled.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@protocol/testing/testnet-dev/dev.sh` around lines 232 - 233, The new dasel
change to set '.consensus.timeout_commit' to '10s' violates the "DO NOT add more
config modifications" rule in edit_config(); either move this override out of
edit_config() and apply it in the caller(s) (e.g., add the dasel command in
create_validators and/or create_full_nodes where dev-only overrides are
applied), or explicitly update the directive comment in edit_config() to
document this exception; ensure references to cmd/config.go remain untouched and
keep edit_config() focused on shared/default edits while placing
environment-specific changes in the calling site(s).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@protocol/testing/testnet-dev/dev.sh`:
- Around line 232-234: The change sets '.consensus.timeout_commit' to '10s' in
dev.sh but it's unclear if this is temporary; either remove this from main
dev.sh and place it in the local-only script (e.g., local.sh) or gate it behind
an explicit flag (e.g., an env var like SLOW_COMMIT=true) so it doesn't affect
all users, and update the PR description/comments to document the intent and
rationale; locate the dasel command that writes '.consensus.timeout_commit' in
dev.sh and either move it to the local testnet script or wrap it with a guard
and add a brief comment explaining the chosen value.

---

Nitpick comments:
In `@protocol/testing/testnet-dev/dev.sh`:
- Around line 232-233: The new dasel change to set '.consensus.timeout_commit'
to '10s' violates the "DO NOT add more config modifications" rule in
edit_config(); either move this override out of edit_config() and apply it in
the caller(s) (e.g., add the dasel command in create_validators and/or
create_full_nodes where dev-only overrides are applied), or explicitly update
the directive comment in edit_config() to document this exception; ensure
references to cmd/config.go remain untouched and keep edit_config() focused on
shared/default edits while placing environment-specific changes in the calling
site(s).

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a0b8b43 and 91aaf54.

📒 Files selected for processing (1)
  • protocol/testing/testnet-dev/dev.sh

Comment on lines +232 to +234
# slow down block time for easier troubleshooting.
dasel put -t string -f "$CONFIG_FOLDER"/config.toml '.consensus.timeout_commit' -v '10s'

Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Clarify whether this timeout_commit = 10s change is permanent or temporary.

The comment "for easier troubleshooting" and the commit message ("slow down block processign on dev") both read like a temporary debug aid rather than a permanent configuration. A 10s commit timeout significantly degrades dev testnet block throughput for all users of the environment. If this is only needed for local deferred-matching testing, it should not land in main — use the local testnet script (local.sh) exclusively, or guard it explicitly.

If it is intended to be permanent, the PR description should document the rationale and the chosen value.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@protocol/testing/testnet-dev/dev.sh` around lines 232 - 234, The change sets
'.consensus.timeout_commit' to '10s' in dev.sh but it's unclear if this is
temporary; either remove this from main dev.sh and place it in the local-only
script (e.g., local.sh) or gate it behind an explicit flag (e.g., an env var
like SLOW_COMMIT=true) so it doesn't affect all users, and update the PR
description/comments to document the intent and rationale; locate the dasel
command that writes '.consensus.timeout_commit' in dev.sh and either move it to
the local testnet script or wrap it with a guard and add a brief comment
explaining the chosen value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

1 participant