Sponsored Content
Skip to content

refactor: Move ledger entry helper functions from View.h/View.cpp to dedicated helper files - #6453

Merged
bthomee merged 21 commits into
XRPLF:developfrom
mvadari:rearchitect-pre
Mar 23, 2026
Merged

refactor: Move ledger entry helper functions from View.h/View.cpp to dedicated helper files#6453
bthomee merged 21 commits into
XRPLF:developfrom
mvadari:rearchitect-pre

Conversation

@mvadari

@mvadari mvadari commented Mar 2, 2026

Copy link
Copy Markdown
Contributor

High Level Overview of Change

Reorganizes helper functions from View.h/View.cpp into dedicated files based on the ledger entry type they operate on. This is a preparatory step for the Typed Ledger Entry Views proposal.

There are no changes to functionality, only functions moved to new files.

New helper files created:

  • DirectoryHelpers.h/cpp - Directory iteration (dirFirst, dirNext, cdirFirst, cdirNext, forEachItem, etc.)
  • AccountRootHelpers.h/cpp - Account operations (xrpLiquid, adjustOwnerCount, transferRate, isPseudoAccount, etc.)
  • RippleStateHelpers.h/cpp - Trust line operations (isFrozen, trustCreate, trustDelete, issueIOU, redeemIOU, etc.)
  • MPTokenHelpers.h/cpp - MPToken operations (isFrozen, transferRate, authorizeMPToken, accountHolds, etc.)
  • OfferHelpers.h/cpp - Offer operations (offerDelete)
  • VaultHelpers.h/cpp - Vault calculations (assetsToSharesDeposit, sharesToAssetsWithdraw, etc.)
  • TokenHelpers.h/cpp - Asset-agnostic dispatchers that work with XRP/IOU/MPT via std::visit

Context of Change

View.h had grown to contain helper functions for many different ledger entry types, making it difficult to find and maintain ledger-entry-specific logic. This refactoring:

  1. Groups related functions by the ledger entry type they operate on
  2. Makes it easier to understand which functions affect which ledger entries
  3. Prepares the codebase for future typed ledger entry views
  4. Keeps multi-entry functions in View.h where they cross unrelated entry type boundaries

Type of Change

  • Refactor (non-breaking change that only restructures code)

API Impact

  • libxrpl change (any change that may affect libxrpl or dependents of libxrpl)

Before / After

Before: All ledger entry helper functions lived in View.h/View.cpp (~1500+ lines)

After: Functions organized by ledger entry type:

  • View.h/cpp - Core view classes + cross-cutting functions (~530 lines)
  • DirectoryHelpers.h/cpp - ltDIR_NODE
  • AccountRootHelpers.h/cpp - ltACCOUNT_ROOT
  • RippleStateHelpers.h/cpp - ltRIPPLE_STATE
  • MPTokenHelpers.h/cpp - ltMPTOKEN / ltMPTOKEN_ISSUANCE
  • OfferHelpers.h/cpp - ltOFFER
  • VaultHelpers.h/cpp - ltVAULT
  • TokenHelpers.h/cpp - Asset-agnostic (XRP/IOU/MPT) dispatchers

No functional changes - existing code continues to work through includes in View.h.

Test Plan

  • All existing unit tests pass (242 suites, 2993 cases, 20,436,724 tests, 0 failures)
  • No API changes - existing callers continue to work

Copilot AI review requested due to automatic review settings March 2, 2026 20:53

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 refactors ledger-entry helper logic out of View.h/View.cpp into dedicated helper headers/sources grouped by ledger entry type (AccountRoot, RippleState, MPToken, Offer, Directory, Vault, and token-agnostic dispatch), as groundwork for the “Typed Ledger Entry Views” proposal while keeping existing callers working via View.h includes.

Changes:

  • Split helper implementations into new *Helpers.h/.cpp files and updated View.h to include them.
  • Introduced token-agnostic dispatch layer (TokenHelpers.*) for XRP/IOU/MPT behavior via std::visit.
  • Deprecated Credit.* implementation files and redirected the API to RippleStateHelpers.* while keeping Credit.* as compatibility shims.

Reviewed changes

