Skip to content

perf: Do not re-parse STTx when relaying a transaction - #8593

Merged
bthomee merged 7 commits into
developfrom
mvadari/perf-relay-skip-reparse
Nov 10, 2026
Merged

bthomee merged 7 commits into
developfrom
mvadari/perf-relay-skip-reparse

Conversation

@mvadari

@mvadari mvadari commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

High Level Overview of Change

Add an Overlay::relay overload that takes the already-parsed STTx. NetworkOPs and OpenLedger use it, so relaying no longer parses the transaction a second time.

Context of Change

OverlayImpl::relay(hash, TMTransaction, toSkip) built a full STTx from the raw message (parse, applyTemplate, sha512Half, batch build) only to call isPseudoTx. Two of its three callers already hold the parsed STTx:

  • NetworkOPsImp::apply: every relayed tx, while masterLock is held.
  • OpenLedger::accept: recovered txs.

The new overload checks isPseudoTx on the caller's STTx. RCLConsensus::Adaptor::share has only the raw bytes from the transaction set, which can contain pseudo-transactions, so it keeps using the overload that parses. Malformed bytes from that path are still not relayed. Both overloads now forward to one private function (relayChecked) with the unchanged peer-selection logic.

API Impact

None. Overlay is internal to xrpld.

Before / After

  1. Improvement to existing functionality.
  2. Transaction relay.
  3. Every tx relayed from NetworkOPsImp::apply (for example submitted txs), and recovered txs in OpenLedger::accept.
  4. Yes: the NetworkOPs call runs while masterLock is held, so this shortens the time the lock is held.

Measured with a temporary jtx unit test (Release, Apple M-series, clang 23; this branch vs its merge base on develop, alternating, 3 runs; best of 5 × 20,000 calls; no peers attached, so the parse dominates):

Benchmark Before (develop, raw bytes) After (parsed STTx)
Overlay::relay of a NoOp tx 1886 / 1918 / 1892 ns 106 / 105 / 107 ns

With peers attached, the per-peer send cost is unchanged; the saving is the one parse per relayed tx.

Test Plan

  • New xrpl.overlay.tx_reduce_relay cases:
    • parsed tx: sent to every peer.
    • parsed pseudo-tx: queued, not sent.
    • unparsed pseudo-tx: queued, not sent; covers the existing parsing overload.
  • xrpld --unittest: 257 suites, 5237 cases, 0 failures.

AI-assisted (Claude Code).

🤖 Generated with Claude Code

OverlayImpl::relay parsed the whole STTx from the raw message only to
call isPseudoTx. NetworkOPs and OpenLedger already hold the parsed
STTx, so add a relay overload that takes it. RCLConsensus has only raw
bytes from the transaction set and keeps using the overload that parses
them, so malformed bytes are still not relayed.
@codecov

codecov Bot commented Oct 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The focused refactor preserves filtering and peer-selection behavior, adds relevant tests, and has no unresolved findings.

0 open findings

What changed in this PR

Avoids redundant transaction parsing during relay by reusing parsed STTx objects available to callers.

Changes:

  • Adds a parsed-transaction relay overload and shares peer-selection logic.
  • Updates NetworkOPs and OpenLedger to use the new overload.
  • Adds tests for ordinary and pseudo-transaction relay behavior.
