Sponsored Content
Skip to content

refactor: Use named constant for leaf item size (#39) - #7130

Merged
bthomee merged 3 commits into
developfrom
vlntb/shamap-leaf-node-size-check
May 13, 2026
Merged

refactor: Use named constant for leaf item size (#39)#7130
bthomee merged 3 commits into
developfrom
vlntb/shamap-leaf-node-size-check

Conversation

@vlntb

@vlntb vlntb commented May 12, 2026

Copy link
Copy Markdown
Contributor

High Level Overview of Change

Tightens input validation in SHAMap leaf-node construction and unifies short-node error messages across makeTransaction, makeTransactionWithMeta, and makeAccountState.

Context of Change

The SHAMapLeafNode constructor assumed a minimum payload size via XRPL_ASSERT, which is a no-op in release builds and leaves no guard against undersized input at the wire-parsing boundary. This PR:

  • Adds an explicit size check at each wire-parsing factory (makeTransaction, makeTransactionWithMeta, makeAccountState) so undersized payloads are rejected before leaf-node construction, in both debug and release builds.
  • Replaces the hardcoded 12 with a named constant (minSHAMapItemBytes) so the threshold is visible and consistent across the three entry points.
  • Normalizes the existing short-node error messages to include actual and expected sizes, so logs and debugging are uniform.

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)

## High Level Overview of Change

Tightens input validation in SHAMap leaf-node construction and unifies short-node error messages across makeTransaction, makeTransactionWithMeta, and makeAccountState.

## Context of Change

The SHAMapLeafNode constructor assumed a minimum payload size via XRPL_ASSERT, which is a no-op in release builds and leaves no guard against undersized input at the wire-parsing boundary. This PR:

- Adds an explicit size check at each wire-parsing factory (makeTransaction, makeTransactionWithMeta, makeAccountState) so undersized payloads are rejected before leaf-node construction, in both debug and release builds.
- Replaces the hardcoded 12 with a named constant (minSHAMapItemBytes) so the threshold is visible and consistent across the three entry points.
- Normalizes the existing short-node error messages to include actual and expected sizes, so logs and debugging are uniform.

<!--
Please include the context of a change.
If a bug fix, when was the bug introduced? What was the behavior?
If a new feature, why was this architecture chosen? What were the alternatives?
If a refactor, how is this better than the previous implementation?

If there is a spec or design document for this feature, please link it here.
-->

### API Impact

<!--
Please check [x] relevant options, delete irrelevant ones.

* If there is any impact to the public API methods (HTTP / WebSocket), please update https://github.com/xrplf/rippled/blob/develop/API-CHANGELOG.md
  * Update API-CHANGELOG.md and add the change directly in this PR by pushing to your PR branch.
* libxrpl: See https://github.com/XRPLF/rippled/blob/develop/docs/build/depend.md
* Peer Protocol: See https://xrpl.org/peer-protocol.html
-->

- [ ] 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)

<!--
## Before / After
If relevant, use this section for an English description of the change at a technical level.
If this change affects an API, examples should be included here.

For performance-impacting changes, please provide these details:
1. Is this a new feature, bug fix, or improvement to existing functionality?
2. What behavior/functionality does the change impact?
3. In what processing can the impact be measured? Be as specific as possible - e.g. RPC client call, payment transaction that involves LOB, AMM, caching, DB operations, etc.
4. Does this change affect concurrent processing - e.g. does it involve acquiring locks, multi-threaded processing, or async processing?
-->

<!--
## Test Plan
If helpful, please describe the tests that you ran to verify your changes and provide instructions so that others can reproduce.
This section may not be needed if your change includes thoroughly commented unit tests.
-->

<!--
## Future Tasks
For future tasks related to PR.
-->
@vlntb vlntb added this to the 3.1.3 (develop) milestone May 12, 2026

@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 Opus 4.6 · Prompt: V15

@vlntb vlntb self-assigned this May 12, 2026
@codecov

codecov Bot commented May 12, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 13.04348% with 20 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.1%. Comparing base (45b1f4d) to head (ff315bd).
⚠️ Report is 5 commits behind head on develop.

Files with missing lines Patch % Lines
src/libxrpl/shamap/SHAMapTreeNode.cpp 13.0% 20 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##           develop   #7130     +/-   ##
=========================================
- Coverage     82.1%   82.1%   -0.0%     
=========================================
  Files         1010    1010             
  Lines        76145   76164     +19     
  Branches      7376    7387     +11     
=========================================
+ Hits         62548   62551      +3     
- Misses       13597   13613     +16     
Files with missing lines Coverage Δ
include/xrpl/shamap/SHAMapTreeNode.h 92.9% <ø> (ø)
src/libxrpl/shamap/SHAMapLeafNode.cpp 85.7% <ø> (ø)
src/libxrpl/shamap/SHAMapTreeNode.cpp 66.3% <13.0%> (-13.7%) ⬇️

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.

No issues.

Review by Claude Opus 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 Opus 4.6 · Prompt: V15

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

@vlntb should the Throw statement be excluded from code coverage, or is the idea that they can be tested but we just haven't written the tests for those edge cases yet?

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

Left a minor comment

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

LGTM

@vlntb

vlntb commented May 13, 2026

Copy link
Copy Markdown
Contributor Author

@vlntb should the Throw statement be excluded from code coverage, or is the idea that they can be tested but we just haven't written the tests for those edge cases yet?

I added a task to improve unit-test coverage:
#7135

@vlntb vlntb 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 May 13, 2026
@bthomee
bthomee added this pull request to the merge queue May 13, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks May 13, 2026
@bthomee
bthomee added this pull request to the merge queue May 13, 2026
Merged via the queue into develop with commit 4ad94ae May 13, 2026
2 of 3 checks passed
@bthomee
bthomee deleted the vlntb/shamap-leaf-node-size-check branch May 13, 2026 14:36
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