Skip to content

refactor: Move accountReserve onto AccountRootEntry - #8379

Open
mvadari wants to merge 7 commits into
mvadari/rearch/typesafe2from
mvadari/rearch/accountroot-accountReserve
Open

mvadari wants to merge 7 commits into
mvadari/rearch/typesafe2from
mvadari/rearch/accountroot-accountReserve

Conversation

@mvadari

@mvadari mvadari commented Sep 30, 2026

Copy link
Copy Markdown
Contributor

High Level Overview of Change

Replaces the entry-taking accountReserve(view, sle, j, adj) free function with the const member AccountRootEntry::reserve(Adjustment adj = {}). The member uses the entry's own view and journal, so call sites now pass their journal to the entry constructor. The accountReserve(view, AccountID, j, adj) overload stays as a one-line shim. Adjustment moves to AccountRootEntry.h, and accountCountImpl moves to namespace detail because both reserve() and xrpLiquid() use it. The member body is in the new src/libxrpl/ledger/entries/AccountRootEntry.cpp.

Context of Change

Part of the Wrapped SLEs migration (design: step 2/3 of #7886). The reserve calculation now lives on the typed entry, so it cannot be called with an SLE of the wrong type or with a view that does not match the entry. Pure refactor: no amendment, no behavior change; any observable difference is a bug.

Stacked on #7916; review only the last commit. The branch also cherry-picks the MSVC C4661 test fix from #8357 (test: Declare, not define, entry instantiations in SLEBase test), because this PR adds out-of-line members with explicit instantiation.

This PR was fully written by AI (Claude Code) under human direction; the human author reviewed the diff.

API Impact

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

Test Plan

Syntax-checked (clang++ -fsyntax-only with project flags) every changed .cpp and every .cpp that includes AccountRootEntry.h or AccountRootHelpers.h (98/98 passed). clang-tidy clean on all changed files and headers; pre-commit clean. No new tests. CI runs the full unit test suite.

🤖 Generated with Claude Code

@ripple-ai-reviewer ripple-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.

This is a clean, mechanical refactor that moves accountReserve() onto AccountRootEntry as a const member, threading the entry's own view/journal through instead of passing them separately. I traced every call-site conversion (accountReserve(view, sle, j, adj) → sle.reserve(adj), and the added journal args to AccountRootEntryR/W constructors) across all ~20 changed transactor files and the helper/header moves (Adjustment struct, accountCountImpl → detail namespace), and the logic is preserved in each case — no dropped adjustments, no mismatched journals, no null-deref risk introduced (existing null checks on the entry are kept before .reserve() is called). The new AccountRootEntry.cpp body and the SLEBase.cpp instantiation-declaration change (for the MSVC C4661 fix) are consistent with the stated design and don't alter behavior. I did not find any correctness, security, or resource-management issues in the added (+) lines that I'm confident about.

@codecov

codecov Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@ripple-ai-reviewer ripple-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.

This is a clean, mechanical refactor consistent with its stated goal: the free function accountReserve(view, sle, j, adj) becomes the const member AccountRootEntry::reserve(adj), with Adjustment relocated to AccountRootEntry.h and accountCountImpl moved into namespace detail. I checked every call site that now uses .reserve(...) and confirmed the entry is always constructed with the same journal (and same view) that the old call passed explicitly, so there's no behavior change from a mismatched view/journal. The extern template class change in SLEBase.cpp and the new AccountRootEntry.cpp explicit-instantiation-definition pattern are internally consistent (explicit instantiation declarations still force instantiation of the class body/static members, which is all the exhaustiveness static_assert needs, while avoiding MSVC C4661 from a second definition). The new detail::escrowDestNotAccountResult guard in EscrowHelpers.h is a legitimate defensive addition for the pre-fixCleanup3_2_0 legacy path and matches its documented intent. I did not find any correctness, security, or resource issues in the changed lines.

@github-actions

Copy link
Copy Markdown

This PR has conflicts, please resolve them in order for the PR to be reviewed.

@mvadari
mvadari force-pushed the mvadari/rearch/accountroot-accountReserve branch from 90bb393 to c72bfa7 Compare September 30, 2026 17:58
@github-actions

Copy link
Copy Markdown

All conflicts have been resolved. Assigned reviewers can now start or resume their review.

@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown

This PR has conflicts, please resolve them in order for the PR to be reviewed.

@mvadari
mvadari force-pushed the mvadari/rearch/accountroot-accountReserve branch from c72bfa7 to 15280de Compare October 5, 2026 13:58
@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown

All conflicts have been resolved. Assigned reviewers can now start or resume their review.

@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown

All conflicts have been resolved. Assigned reviewers can now start or resume their review.

The exhaustive per-entry-type check in the SLEBase gtest used explicit
instantiation definitions. Once an entry class gets out-of-line member
bodies in its own .cpp (with the explicit instantiation definition
there), the test would instantiate the class a second time, and MSVC
rejects it with C4661 because those member bodies are not visible in
the test translation unit. Explicit instantiation declarations still
instantiate the class definition, which is all the check needs.

(cherry picked from commit 8b07abc)
Replace the entry-taking accountReserve(view, sle, j, adj) free function
with the const member AccountRootEntry::reserve(adj). The member uses the
entry's own view and journal, so call sites now pass their journal to the
entry constructor. The AccountID-based accountReserve overload stays as a
one-line shim.

Adjustment moves to AccountRootEntry.h, since the member takes it.
accountCountImpl moves from the anonymous namespace to namespace detail,
because both reserve() and xrpLiquid() use it.
An explicit instantiation declaration stops clang from emitting the
inline constructors of the header-only entries at -O0, so the debug
builds fail to link xrpl_tests (undefined AccountRootEntry constructors).
Naming each class in a static_assert already instantiates its definition,
which is all the exhaustiveness check needs.

(cherry picked from commit 611415e)
(cherry picked from commit 3cca9d3)
@mvadari
mvadari force-pushed the mvadari/rearch/accountroot-accountReserve branch from 15280de to 269f79e Compare October 5, 2026 14:51

@ripple-ai-reviewer ripple-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.

This is a clean, mechanical refactor moving accountReserve into AccountRootEntry::reserve(). I traced every call site to verify the beast::Journal threaded into the new entry constructors matches the journal previously passed directly to accountReserve(), and all ~20 sites are consistent. The core reserve() logic in the new AccountRootEntry.cpp preserves the original branching (featureSponsor check, ownerCount/accountCountImpl paths) exactly. The only thing worth flagging is a stale debug-assert message left over from the free-function days.

…ot-accountReserve

# Conflicts:
#	src/libxrpl/tx/transactors/bridge/XChainBridge.cpp
#	src/libxrpl/tx/transactors/escrow/EscrowCreate.cpp
#	src/tests/libxrpl/ledger/SLEBase.cpp
@github-actions

Copy link
Copy Markdown

This PR has conflicts, please resolve them in order for the PR to be reviewed.

2 similar comments
@github-actions

Copy link
Copy Markdown

This PR has conflicts, please resolve them in order for the PR to be reviewed.

@github-actions

Copy link
Copy Markdown

This PR has conflicts, please resolve them in order for the PR to be reviewed.

@github-actions

Copy link
Copy Markdown

All conflicts have been resolved. Assigned reviewers can now start or resume their review.

This branch has not been deployed

No deployments
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.

1 participant