Copilot reviewed 18 out of 19 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/test/app/Vault_test.cpp Adds an include in vault unit tests (appears to be unused).
src/libxrpl/ledger/VaultHelpers.cpp New vault share/asset conversion helper implementations.
src/libxrpl/ledger/TokenHelpers.cpp New token-agnostic helper implementations (balance, freeze, transfers, dispatch).
src/libxrpl/ledger/RippleStateHelpers.cpp New trustline (IOU) helpers including credit/freeze/auth and trustline ops.
src/libxrpl/ledger/OfferHelpers.cpp New offer deletion helper implementation.
src/libxrpl/ledger/MPTokenHelpers.cpp New MPToken helpers (freeze/auth/escrow/transfer, etc.).
src/libxrpl/ledger/DirectoryHelpers.cpp New directory iteration and directory utility helper implementations.
src/libxrpl/ledger/Credit.cpp Deprecated shim translation unit retained for build compatibility.
src/libxrpl/ledger/AccountRootHelpers.cpp New account-root helpers (owner count, liquid XRP, pseudo-account utilities, etc.).
include/xrpl/tx/paths/detail/StrandFlow.h Adds View.h include to satisfy dependencies after header refactor.
include/xrpl/ledger/View.h Removes many helpers and replaces them with includes of the new helper headers.
include/xrpl/ledger/VaultHelpers.h Declares vault conversion helper APIs and supporting enum.
include/xrpl/ledger/TokenHelpers.h Declares token-agnostic dispatch helpers + shared enums used by callers.
include/xrpl/ledger/RippleStateHelpers.h Declares IOU/trustline helpers (credit, freeze, auth, trustline ops, etc.).
include/xrpl/ledger/OfferHelpers.h Declares offer deletion helper API.
include/xrpl/ledger/MPTokenHelpers.h Declares MPToken helper APIs (freeze/auth/escrow/transfer, etc.).
include/xrpl/ledger/DirectoryHelpers.h Declares directory iteration helpers and related utilities.
include/xrpl/ledger/Credit.h Deprecated shim header redirecting to RippleStateHelpers.h.
include/xrpl/ledger/AccountRootHelpers.h Declares account-root helper APIs (liquid XRP, owner count, pseudo-accounts, etc.).
Comments suppressed due to low confidence (4)

src/libxrpl/ledger/VaultHelpers.cpp:66

  • The assert message string uses assetsToSharesDeposit inside assetsToSharesWithdraw, which is misleading when diagnosing assertion failures. Update the message to reference assetsToSharesWithdraw.
    XRPL_ASSERT(!assets.negative(), "xrpl::assetsToSharesDeposit : non-negative assets");
    XRPL_ASSERT(
        assets.asset() == vault->at(sfAsset),

src/libxrpl/ledger/VaultHelpers.cpp:92

  • The assert message string uses sharesToAssetsDeposit inside sharesToAssetsWithdraw, which is misleading when diagnosing assertion failures. Update the message to reference sharesToAssetsWithdraw.
    XRPL_ASSERT(!shares.negative(), "xrpl::sharesToAssetsDeposit : non-negative shares");
    XRPL_ASSERT(
        shares.asset() == vault->at(sfShareMPTID),

src/libxrpl/ledger/TokenHelpers.cpp:1017

  • Typo in the XRPL_ASSERT_PARTS label string: "rippler::rippleSendMultiMPT" should be "xrpl::rippleSendMultiMPT" (or consistent with the surrounding function naming).
                XRPL_ASSERT_PARTS(
                    takeFromSender == beast::zero,
                    "rippler::rippleSendMultiMPT",
                    "sender == issuer, takeFromSender == zero");

include/xrpl/tx/paths/detail/StrandFlow.h:6

  • Including <xrpl/ledger/View.h> here significantly increases compile-time dependencies. This header appears to only need specific symbols (e.g. keylet / ReadView), so prefer including the narrowest headers that provide the required declarations instead of the full View interface.
#include <xrpl/basics/Log.h>
#include <xrpl/ledger/Credit.h>
#include <xrpl/ledger/View.h>
#include <xrpl/protocol/Feature.h>

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

Comment thread src/libxrpl/ledger/helpers/AccountRootHelpers.cpp
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings March 2, 2026 21:01

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

Copilot reviewed 18 out of 19 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (4)

src/libxrpl/ledger/VaultHelpers.cpp:67

  • In assetsToSharesWithdraw(), the XRPL_ASSERT message string still says "assetsToSharesDeposit". This makes debug assertions misleading; please update the message to reference assetsToSharesWithdraw().
    XRPL_ASSERT(!assets.negative(), "xrpl::assetsToSharesDeposit : non-negative assets");
    XRPL_ASSERT(
        assets.asset() == vault->at(sfAsset),
        "xrpl::assetsToSharesWithdraw : assets and vault match");

src/libxrpl/ledger/VaultHelpers.cpp:93

  • In sharesToAssetsWithdraw(), the XRPL_ASSERT message string still says "sharesToAssetsDeposit". Please update the assertion text so it matches the withdraw function for clearer diagnostics.
    XRPL_ASSERT(!shares.negative(), "xrpl::sharesToAssetsDeposit : non-negative shares");
    XRPL_ASSERT(
        shares.asset() == vault->at(sfShareMPTID),
        "xrpl::sharesToAssetsWithdraw : shares and vault match");

src/libxrpl/ledger/TokenHelpers.cpp:1017

  • XRPL_ASSERT_PARTS in rippleSendMultiMPT uses the string "rippler::rippleSendMultiMPT" (typo). This should likely be "xrpl::rippleSendMultiMPT" to match the namespace used elsewhere and avoid confusing assertion output.
                XRPL_ASSERT_PARTS(
                    takeFromSender == beast::zero,
                    "rippler::rippleSendMultiMPT",
                    "sender == issuer, takeFromSender == zero");

src/libxrpl/ledger/AccountRootHelpers.cpp:59

  • In confineOwnerCount(), the underflow branch logs a fatal message when id is set, but then asserts !id with the message "id is not set". This assertion/message pairing is confusing and makes it hard to interpret debug failures; consider making the assertion intent explicit (e.g., assert false with an "unexpected underflow" message when id is provided, or adjust the message/condition accordingly).
                JLOG(j.fatal()) << "Account " << *id << " owner count set below 0!";
            }
            adjusted = 0;
            XRPL_ASSERT(!id, "xrpl::confineOwnerCount : id is not set");
        }

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

