Skip to content

R1-04: Messages, events, and reason codes - #4

Merged
aravgarg28 merged 2 commits into
mainfrom
task/R1-04-events
Jul 27, 2026
Merged

R1-04: Messages, events, and reason codes#4
aravgarg28 merged 2 commits into
mainfrom
task/R1-04-events

Conversation

@aravgarg28

Copy link
Copy Markdown
Owner

R1-04: Messages, events, and reason codes — Completion Report

Status: complete
Branch/PR: task/R1-04-events

What was built

The exchange's message and event vocabulary, translated from EXCHANGE_RULES.md and the MATCHING_ENGINE_SPEC I/O lists.

  • core/messages.hpp: OrderType enum; NewOrder (R-3.2), CancelOrder (R-6.1), ModifyOrder (R-7.1), SessionEnd (R-12) structs; Inbound variant.
  • core/events.hpp: complete RejectReason (17) and CancelReason (5) enumerations (R-14) plus LiquidityFlag; EventHeader (R-10.2, kept separate so payloads stay ≤64 B); OrderAccepted/OrderRejected/OrderCanceled/OrderModified/Fill/Trade payloads; Outbound variant.
  • core/src/enums.cpp: to_cstr tables (switch, no default → -Wswitch enforces exhaustiveness) and from_cstr round-trip parsers.

Acceptance criteria

  • All inbound messages + outbound events matching R-3.2/R-4.3/R-14 and the spec I/O lists — present
  • RejectReason/CancelReason complete enumerations — 17 + 5, static_assert pins array size to enum count
  • Trivially-copyable + sizeof ≤ 64 static_asserts — on every payload struct + variants
  • enum↔string tables (logs/tests) — to_cstr + from_cstr, round-trip tested
  • Excludes respected — no MD messages (TradeMD/book deltas → R2), no serialization (→ R1-11)

Verification output

ctest --preset debug        → 100% tests passed out of 39
ctest --preset asan-ubsan   → 100% tests passed out of 39   (no ASan/UBSan findings)
-DMICROSIM_WERROR=ON build   → clean (no warnings)
./scripts/format.sh --check → clang-format: 48 files OK

Tests added

Test Covers Type
static_assert (headers + test_events.cpp) trivial-copyability, ≤64 B, array/enum-count sync compile-time
NewOrder.*, Inbound.*, Outbound.* field wiring, variant dispatch, MARKET price=0 (R-3.2) unit
RejectReason.*, CancelReason.* every value uniquely named, spec-canonical strings, name round-trip unit
OrderTypeAndLiquidity.Names enum string tables unit

Deviations / Questions

  1. EventHeader (seq_out/seq_in/ts_event) is a separate struct, not embedded in each event payload. R-10.2 says every event "carries" the header; embedding its 24 bytes would push Trade (49 B of ids) past the 64-byte payload budget from MEMORY_MODEL.md. Keeping payloads header-free preserves ≤64 B and trivial-copyability; the sequencer (R1-11) pairs header+payload. Flagging as a conscious structural choice consistent with both docs.
  2. No OrderFilled event — the FILLED-terminal state is implicit per R-4.3 (the fill that brings remaining to zero), matching the spec's state machine. Noted so it's clearly intentional.

Notes for reviewer

  • Fill.fee is a signed Cash (taker fee > 0 cost, maker rebate < 0 cost) so accounting (R2) can apply it uniformly; the audit Trade carries full identities while the anonymized public TradeMD is deferred to md (R2).

Defines the exchange's inbound message and outbound event vocabulary
from EXCHANGE_RULES.md and the MATCHING_ENGINE_SPEC I/O lists:

- messages.hpp: OrderType enum; NewOrder (R-3.2), CancelOrder (R-6.1),
  ModifyOrder (R-7.1), SessionEnd (R-12) structs; Inbound variant.
- events.hpp: complete RejectReason (17) and CancelReason (5)
  enumerations (R-14) and LiquidityFlag; EventHeader (R-10.2, kept
  separate so payloads stay small); OrderAccepted/OrderRejected/
  OrderCanceled/OrderModified/Fill/Trade payloads; Outbound variant.
  The FILLED-terminal state is implicit per R-4.3, so no OrderFilled
  event. Public market-data messages are excluded (belong to md, R2).
- enums.cpp: to_cstr string tables (switch with no default so -Wswitch
  enforces exhaustiveness) and from_cstr round-trip parsers.

Every payload is trivially copyable and <= 64 bytes (static_assert);
kAll* arrays are pinned to the enum counts. Tests cover field wiring,
variant dispatch, unique/canonical reason-code names matching the spec
strings, and name round-trips.

Verified: 39/39 tests pass under debug and asan-ubsan; -Werror clean;
clang-format clean.
Build-time gtest_discover_tests intermittently fails on CI runners
with 'Missing expected JSON file with test list'. PRE_TEST enumerates
at ctest time instead, avoiding running executables during the build.
@aravgarg28
aravgarg28 merged commit 15d24b6 into main Jul 27, 2026
5 checks passed
@aravgarg28
aravgarg28 deleted the task/R1-04-events branch July 27, 2026 03:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant