Skip to content

perf: Deserialize received nodes once and only in job queue#7420

Open
bthomee wants to merge 11 commits into
developfrom
bthomee/jq
Open

perf: Deserialize received nodes once and only in job queue#7420
bthomee wants to merge 11 commits into
developfrom
bthomee/jq

Conversation

@bthomee

@bthomee bthomee commented Jun 6, 2026

Copy link
Copy Markdown
Collaborator

High Level Overview of Change

This change defers the deserialization of received nodes from the I/O thread to the job queue.

Context of Change

The changes here were originally developed as part of #6353, but it's better to pull them into a separate PR whose performance impact can then be evaluated individually.

Currently, received nodes in a TMGetLedger message are deserialized in the OnMessage handler, which runs in the I/O thread, purely as a sanity check before dispatching to the job queue. The nodes are then deserialized again after a thread picks up the task from the job queue. The proposed change will fully defer the deserialization and integrity checking to the job queue to free up to I/O thread and avoid double work.

One new addition is that the peer will now be charged a fee when sending more than Tuning::kSoftMaxReplyLimit nodes, which protects against a peer sending a request containing a very large number of node IDs. This limit was chosen because the existing code limits the number of nodes returned in the response to that amount* so there is little point in even sending more nodes to be processed.

*) The kSoftMaxReplyLimit is a soft limit; since a requested node ID can return multiple nodes in the response (via the getNodeFat function, which returns the node itself and its children up to a certain depth), the total number of nodes returned may be larger than the soft limit. However, it is hard limited via kHardMaxReplyLimit.

Copilot AI review requested due to automatic review settings June 6, 2026 13:31

@xrplf-ai-reviewer xrplf-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.

Behavior regression flagged inline: malformed SHAMap node IDs no longer trigger immediate disconnect, allowing fee-accumulation abuse via job-queue slots.

Review by Claude Sonnet 4.6 · Prompt: V15

Comment thread src/xrpld/overlay/detail/PeerImp.cpp Outdated

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.

Pull request overview

This PR moves TMGetLedger SHAMap node-ID deserialization and integrity checking out of the I/O-thread onMessage handler and into the job-queue path, eliminating the prior “deserialize twice” behavior and reducing I/O-thread work during ledger-fetch traffic.

Changes:

  • Removed per-node SHAMapNodeID deserialization/validation from the I/O thread and deferred it into the JtLedgerReq job.
  • Updated processLedgerRequest to accept already-parsed std::vector<SHAMapNodeID> and use it when building TMLedgerData replies.
  • Minor internal refactors in node reply assembly (loop structure, variable naming, reserving capacity once).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/xrpld/overlay/detail/PeerImp.h Extends processLedgerRequest to accept a parsed std::vector<SHAMapNodeID> and adds required include.
src/xrpld/overlay/detail/PeerImp.cpp Defers node-id parsing to the job queue and adjusts processLedgerRequest to use the parsed node IDs.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/xrpld/overlay/detail/PeerImp.cpp
@bthomee bthomee added QE test desired RippleX QE Team should consider looking at this PR. and removed QE test desired RippleX QE Team should consider looking at this PR. labels Jun 6, 2026
@codecov

codecov Bot commented Jun 6, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 33 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.3%. Comparing base (8e378c4) to head (be95c2c).

Files with missing lines Patch % Lines
src/xrpld/overlay/detail/PeerImp.cpp 0.0% 33 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##           develop   #7420     +/-   ##
=========================================
- Coverage     82.3%   82.3%   -0.0%     
=========================================
  Files         1024    1024             
  Lines        78456   78466     +10     
  Branches      8973    8980      +7     
=========================================
- Hits         64575   64566      -9     
- Misses       13872   13891     +19     
  Partials         9       9             
Files with missing lines Coverage Δ
src/xrpld/overlay/detail/PeerImp.h 12.1% <ø> (ø)
src/xrpld/overlay/detail/PeerImp.cpp 6.1% <0.0%> (-<0.1%) ⬇️

... and 5 files with indirect coverage changes

Impacted file tree graph

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@xrplf-ai-reviewer xrplf-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.

Enforcement regression flagged inline — malformed node IDs no longer disconnect the peer.

Review by Claude Sonnet 4.6 · Prompt: V15

Comment thread src/xrpld/overlay/detail/PeerImp.cpp Outdated

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.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comment thread src/xrpld/overlay/detail/PeerImp.cpp

@xrplf-ai-reviewer xrplf-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.

Review by Claude Sonnet 4.6 · Prompt: V15

@xrplf-ai-reviewer xrplf-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.

Review by Claude Sonnet 4.6 · Prompt: V15

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.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

Comment thread src/xrpld/overlay/detail/PeerImp.cpp Outdated
Comment thread src/xrpld/overlay/detail/PeerImp.cpp
Comment thread src/xrpld/overlay/detail/PeerImp.cpp Outdated

@xrplf-ai-reviewer xrplf-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.

Review by Claude Sonnet 4.6 · Prompt: V15

@bthomee bthomee requested review from vlntb and ximinez June 6, 2026 23:14
@bthomee

bthomee commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator Author

The performance evaluations can be found in https://gist.github.com/bthomee/3a0cb89a9709dc00b3f3e3bc0c329736. I included an AI generated summary of the findings.

@bthomee bthomee added this to the 3.3.0 milestone Jun 15, 2026
@github-actions

Copy link
Copy Markdown

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

@github-actions

Copy link
Copy Markdown

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

@xrplf-ai-reviewer xrplf-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.

Review by Claude Sonnet 4.6 · Prompt: V15

@bthomee

bthomee commented Jun 18, 2026

Copy link
Copy Markdown
Collaborator Author

@ximinez In this PR I removed the deserialization of received nodes from the code before the message is added to the job queue, since the deserialization was also being done inside the job queue, and I assumed that it would be healthier for the node to check the validity of the message inside the job queue (since it has many threads consuming from it) as opposed to where the inbound messages are received (which may only use one thread or fewer).

However, if someone were to send a message containing many (intentionally) invalid nodes, would it be better to prevent such messages from being added to the job queue in the first place? I can rewrite the logic to only deserialize the nodes before inserting the message and those deserialized nodes into the jq.

@ximinez ximinez left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The changes are good. I suggested a couple of tweaks.

Comment thread src/xrpld/overlay/detail/PeerImp.cpp Outdated
Comment thread src/xrpld/overlay/detail/PeerImp.cpp Outdated
@bthomee bthomee requested a review from ximinez June 23, 2026 17:29

@xrplf-ai-reviewer xrplf-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.

Review by Claude Sonnet 4.6 · Prompt: V15

@bthomee bthomee modified the milestones: 3.3.0, 3.4.0 Jun 24, 2026
@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown

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

@github-actions

github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown

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

@xrplf-ai-reviewer xrplf-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.

One misleading log line flagged inline — m->nodeids_size() reports the raw wire count rather than the capped processed count, obscuring truncation.

Review by Claude Sonnet 4.6 · Prompt: V15

Comment thread src/xrpld/overlay/detail/PeerImp.cpp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

QE test desired RippleX QE Team should consider looking at this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants