Skip to content

refactor: Add SHAMapNodeID::isPrefixOf - #7939

Open
bthomee wants to merge 1 commit into
bthomee/shamap-stack-01-unsigned-int-branch-opsfrom
bthomee/shamap-stack-02-shamapnodeid-isprefixof
Open

refactor: Add SHAMapNodeID::isPrefixOf#7939
bthomee wants to merge 1 commit into
bthomee/shamap-stack-01-unsigned-int-branch-opsfrom
bthomee/shamap-stack-02-shamapnodeid-isprefixof

Conversation

@bthomee

@bthomee bthomee commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator

Part 2/8 of a stack. Base: part 1 (bthomee/shamap-stack-01-unsigned-int-branch-ops).

A node at depth d names the tree path spelled by the first d nibbles of its
key, so any leaf beneath it must agree on that prefix. Three call sites
open-coded this check against depthMask, and a fourth rebuilt a whole node
ID with createID just to compare it back.

No behavior change: each converted site tests the same condition it did
before.

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 introduces a small helper API on SHAMapNodeIDisPrefixOf(uint256 const&)—to centralize the “node ID matches the prefix implied by depth” check, and refactors existing call sites to use it instead of open-coding depthMask comparisons or rebuilding IDs via createID.

Changes:

  • Add SHAMapNodeID::isPrefixOf(uint256 const&) to test whether a leaf key shares this node’s depth-prefix.
  • Replace open-coded prefix/ID consistency checks with isPrefixOf in ledger node deserialization and SHAMap sync logic.
  • Reuse the helper internally to simplify invariant checks in SHAMapNodeID construction and child derivation.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
src/xrpld/app/ledger/detail/LedgerNodeHelpers.cpp Uses isPrefixOf to validate legacy leaf node IDs against their leaf keys.
src/libxrpl/shamap/SHAMapSync.cpp Switches leaf-position assertion to XRPL_ASSERT_IF(..., nodeID.isPrefixOf(leafKey(...))).
src/libxrpl/shamap/SHAMapNodeID.cpp Implements isPrefixOf and reuses it for existing depth-mask invariant checks.
include/xrpl/shamap/SHAMapNodeID.h Declares and documents the new isPrefixOf public API.

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

@bthomee
bthomee force-pushed the bthomee/shamap-stack-01-unsigned-int-branch-ops branch from 080c08b to 72936bc Compare August 4, 2026 00:12
@bthomee
bthomee force-pushed the bthomee/shamap-stack-02-shamapnodeid-isprefixof branch from ef6fda7 to cc83dd3 Compare August 4, 2026 00:12
A node at depth d names the tree path spelled by the first d nibbles of its
key, so any leaf beneath it must agree on that prefix. Three call sites
open-coded this check against `depthMask`, and a fourth rebuilt a whole node
ID with `createID` just to compare it back.

No behavior change: each converted site tests the same condition it did
before.
@bthomee
bthomee force-pushed the bthomee/shamap-stack-01-unsigned-int-branch-ops branch from 72936bc to 561ca50 Compare August 4, 2026 00:49
@bthomee
bthomee force-pushed the bthomee/shamap-stack-02-shamapnodeid-isprefixof branch from cc83dd3 to bb0a62e Compare August 4, 2026 00:49
@bthomee
bthomee marked this pull request as ready for review August 4, 2026 13:06
@bthomee bthomee added the Trivial Simple change with minimal effect, or already tested. Only needs one approval. label Aug 4, 2026
@bthomee
bthomee requested review from godexsoft and vlntb August 4, 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, mechanical refactor extracting a shared isPrefixOf helper. Verified each of the four call sites: the new isPrefixOf(id_) / isPrefixOf(key) checks are algebraically equivalent to the mask comparisons and createID(...).getNodeID() == ... comparisons they replace, so the 'no behavior change' claim holds. No issues found in the added lines.

@codecov

codecov Bot commented Aug 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Trivial Simple change with minimal effect, or already tested. Only needs one approval.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants