Skip to content

major refactor of ledger_entry source code and tests#5237

Merged
ximinez merged 21 commits intoXRPLF:developfrom
mvadari:refactor-ledger-entry2
Aug 29, 2025
Merged

major refactor of ledger_entry source code and tests#5237
ximinez merged 21 commits intoXRPLF:developfrom
mvadari:refactor-ledger-entry2

Conversation

@mvadari
Copy link
Copy Markdown
Collaborator

@mvadari mvadari commented Jan 7, 2025

High Level Overview of Change

This PR is a major refactor of LedgerEntry.cpp. It adds a number of helper functions to make the code easier to maintain.

It also splits up the ledger and ledger_entry tests into different files, and cleans up the ledger_entry tests to make them easier to write and maintain.

This refactor also caught a few bugs in some of the other RPC processing, so those are fixed along the way.

Context of Change

The ledger_entry code wasn't very readable and was hard to extend whenever a new ledger type was created.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • Refactor (non-breaking change that only restructures code)

API Impact

There are some error code changes. They are made as minimal as possible. The test changes should make it clear what the error code changes are.

Notes for Reviewers

The code has been cleaned up into 4 commits. Reviewing will probably be easier if these commits are reviewed separately, as the overall diff for the tests is very difficult to follow.

  1. The ledger and ledger_entry tests are split up, and the ledger_entry tests are all moved to LedgerEntry_test.cpp. No actual code changes, just moving code around.
  2. The functions in LedgerEntry.cpp are sorted in alphabetical order by ledger entry name. No actual code changes, just moving code around.

Test Plan

Tests pass and have better coverage.

@codecov
Copy link
Copy Markdown

codecov bot commented Jan 7, 2025

Codecov Report

❌ Patch coverage is 86.09756% with 57 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.7%. Comparing base (e4fdf33) to head (308b0bb).
⚠️ Report is 1 commits behind head on develop.

Files with missing lines Patch % Lines
src/xrpld/rpc/handlers/LedgerEntry.cpp 84.6% 44 Missing ⚠️
src/xrpld/rpc/handlers/LedgerEntryHelpers.h 88.9% 12 Missing ⚠️
src/xrpld/rpc/detail/RPCHelpers.cpp 83.3% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##           develop   #5237   +/-   ##
=======================================
  Coverage     78.6%   78.7%           
=======================================
  Files          815     816    +1     
  Lines        71778   71748   -30     
  Branches      8465    8473    +8     
=======================================
- Hits         56453   56447    -6     
+ Misses       15325   15301   -24     
Files with missing lines Coverage Δ
include/xrpl/protocol/ErrorCodes.h 100.0% <ø> (ø)
src/libxrpl/json/json_value.cpp 93.7% <100.0%> (-0.3%) ⬇️
src/libxrpl/protocol/ErrorCodes.cpp 85.7% <ø> (ø)
src/libxrpl/protocol/STXChainBridge.cpp 71.4% <100.0%> (ø)
src/xrpld/rpc/detail/RPCHelpers.cpp 82.6% <83.3%> (-0.1%) ⬇️
src/xrpld/rpc/handlers/LedgerEntryHelpers.h 88.9% <88.9%> (ø)
src/xrpld/rpc/handlers/LedgerEntry.cpp 80.4% <84.6%> (+1.9%) ⬆️

... and 8 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.

@mvadari mvadari force-pushed the refactor-ledger-entry2 branch 10 times, most recently from 6008f56 to ee2b76f Compare January 14, 2025 20:21
(other == uintValue && value_.real_ >= 0 &&
value_.real_ <= maxUInt) ||
value_.real_ <= maxUInt &&
static_cast<int>(value_.real_) == value_.real_) ||
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.

You should avoid using == with float point. Consider something like std::fabs(round(value_.real_) - value_.real_) < 1e-10

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.

We should use std::numeric_limits<double>::epsilon() instead of 1e-10

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.

Should we cast it to Json::UInt?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in c6450eb

}

auto const index = indexValue.asString();
if (indexValue.isConvertibleTo(Json::stringValue))
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.

Do we support both forms index: 3 and index: "3" ?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I believe so

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

More accurately, I think we should.

std::uint32_t iVal;
if (beast::lexicalCastChecked(iVal, index))
return getLedger(ledger, iVal, context);
std::uint32_t iVal;
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.

Please avoid Hungarian

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This line wasn't touched by me, I don't see the point in increasing the diff to change a minor variable name

@mvadari mvadari force-pushed the refactor-ledger-entry2 branch 3 times, most recently from 29c7ef9 to 72ed5e2 Compare February 20, 2025 01:51
@mvadari mvadari force-pushed the refactor-ledger-entry2 branch from 72ed5e2 to 91ff59b Compare February 28, 2025 21:08
@mvadari mvadari marked this pull request as ready for review February 28, 2025 21:31
@mvadari mvadari linked an issue Mar 5, 2025 that may be closed by this pull request
@mvadari mvadari force-pushed the refactor-ledger-entry2 branch 6 times, most recently from 3fb9479 to b1cf0ce Compare March 18, 2025 22:31
@mvadari mvadari force-pushed the refactor-ledger-entry2 branch from b1cf0ce to 99dd5a6 Compare March 24, 2025 22:10
@mvadari mvadari requested a review from Copilot March 26, 2025 22:35
@bthomee bthomee requested a review from a1q123456 August 15, 2025 15:08
@bthomee bthomee added Needs additional review PR requires at least one more code review approval before it can be merged and removed Blocked on requested changes Reviewers have requested changes which must be addressed or responded to labels Aug 22, 2025
ximinez added a commit that referenced this pull request Aug 22, 2025
ximinez added a commit that referenced this pull request Aug 25, 2025
}

if (hashValue)
if (not hashValue.isNull())
Copy link
Copy Markdown
Contributor

@a1q123456 a1q123456 Aug 27, 2025

Choose a reason for hiding this comment

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

Not sure if we use this style in rippled but I don't think it blocks anything.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I believe this was suggested by @godexsoft or @mathbunnyru - it seemed weird to me too

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.

Definitely suggested by @godexsoft :)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in 72a1dd8

@a1q123456
Copy link
Copy Markdown
Contributor

Generally looks good. I'll double check functions in LedgerEntry.cpp tomorrow.

ximinez added a commit that referenced this pull request Aug 27, 2025
ximinez added a commit that referenced this pull request Aug 28, 2025
ximinez added a commit that referenced this pull request Aug 29, 2025
Copy link
Copy Markdown
Contributor

@a1q123456 a1q123456 left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@mvadari mvadari added Ready to merge *PR author* thinks it's ready to merge. Has passed code review. Perf sign-off may still be required. and removed Needs additional review PR requires at least one more code review approval before it can be merged labels Aug 29, 2025
@godexsoft godexsoft removed their request for review August 29, 2025 17:45
@godexsoft godexsoft dismissed their stale review August 29, 2025 17:47

Review comments were addressed

@ximinez ximinez merged commit e0b9812 into XRPLF:develop Aug 29, 2025
26 checks passed
@mvadari mvadari deleted the refactor-ledger-entry2 branch October 7, 2025 17:23
@mvadari mvadari linked an issue Oct 14, 2025 that may be closed by this pull request
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.

Add NFT Offer support to ledger_entry Do not allow multiple inputs in LedgerEntry API ledger_entry returns bad error when given invalid request

9 participants