File Description
src/​xrpld/​overlay/​Overlay.h Declares the parsed-transaction overload.
src/​xrpld/​overlay/​detail/​OverlayImpl.h Declares the overload implementation and shared helper.
src/​xrpld/​overlay/​detail/​OverlayImpl.cpp Reuses parsed transactions while preserving relay filtering.
src/​xrpld/​app/​misc/​NetworkOPs.cpp Passes the existing parsed transaction.
src/​xrpld/​app/​ledger/​detail/​OpenLedger.cpp Reuses parsed recovered transactions.
src/​test/​overlay/​tx_reduce_relay_test.cpp Tests parsed relay and pseudo-transaction filtering.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@ripple-ai-reviewer ripple-ai-reviewer Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This MR adds an Overlay::relay overload that accepts an already-parsed STTx, so NetworkOPsImp::apply and OpenLedger::accept can avoid re-parsing the transaction just to check isPseudoTx. Both overloads correctly forward to a new private relayChecked helper that preserves the existing peer-selection logic unchanged, and the pseudo-tx short-circuit logic (reset to std::nullopt so only the hash is queued, not the full tx) is correctly mirrored between the raw-bytes and pre-parsed paths. Call sites in NetworkOPs.cpp and OpenLedger.cpp pass the already-held STTx matching the relayed transaction, and new unit tests cover parsed-tx, parsed-pseudo-tx, and unparsed-pseudo-tx cases. I did not find correctness, security, or resource issues in the changed lines; the change is small, self-contained, and matches its stated intent.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The focused refactor preserves relay behavior and raw-message validation, with relevant tests and no unresolved findings.

0 open findings

🧠 Review effort: Balanced

@nbougalis nbougalis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice fix. A couple of small nits, but 👍 from me.

The overload of Overlay::relay that takes a parsed STTx no longer
takes a separate hash; it uses tx.getTransactionID(). Its message
parameter is now const.

@ripple-ai-reviewer ripple-ai-reviewer Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Clean, mechanical refactor: adds an Overlay::relay overload that accepts an already-parsed STTx so NetworkOPs::apply and OpenLedger::accept avoid re-parsing the transaction, while both overloads funnel into a shared private relayChecked that preserves the existing peer-selection logic. The pseudo-tx check is correctly re-derived from the caller-supplied STTx instead of re-parsing raw bytes, the hash is correctly taken from the parsed tx, and the exception-swallowing behavior on the raw-bytes path is preserved unchanged. New unit tests cover the parsed/unparsed and tx/pseudo-tx combinations. I did not find a correctness, security, or resource issue introduced by the added (+) lines.

@ripple-ai-reviewer ripple-ai-reviewer Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Solid, well-scoped perf refactor: adds an Overlay::relay overload taking an already-parsed STTx and routes NetworkOPsImp::apply and OpenLedger::accept through it, with both overloads funneling into a new private relayChecked. The call-site changes and new overload logic look correct and match the described hash/pseudo-tx semantics. One point worth double-checking: the raw-bytes overload's local 'relay' bool was removed, and the adjacent catch block (not shown as changed) may still reference it.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The focused refactor preserves relay behavior, updates both callers consistently, and adds targeted tests with no unresolved findings.

0 open findings

🧠 Review effort: Balanced

@nbougalis nbougalis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice!

@ripple-ai-reviewer ripple-ai-reviewer Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues found.

@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown

This PR has conflicts, please resolve them in order for the PR to be reviewed.

@ripple-ai-reviewer ripple-ai-reviewer Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues found.

@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown

All conflicts have been resolved. Assigned reviewers can now start or resume their review.

Comment thread src/xrpld/app/misc/NetworkOPs.cpp Resolved
Comment thread src/xrpld/overlay/Overlay.h Resolved
Comment thread src/xrpld/overlay/Overlay.h Resolved
Mirror the raw-message overload, (hash, m, toSkip), with the hash
replaced by the STTx it comes from, and document every parameter.

@ripple-ai-reviewer ripple-ai-reviewer Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues found.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The parsed-transaction relay changes have no active review issues.

No open issues 🎉

Review effort: Balanced

@mvadari mvadari added the Ready to merge *PR author* thinks it's ready to merge. Has passed code review. Perf sign-off may still be required. label Nov 10, 2026
@bthomee
bthomee enabled auto-merge November 10, 2026 14:07
@bthomee
bthomee added this pull request to the merge queue Nov 10, 2026
Merged via the queue into develop with commit 1c41d8d Nov 10, 2026
105 checks passed
@bthomee
bthomee deleted the mvadari/perf-relay-skip-reparse branch November 10, 2026 15:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Ready to merge *PR author* thinks it's ready to merge. Has passed code review. Perf sign-off may still be required.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants