Repository navigation
refactor: Pass TMTransaction by pointer in Overlay::relay - #8731
Open
FawwazLawal wants to merge 5 commits into
Open
FawwazLawal wants to merge 5 commits into
FawwazLawal wants to merge 5 commits into
Conversation
Replace std::optional<std::reference_wrapper<protocol::TMTransaction>>
with protocol::TMTransaction const* on Overlay::relay(UInt256, ...)
and OverlayImpl::relayChecked. Callers pass nullptr where they
previously passed std::nullopt or {}; dereferencing the pointer
replaces the prior tx->get() call on the reference wrapper. No
behaviour change: the two branches ("hash only" and "with message")
map one to one.
The sibling Overlay::relay(STTx, TMTransaction const&, ...) overload
keeps its signature; its body now forwards &m or nullptr into
relayChecked instead of wrapping m in an optional reference wrapper.
Drop three now-unused <functional> includes from Overlay.h,
OverlayImpl.h and OverlayImpl.cpp.
Fixes XRPLF#8607.
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain for the transaction-relay pointer refactor.
No open issues 🎉
What changed in this PR
Simplifies transaction relay in xrpld’s internal overlay by replacing optional reference wrappers with nullable TMTransaction const* pointers, addressing #8607. Relay behavior and wire format remain unchanged.
Changes:
- Updates the hash-based
relayinterface andrelayCheckedhelper to accept pointers. - Converts callers and forwarding logic to use message addresses or
nullptr, preserving the parsed-transaction overload’s signature. - Adjusts existing tests and explanatory comments, and removes unused
<functional>includes.
| File | Description |
|---|---|
src/xrpld/overlay/Overlay.h |
Changes the hash-based relay interface to a nullable const pointer. |
src/xrpld/overlay/detail/PeerImp.cpp |
Passes nullptr for hash-only pseudo-transaction relay. |
src/xrpld/overlay/detail/OverlayImpl.h |
Aligns relay and helper declarations with the pointer interface. |
src/xrpld/overlay/detail/OverlayImpl.cpp |
Uses pointer checks, forwarding, and dereferencing while preserving relay logic. |
src/xrpld/app/consensus/RCLConsensus.cpp |
Passes the local transaction message by address. |
src/test/overlay/tx_reduce_relay_test.cpp |
Updates relay calls and the hash-only test comment for pointer semantics. |
Review effort: Balanced
…mtransaction-no-raw-pointer
…mtransaction-no-raw-pointer
…mtransaction-no-raw-pointer
…mtransaction-no-raw-pointer
This branch has not been deployed
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.
High Level Overview of Change
Replace
std::optional<std::reference_wrapper<protocol::TMTransaction>>with a rawprotocol::TMTransaction const*onOverlay::relay(UInt256 const&, ...)andOverlayImpl::relayChecked. Callers passnullptrwhere they previously passedstd::nulloptor{}. The pointer type says "maybe a message, or just queue the hash" in one level instead of two, and removes the extra wrapper at every call site. The siblingOverlay::relay(STTx const&, protocol::TMTransaction const&, ...)overload keeps its signature; only its body now forwards&mornullptrintorelayChecked.Fixes #8607.
Context of Change
Overlay::relay(UInt256 const&, std::optional<std::reference_wrapper<protocol::TMTransaction>>, std::set<Peer::ID> const&)has been on theOverlayinterface since well before #8593 (git show 1c41d8d2c~1:src/xrpld/overlay/Overlay.hshows it at lines 184-188). #8593 (merged 2026-11-10,1c41d8d2c0) added a sibling overloadOverlay::relay(STTx const&, protocol::TMTransaction const&, ...)that takes the caller's already-parsedSTTxso it is not parsed again (#8593 doc comment and title), and the private helperOverlayImpl::relayChecked. In review of that PR the hash-plus-optional parameter was flagged as awkward: anoptional<reference_wrapper<TMTransaction>>is a two-level wrapper for "maybe a reference to aTMTransaction", which aTMTransaction const*expresses in one level withnullptras the "no transaction" sentinel. #8607 names the pattern and the sites to update.Lifetime stays the same as before:
relayCheckedonly reads from the pointer within the same call (dereferences it once to build astd::make_shared<Message>(*tx, protocol::mtTRANSACTION)), it does not store it, and all call sites already own the referent for the duration of the call (msgis a local inRCLConsensus::Adaptor::shareand in the test,nullptron the "hash only" branch).OverlayImpl::relay's body still handles pseudo-transactions by reassigning the pointer tonullptrbefore the call falls through torelayChecked(the pointer analogue of the priortx.reset()on the optional);relayCheckedthen takes the queue-only branch and queues the hash (OverlayImpl.cpp:1379,addTxQueue(hash)) for peers that negotiated tx reduce-relay; the announcement itself comes later in aTMHaveTransactions, whichtx_reduce_relay_test.cpp:235-239describes as "a pseudo-transaction, or an explicit nullptr as here. A queued hash is announced later in a TMHaveTransactions".The sibling
Overlay::relay(STTx const&, protocol::TMTransaction const&, ...)overload used byNetworkOPs(src/xrpld/app/misc/NetworkOPs.cpp:1887) andOpenLedger(src/xrpld/app/ledger/detail/OpenLedger.cpp:151) keeps its by-reference signature, since those callers already hold a valid message by reference; only its forwarding body is adjusted.API Impact
libxrplchange (any change that may affectlibxrplor dependents oflibxrpl)src/xrpld/overlay/Overlay.his asrc/xrpld/-private header, not an installedlibxrplheader, so this is not alibxrplchange. The wire format is unchanged: theTMTransactionthatrelayCheckedwraps instd::make_shared<Message>(*tx, protocol::mtTRANSACTION)is byte-identical to the prior path. No public JSON-RPC / WebSocket method or field is touched.Before / After
Interface
src/xrpld/overlay/Overlay.h:Private helper
src/xrpld/overlay/detail/OverlayImpl.h:Call-sites that change (all 5):
Inside
OverlayImpl::relay, the pseudo-transaction reset becomes a null assignment:The sibling
Overlay::relay(STTx const&, TMTransaction const&, ...)overload forwards without the wrapper:Three now-unused
<functional>includes drop fromsrc/xrpld/overlay/Overlay.h:22,src/xrpld/overlay/detail/OverlayImpl.h:47andsrc/xrpld/overlay/detail/OverlayImpl.cpp:82: the only use in each of those files was thestd::reference_wrapperin the old signature.Test Plan
The change is representation-only. Correctness is covered by the existing
xrpl.overlayunit suite, which exercises both thenullptrbranch (hash-only relay, pseudo-transactions, and thetx_reduce_relay_testbranch at line 267) and the&msgbranch (normal relay inRCLConsensus::Adaptor::shareand thetx_reduce_relay_testbranches at lines 222 and 327).Ran locally in the
ghcr.io/xrplf/xrpld/nix-ubuntu:sha-d3a71b2docker image (the tag.github/scripts/strategy-matrix/linux.jsonpins for the matching CI leg), Debug build with-Dxrpld=ON -Dtests=ON -Dwerr=ON -Dverify_headers=ON -Drust=ON:Exit 0.
Also ran, on the same image:
pre-commit run clang-format --all-files: PASS, no file diffs after the run.run-clang-tidy -j18 -p . -quiet -allow-no-checks -extra-arg=-Wno-unknown-warning-option -extra-arg=-Wno-error -extra-arg=-Wno-deprecated-declarationson all 6 changed files: all 6 translation units completed, 0 Error-while-processing, 0 unique diagnostics viabin/filter-clang-tidy.py.python3 .github/scripts/levelization/generate.py: EXIT=0,.github/scripts/levelization/results/loops.txtandordering.txtbyte-identical to the worktree copies (no committed-result drift)..github/scripts/rename/(binary.sh,cmake.sh,config.sh,copyright.sh,definitions.sh,docs.sh,include.sh,namespace.sh): all EXIT=0;diff -r --briefof the rename output against the worktree returns zero source-file differences.git diff upstream/develop --shortstat:6 files changed, 19 insertions(+), 26 deletions(-).