Copilot AI review requested due to automatic review settings March 2, 2026 21:16

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

Copilot reviewed 18 out of 19 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (4)

src/libxrpl/ledger/TokenHelpers.cpp:1018

  • The XRPL_ASSERT_PARTS tag string has a typo (rippler::rippleSendMultiMPT). This should match the surrounding namespace/function naming (xrpl::rippleSendMultiMPT) to keep assertion diagnostics consistent and searchable.
                XRPL_ASSERT_PARTS(
                    takeFromSender == beast::zero,
                    "rippler::rippleSendMultiMPT",
                    "sender == issuer, takeFromSender == zero");
                auto const sendAmount = amount.mpt().value();

include/xrpl/tx/paths/detail/StrandFlow.h:6

  • <xrpl/ledger/View.h> appears to be unused in this header (no symbols from View.h are referenced directly here), and it is a particularly heavyweight include. Consider removing it, or replacing it with the narrowest header(s) that provide the needed declarations if something is indirectly relying on it.
#include <xrpl/ledger/Credit.h>
#include <xrpl/ledger/View.h>
#include <xrpl/protocol/Feature.h>

src/libxrpl/ledger/VaultHelpers.cpp:66

  • The XRPL_ASSERT message string references assetsToSharesDeposit, but this function is assetsToSharesWithdraw. This makes assertion failures harder to diagnose and can mislead debugging; update the assertion text to match the function name.
    XRPL_ASSERT(!assets.negative(), "xrpl::assetsToSharesDeposit : non-negative assets");
    XRPL_ASSERT(
        assets.asset() == vault->at(sfAsset),

src/libxrpl/ledger/VaultHelpers.cpp:93

  • The XRPL_ASSERT message string references sharesToAssetsDeposit, but this function is sharesToAssetsWithdraw. Updating the assertion text will make failures easier to interpret.
    XRPL_ASSERT(!shares.negative(), "xrpl::sharesToAssetsDeposit : non-negative shares");
    XRPL_ASSERT(
        shares.asset() == vault->at(sfShareMPTID),
        "xrpl::sharesToAssetsWithdraw : shares and vault match");

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

@codecov

codecov Bot commented Mar 2, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.31138% with 76 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.4%. Comparing base (c463d0f) to head (7b29d93).
⚠️ Report is 1 commits behind head on develop.

Files with missing lines Patch % Lines
src/libxrpl/ledger/helpers/TokenHelpers.cpp 93.5% 33 Missing ⚠️
src/libxrpl/ledger/helpers/RippleStateHelpers.cpp 92.4% 22 Missing ⚠️
src/libxrpl/ledger/helpers/MPTokenHelpers.cpp 96.2% 10 Missing ⚠️
src/libxrpl/ledger/helpers/AccountRootHelpers.cpp 95.1% 5 Missing ⚠️
src/libxrpl/ledger/helpers/DirectoryHelpers.cpp 95.5% 3 Missing ⚠️
include/xrpl/ledger/helpers/DirectoryHelpers.h 92.9% 2 Missing ⚠️
src/libxrpl/ledger/helpers/OfferHelpers.cpp 94.4% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##           develop   #6453     +/-   ##
=========================================
- Coverage     81.5%   81.4%   -0.0%     
=========================================
  Files          988     997      +9     
  Lines        74411   74416      +5     
  Branches      7579    7557     -22     
=========================================
+ Hits         60608   60609      +1     
- Misses       13803   13807      +4     
Files with missing lines Coverage Δ
include/xrpl/ledger/View.h 100.0% <ø> (ø)
include/xrpl/ledger/helpers/AccountRootHelpers.h 100.0% <100.0%> (ø)
include/xrpl/ledger/helpers/RippleStateHelpers.h 100.0% <100.0%> (ø)
include/xrpl/tx/paths/detail/StrandFlow.h 92.4% <ø> (ø)
src/libxrpl/ledger/View.cpp 96.1% <ø> (+1.7%) ⬆️
src/libxrpl/ledger/helpers/CredentialHelpers.cpp 97.6% <ø> (ø)
src/libxrpl/ledger/helpers/VaultHelpers.cpp 100.0% <100.0%> (ø)
src/libxrpl/tx/Transactor.cpp 93.2% <ø> (ø)
...xrpl/tx/invariants/PermissionedDomainInvariant.cpp 100.0% <ø> (ø)
src/libxrpl/tx/paths/Flow.cpp 94.3% <ø> (ø)
... and 24 more

... and 1 file 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.

Comment thread src/libxrpl/ledger/VaultHelpers.cpp Outdated
Comment thread src/libxrpl/ledger/helpers/VaultHelpers.cpp
Comment thread include/xrpl/ledger/VaultHelpers.h Outdated
Comment thread src/libxrpl/ledger/helpers/AccountRootHelpers.cpp
Comment thread src/libxrpl/ledger/helpers/OfferHelpers.cpp
Comment thread include/xrpl/ledger/helpers/TokenHelpers.h
Comment thread include/xrpl/ledger/helpers/RippleStateHelpers.h
Comment thread include/xrpl/ledger/helpers/OfferHelpers.h
Comment thread src/libxrpl/ledger/helpers/DirectoryHelpers.cpp
Comment thread include/xrpl/ledger/View.h Outdated
@ximinez
ximinez removed their request for review March 4, 2026 21:50

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

This is a great change. LGTM.

@mvadari mvadari added the Needs additional review PR requires at least one more code review approval before it can be merged label Mar 17, 2026
@a1q123456

Copy link
Copy Markdown
Contributor

I think it'd be nice if we could create some jira tickets for the follow up work (i.e. use the auto generated class) to keep things on track

@a1q123456 a1q123456 mentioned this pull request Mar 20, 2026
7 tasks
@mvadari

mvadari commented Mar 20, 2026

Copy link
Copy Markdown
Contributor Author

I think it'd be nice if we could create some jira tickets for the follow up work (i.e. use the auto generated class) to keep things on track

Happy to, but I'd like to get this PR merged first so that I can open up the PRs that I have so far.

#include <xrpl/ledger/ApplyView.h>
#include <xrpl/ledger/CredentialHelpers.h>
#include <xrpl/ledger/View.h>
#include <xrpl/ledger/entries/CredentialHelpers.h>

@a1q123456 a1q123456 Mar 23, 2026

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.

Is ledger/entries the best name? We've got xrpl/protocol_autogen/ledger_entries, which people will confuse it with xrpl/ledger/entries.

I think ledger/operations, ledger/helpers, ledger/modifiers, or ledger/views are better

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

helpers is fine for now, but these will eventually morph into classes for each ledger entry, so we may want to revisit naming then.

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.

Yeah maybe in the future, we can use ledger/modifiers or something, but that’s for future

@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 Mar 23, 2026

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

let's move the header files as well

@a1q123456
a1q123456 self-requested a review March 23, 2026 15:12

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

@bthomee
bthomee enabled auto-merge March 23, 2026 15:27
@bthomee
bthomee added this pull request to the merge queue Mar 23, 2026
Merged via the queue into XRPLF:develop with commit e0dbe90 Mar 23, 2026
3 checks passed
Tapanito pushed a commit that referenced this pull request Mar 24, 2026
…dedicated helper files (#6453)

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@mvadari mvadari added this to the 3.2.0 milestone May 20, 2026
beartec-jpg pushed a commit to beartec-jpg/FalconLedger that referenced this pull request Jun 1, 2026
…dedicated helper files (XRPLF#6453)

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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.

6 participants