Skip to content

refactor: Add ReserveTxContext to ApplyViewContext#7661

Open
mvadari wants to merge 17 commits into
mvadari/sponsor/apply-view-contextfrom
mvadari/sponsor/reserve-context
Open

refactor: Add ReserveTxContext to ApplyViewContext#7661
mvadari wants to merge 17 commits into
mvadari/sponsor/apply-view-contextfrom
mvadari/sponsor/reserve-context

Conversation

@mvadari

@mvadari mvadari commented Jun 29, 2026

Copy link
Copy Markdown
Collaborator

High Level Overview of Change

Context of Change

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)

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

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

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

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

@mvadari mvadari marked this pull request as ready for review June 30, 2026 00:59
Comment thread src/libxrpl/ledger/helpers/NFTokenHelpers.cpp Outdated

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

Gave this a review

Owner-count correctness bug introduced by the refactor — see inline comment at line 274.


Review by ReviewBot 🤖

Review by Claude Sonnet 4.6 · Prompt: V15

adjustOwnerCount(view, owner, {}, 1, beast::Journal{beast::Journal::getNullSink()});
SLE::pointer const page = getPageForToken(
ctx, owner, nft[sfNFTokenID], [](ApplyViewContext& ctx, AccountID const& owner) {
adjustOwnerCount(ctx, 1, beast::Journal{beast::Journal::getNullSink()});

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.

Wrong account adjusted — ctx.reserveContext.accountID is the tx submitter, not the NFT recipient. Pass owner explicitly:

Suggested change
adjustOwnerCount(ctx, 1, beast::Journal{beast::Journal::getNullSink()});
adjustOwnerCount(ctx.view, owner, nullptr, 1, beast::Journal{beast::Journal::getNullSink()});

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

LGTM

Review by Claude Sonnet 4.6 · Prompt: V15

Comment thread src/libxrpl/ledger/helpers/NFTokenHelpers.cpp Outdated
Comment on lines +439 to +440
{
auto const accountID = ownerSle->getAccountID(sfAccount);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Severity: LOW

makeFromObject dereferences ownerSle without a null check, unlike makeFromAccount which explicitly throws on null. Multiple callers pass view.peek() results (e.g., OfferHelpers.cpp, CredentialHelpers.cpp) that can return null, risking a null-pointer dereference crash.
Helpful? Add 👍 / 👎

💡 Fix Suggestion

Suggestion: Add a null check for ownerSle before dereferencing it at line 440, consistent with the sibling makeFromAccount function which throws on null at line 422. Add if (!ownerSle) Throw<std::runtime_error>("ReserveContext::makeFromObject : valid owner sle"); before the dereference.

⚠️ Experimental Feature: This code suggestion is automatically generated. Please review carefully.

Suggested change
{
auto const accountID = ownerSle->getAccountID(sfAccount);
{
if (!ownerSle)
Throw<std::runtime_error>("ReserveContext::makeFromObject : valid owner sle");
auto const accountID = ownerSle->getAccountID(sfAccount);

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

Clean refactor. No issues.

Review by Claude Sonnet 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.

LGTM

Review by Claude Sonnet 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.

Looks good.

Review by Claude Sonnet 4.6 · Prompt: V15

@codecov

codecov Bot commented Jun 30, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.88889% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.2%. Comparing base (4cbc050) to head (8703d10).

Files with missing lines Patch % Lines
src/libxrpl/tx/paths/MPTEndpointStep.cpp 80.0% 2 Missing ⚠️
src/libxrpl/ledger/ApplyView.cpp 95.0% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@                        Coverage Diff                         @@
##           mvadari/sponsor/apply-view-context   #7661   +/-   ##
==================================================================
  Coverage                                82.1%   82.2%           
==================================================================
  Files                                    1016    1016           
  Lines                                   78233   78295   +62     
  Branches                                 9003    9007    +4     
==================================================================
+ Hits                                    64267   64330   +63     
+ Misses                                  13957   13956    -1     
  Partials                                    9       9           
Files with missing lines Coverage Δ
include/xrpl/ledger/ApplyView.h 97.6% <100.0%> (+0.4%) ⬆️
include/xrpl/ledger/helpers/AccountRootHelpers.h 100.0% <ø> (ø)
include/xrpl/ledger/helpers/EscrowHelpers.h 98.9% <100.0%> (-<0.1%) ⬇️
include/xrpl/ledger/helpers/NFTokenHelpers.h 100.0% <ø> (ø)
include/xrpl/ledger/helpers/SponsorHelpers.h 100.0% <ø> (+2.2%) ⬆️
include/xrpl/tx/ApplyContext.h 100.0% <100.0%> (ø)
src/libxrpl/ledger/View.cpp 96.8% <100.0%> (-<0.1%) ⬇️
src/libxrpl/ledger/helpers/AccountRootHelpers.cpp 88.4% <100.0%> (+0.4%) ⬆️
src/libxrpl/ledger/helpers/CredentialHelpers.cpp 98.3% <100.0%> (ø)
src/libxrpl/ledger/helpers/MPTokenHelpers.cpp 96.5% <100.0%> (+<0.1%) ⬆️
... and 41 more

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

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