Skip to content

Refactor spot-exchange Commands for improved Marshallable code readability and consistency#25

Open
vincentf13 wants to merge 1 commit into
masterfrom
refactor/spot-exchange-marshallable-models-5331915758396860001
Open

Refactor spot-exchange Commands for improved Marshallable code readability and consistency#25
vincentf13 wants to merge 1 commit into
masterfrom
refactor/spot-exchange-marshallable-models-5331915758396860001

Conversation

@vincentf13
Copy link
Copy Markdown
Owner

This PR refactors how spot-exchange uses net.openhft.chronicle.wire inside Aeron integration logic.

Instead of parsing objects manually inside network handlers and routing orchestrators, spot-infra commands (AuthCommand, DepositCommand, OrderCreateCommand, etc.) now strictly implement the Marshallable interface. Senders and receivers simply deserialize/serialize entire objects using .marshallable() via ChronicleWireKey.payload.

Additionally, we use direct copying onto thread-local off-heap structures inside Aeron loops to prevent hot-path allocations and Garbage Collection pressure.


PR created automatically by Jules for task 5331915758396860001 started by @vincentf13

…loc wire reads/writes

- Implemented explicit `readMarshallable` and `writeMarshallable` methods on `AuthCommand`, `DepositCommand`, `OrderCancelCommand`, `OrderCreateCommand`, and `SnapshotCommand`.
- Refactored `OrderCreateCommand` to carry the SBE payload as a `PointerBytesStore`.
- Updated `WsCommandInboundHandler` to use `.marshallable(cmd)` with `ChronicleWireKey.payload` to write domain commands directly to the WAL.
- Refactored `AeronSender` (gateway) and `AeronReceiver` (core) to cleanly serialize/deserialize the commands directly from the payload.
- Refactored `Engine` core to retrieve properties cleanly without duplicated raw wire manipulations.
- Fixed direct buffer `byte[]` allocation issues on hot-paths inside `AeronSender` by properly reading into a thread-local `scratchBuffer` directly.

Co-authored-by: vincentf13 <13410214+vincentf13@users.noreply.github.com>
@google-labs-jules
Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 25a19eb474

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

wire.read(ChronicleWireKey.payload).marshallable(cmd);

final int payloadLength = (int) cmd.getSbePayload().capacity();
cmd.getSbePayload().bytesForRead().read(scratchBuffer.buffer().byteArray(), 0, payloadLength);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Populate scratch bytes before forwarding ORDER_CREATE

After scratchBuffer.clear(), this code copies into scratchBuffer.buffer().byteArray() without first wrapping the buffer to valid writable storage, and it never advances scratchBuffer.bytes() positions. In the ORDER_CREATE path this can produce a null/invalid destination or leave wrapForRead() with zero readable bytes, so the gateway can send malformed or empty create-order payloads to Aeron.

Useful? React with 👍 / 👎.

wire.read(ChronicleWireKey.data).bytes(scratchBuffer.bytes());
// Copy SBE payload to scratchBuffer for decoding
long bytesLen = cmd.getSbePayload().capacity();
cmd.getSbePayload().bytesForRead().read(scratchBuffer.buffer().byteArray(), 0, (int) bytesLen);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Populate scratch bytes before decoding ORDER_CREATE

The engine repeats the same copy pattern by reading into scratchBuffer.buffer().byteArray() right after scratchBuffer.clear() and before preparing the scratch buffer state. Since wrapForRead() uses scratchBuffer.bytes().readRemaining(), ORDER_CREATE can be decoded from an empty/invalid buffer, leading to failed or corrupted create-order processing during WAL replay/live consumption.

Useful? React with 👍 / 👎.

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