Skip to content

refactor: Add Cluster::isMember, a membership query that copies nothing - #8221

Merged
bthomee merged 3 commits into
developfrom
bthomee/cluster-is-member
Sep 15, 2026
Merged

bthomee merged 3 commits into
developfrom
bthomee/cluster-is-member

Conversation

@bthomee

@bthomee bthomee commented Sep 13, 2026

Copy link
Copy Markdown
Collaborator

High Level Overview of Change

Adds Cluster::isMember(PublicKey const&) const, a bool-returning membership query, and switches the
two production call sites that only test cluster membership for engagement - PeerImp::cluster() and
OverlayImpl::onHandoff - from Cluster::member to it.

Context of Change

Cluster::member returns std::optional<std::string>, copying the node's configured comment out from
under mutex_ on every call. PeerImp::cluster() has 9 call sites in PeerImp.cpp, several of them on
the per-message path (transaction, validation, and proposal relay), and both it and
OverlayImpl::onHandoff discard the string immediately after testing it for bool.

isMember replaces that with nodes_.contains(identity), no string copy, under the same lock. The two
callers that actually want the name - PeerImp's connection banner and ConnectAttempt's - are left on
member.

Covered by a new case in the existing cluster suite (src/test/overlay/cluster_test.cpp) asserting
isMember agrees with member across a mixed cluster/non-cluster population of public keys.

API Impact

  • Public API: New feature (new methods and/or new fields)
  • Public API: Breaking change (in general, breaking changes should only impact the next api_version)
  • libxrpl change (any change that may affect libxrpl or dependents of libxrpl)
  • Peer protocol change (must be backward compatible or bump the peer protocol version)

Cluster::member returns std::optional<std::string>, copying the node's
configured name out from under the mutex. Two production callers only ever
test the result for engagement and throw the string away, and one of them is
PeerImp::cluster(), which ten call sites in PeerImp use - several of them per
message.

Adds a bool-returning isMember alongside member and uses it at those two
sites. The two callers that actually want the name, PeerImp's connection
banner and ConnectAttempt's, are left alone. Covered by a case in the
existing cluster suite asserting the two queries agree over a mixed
population.
Copilot AI lite review requested due to automatic review settings September 13, 2026 10:51

@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.

Clean, mechanical refactor: adds Cluster::isMember mirroring the existing member lookup under the same lock but without copying the name, and updates the two boolean-only call sites (PeerImp::cluster(), OverlayImpl::onHandoff) plus adds a test case verifying isMember agrees with member. Implementation and call-site changes are correct and consistent with the existing locking/lookup pattern; no correctness, security, or consistency issues found in the added lines.

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

No unresolved issues remain, and membership consistency is covered by tests.

Pull request overview

Adds a non-copying cluster membership query and updates membership-only callers to use it.

Changes:

  • Added Cluster::isMember.
  • Updated peer and overlay membership checks.
  • Added consistency test coverage.
File summaries
File Summary
src/xrpld/overlay/detail/PeerImp.cpp Uses the efficient membership query.
src/xrpld/overlay/detail/OverlayImpl.cpp Uses the query for handoff decisions.
src/xrpld/overlay/detail/Cluster.cpp Implements locked membership lookup.
src/xrpld/overlay/Cluster.h Declares and documents the new query.
src/test/overlay/cluster_test.cpp Verifies consistency with member.
Review details
  • Files reviewed: 5/5 changed files
  • Comments generated: 0
  • Review effort level: Lite

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

@codecov

codecov Bot commented Sep 13, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.00000% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/xrpld/overlay/detail/OverlayImpl.cpp 0.0% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@bthomee
bthomee requested review from Tapanito, godexsoft and mvadari and removed request for mvadari September 13, 2026 12:55

@Tapanito Tapanito 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 optimisation!

@godexsoft godexsoft 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.

Small request, otherwise good to go 👍

Comment thread src/test/overlay/cluster_test.cpp Outdated
Review feedback pointed out that the cluster/network sizes in the new
"isMember agrees with member" test case were unnamed magic numbers.
Pull them into overlapCount and clusterSize constants so the intent
of each value is clear.
@bthomee
bthomee force-pushed the bthomee/cluster-is-member branch from 54040e7 to 0dc2c44 Compare September 15, 2026 13:13
@bthomee
bthomee requested a review from godexsoft September 15, 2026 13:14

@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.

Clean, minimal refactor: adds Cluster::isMember(PublicKey const&) mirroring the existing member() locking pattern but avoiding the string copy, and correctly swaps the two boolean-only call sites (PeerImp::cluster, OverlayImpl::onHandoff) to use it while leaving the two callers that need the name (PeerImp's banner, ConnectAttempt) on member(). New test case validates isMember agrees with member() across a mixed cluster/non-cluster population. No correctness, security, or consistency issues found in the changed lines.

@XRPLF XRPLF deleted a comment from github-actions Bot Sep 15, 2026
@bthomee bthomee 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 Sep 15, 2026
@xrplf-bot
xrplf-bot requested a lite review from Copilot September 15, 2026 13:18

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

No unresolved issues were identified that would block approval.

Review details
  • Files reviewed: 5/5 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

The named constants added for the isMember test case use std::size_t,
but the file never included the header that provides it. That tripped
misc-include-cleaner in CI, which treats the warning as an error.

@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.

Clean, low-risk refactor: adds Cluster::isMember mirroring the existing member locking/lookup pattern, updates the two call sites that only needed a boolean, and adds a test asserting isMember agrees with member. No behavioral or correctness issues found in the changed lines — the new method reuses the same mutex and underlying nodes_ container semantics as member, and the call-site swaps are mechanical (static_cast<bool>(member(...))isMember(...)).

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

No unresolved issues were identified, and membership behavior is covered by tests.

Review details
  • Files reviewed: 5/5 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

@godexsoft godexsoft 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!

@bthomee
bthomee enabled auto-merge September 15, 2026 14:44
@bthomee
bthomee added this pull request to the merge queue Sep 15, 2026
Merged via the queue into develop with commit 551a19b Sep 15, 2026
70 of 71 checks passed
@bthomee
bthomee deleted the bthomee/cluster-is-member branch September 15, 2026 21:15
@bthomee bthomee added this to the 3.5.0 milestone Sep 17, 2026
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