Centralize engine_seq minting through next_engine_seq() (#73)#84
Merged
joaquinbejar merged 1 commit intomainfrom Apr 25, 2026
Merged
Centralize engine_seq minting through next_engine_seq() (#73)#84joaquinbejar merged 1 commit intomainfrom
joaquinbejar merged 1 commit intomainfrom
Conversation
…_seq() Convert process_level_match from a static function to a method on OrderBook<T>. The matching emission path now calls self.next_engine_seq() directly instead of going through a private mint_engine_seq() helper, eliminating the duplicate fetch_add site that issue #73 flagged. - Drop the pub(super) mint_engine_seq() free function from book.rs. - next_engine_seq() inlines fetch_add(1, Relaxed) and is now the single source of truth for sequence allocation. - process_level_match() loses 5 parameters now that it can read last_trade_price, has_traded, price_level_changed_listener, engine_seq, and risk_state from &self. Closes #73.
There was a problem hiding this comment.
Pull request overview
This PR centralizes engine_seq minting by making OrderBook::next_engine_seq() the only place that performs the fetch_add(1, Relaxed), and updates the matching emission path to call that method directly (addressing issue #73’s duplication concern).
Changes:
- Convert
process_level_matchfrom a static helper into anOrderBook<T>method so it can read needed state from&self. - Remove the
mint_engine_seq()helper and inline itsfetch_add(1, Relaxed)logic intonext_engine_seq(). - Route price-level change event stamping through
self.next_engine_seq()from withinprocess_level_match.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/orderbook/matching.rs | Makes process_level_match a method and routes engine sequence stamping through next_engine_seq(). |
| src/orderbook/book.rs | Removes mint_engine_seq() and makes next_engine_seq() the single minting site by inlining the atomic increment. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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
process_level_matchfrom a static function to a method onOrderBook<T>.self.next_engine_seq()directly instead of going through a privatemint_engine_seq()helper, removing the duplicatefetch_addsite that issue Refactor matching loop to centralize engine_seq minting #73 flagged.next_engine_seq()is now the single source of truth and inlinesfetch_add(1, Relaxed).process_level_match()loses 5 parameters now that it can readlast_trade_price,has_traded,price_level_changed_listener,engine_seq, andrisk_statefrom&self.Closes #73.
Test plan
cargo clippy --all-targets --all-features -- -D warningscargo fmt --all --checkcargo test --all-features— 1125 passed, 0 failedcargo build --release --all-features