Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

major refactor of ledger_entry source code and tests #5237

Draft
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

mvadari
Copy link
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 3 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 source code changes.
  3. The test changes.

Test Plan

Tests pass and have better coverage.

Copy link

codecov bot commented Jan 7, 2025

Codecov Report

Attention: Patch coverage is 88.12352% with 50 lines in your changes missing coverage. Please review.

Project coverage is 78.1%. Comparing base (01fc8f2) to head (72ed5e2).
Report is 2 commits behind head on develop.

Files with missing lines Patch % Lines
src/xrpld/rpc/handlers/LedgerEntry.cpp 87.0% 38 Missing ⚠️
src/xrpld/rpc/handlers/LedgerEntryHelpers.h 88.8% 12 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##           develop   #5237     +/-   ##
=========================================
+ Coverage     77.9%   78.1%   +0.3%     
=========================================
  Files          791     791             
  Lines        68006   67658    -348     
  Branches      8352    8205    -147     
=========================================
- Hits         52962   52861    -101     
+ Misses       15044   14797    -247     
Files with missing lines Coverage Δ
include/xrpl/protocol/ErrorCodes.h 100.0% <ø> (ø)
src/libxrpl/json/json_value.cpp 93.2% <100.0%> (-0.7%) ⬇️
src/libxrpl/protocol/ErrorCodes.cpp 85.7% <ø> (ø)
src/libxrpl/protocol/STXChainBridge.cpp 71.4% <100.0%> (ø)
src/xrpld/rpc/detail/RPCHelpers.cpp 82.8% <100.0%> (+0.1%) ⬆️
src/xrpld/rpc/handlers/LedgerEntryHelpers.h 88.8% <88.8%> (ø)
src/xrpld/rpc/handlers/LedgerEntry.cpp 81.7% <87.0%> (+4.3%) ⬆️

... and 27 files with indirect coverage changes

Impacted file tree graph

@mvadari mvadari force-pushed the refactor-ledger-entry2 branch 10 times, most recently from 6008f56 to ee2b76f Compare January 14, 2025 20:21
@@ -672,7 +672,8 @@ Value::isConvertibleTo(ValueType other) const
(other == intValue && value_.real_ >= minInt &&
value_.real_ <= maxInt) ||
(other == uintValue && value_.real_ >= 0 &&
value_.real_ <= maxUInt) ||
value_.real_ <= maxUInt &&
static_cast<int>(value_.real_) == value_.real_) ||
Copy link
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

@@ -385,20 +385,23 @@ ledgerFromRequest(T& ledger, JsonContext& context)
return getLedger(ledger, ledgerHash, context);
}

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

std::uint32_t iVal;
if (beast::lexicalCastChecked(iVal, index))
return getLedger(ledger, iVal, context);
std::uint32_t iVal;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please avoid Hungarian

@@ -36,820 +37,591 @@

namespace ripple {

static STArray
parseAuthorizeCredentials(Json::Value const& jv)
static Expected<uint256, Json::Value>
Copy link
Collaborator

@oleks-rip oleks-rip Jan 22, 2025

Choose a reason for hiding this comment

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

The moving of the functions makes this change near impossible to review. Consider to make as few differences as possible. Could you please add the new functions to the end of the file and use forward declaration when you need them.

@mvadari mvadari force-pushed the refactor-ledger-entry2 branch from ee2b76f to d895d4a Compare February 13, 2025 22:35
@mvadari mvadari force-pushed the refactor-ledger-entry2 branch from d895d4a to 29c7ef9 Compare February 18, 2025 23:45
@mvadari mvadari force-pushed the refactor-ledger-entry2 branch from 29c7ef9 to 72ed5e2 Compare February 20, 2025 01:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants