Repository navigation
perf: Do not re-parse STTx when relaying a transaction - #8593
Conversation
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 Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
🟢 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
NetworkOPsandOpenLedgerto 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.
There was a problem hiding this comment.
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.
nbougalis
left a comment
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
|
This PR has conflicts, please resolve them in order for the PR to be reviewed. |
|
All conflicts have been resolved. Assigned reviewers can now start or resume their review. |
Mirror the raw-message overload, (hash, m, toSkip), with the hash replaced by the STTx it comes from, and document every parameter.
High Level Overview of Change
Add an
Overlay::relayoverload that takes the already-parsedSTTx.NetworkOPsandOpenLedgeruse it, so relaying no longer parses the transaction a second time.Context of Change
OverlayImpl::relay(hash, TMTransaction, toSkip)built a fullSTTxfrom the raw message (parse,applyTemplate,sha512Half, batch build) only to callisPseudoTx. Two of its three callers already hold the parsedSTTx:NetworkOPsImp::apply: every relayed tx, whilemasterLockis held.OpenLedger::accept: recovered txs.The new overload checks
isPseudoTxon the caller'sSTTx.RCLConsensus::Adaptor::sharehas 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.
Overlayis internal toxrpld.Before / After
NetworkOPsImp::apply(for example submitted txs), and recovered txs inOpenLedger::accept.NetworkOPscall runs whilemasterLockis 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):develop, raw bytes)STTx)Overlay::relayof a NoOp txWith peers attached, the per-peer send cost is unchanged; the saving is the one parse per relayed tx.
Test Plan
xrpl.overlay.tx_reduce_relaycases: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