Skip to content

refactor: Use ApplyViewContext everywhere instead of ApplyView+STTx#7618

Draft
mvadari wants to merge 10 commits into
xrplf/sponsorfrom
mvadari/sponsor/apply-view-context
Draft

refactor: Use ApplyViewContext everywhere instead of ApplyView+STTx#7618
mvadari wants to merge 10 commits into
xrplf/sponsorfrom
mvadari/sponsor/apply-view-context

Conversation

@mvadari

@mvadari mvadari commented Jun 24, 2026

Copy link
Copy Markdown
Collaborator

High Level Overview of Change

This PR adds a new tiny struct, ApplyViewContext, that's just ApplyView+STTx, that can be passed around more easily than ApplyView+STTx separately as parameters. It should be used in place of all ApplyView parameters in helpers.

Context of Change

Adding an extra tx parameter is a bit messy

Future Tasks

Long term, once #7404 is merged, we can switch this to just use ApplyContext directly. But to avoid that being a blocker for Sponsor, we're doing this instead temporarily.

@mvadari mvadari added the DraftRunCI Normally CI does not run on draft PRs. This opts in. label Jun 24, 2026
@codecov

codecov Bot commented Jun 25, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.29412% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.2%. Comparing base (6ecf413) to head (88ae2bb).
⚠️ Report is 6 commits behind head on xrplf/sponsor.

Files with missing lines Patch % Lines
src/libxrpl/tx/transactors/vault/VaultCreate.cpp 33.3% 2 Missing ⚠️
src/libxrpl/tx/transactors/vault/VaultWithdraw.cpp 0.0% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@               Coverage Diff               @@
##           xrplf/sponsor   #7618     +/-   ##
===============================================
- Coverage           82.2%   82.2%   -0.1%     
===============================================
  Files               1016    1016             
  Lines              78385   78214    -171     
  Branches            8994    9000      +6     
===============================================
- Hits               64462   64255    -207     
- Misses             13914   13950     +36     
  Partials               9       9             
Files with missing lines Coverage Δ
include/xrpl/ledger/ApplyView.h 97.1% <ø> (ø)
include/xrpl/ledger/View.h 100.0% <ø> (ø)
include/xrpl/ledger/helpers/RippleStateHelpers.h 100.0% <ø> (ø)
include/xrpl/tx/ApplyContext.h 100.0% <100.0%> (ø)
src/libxrpl/ledger/View.cpp 96.8% <100.0%> (+<0.1%) ⬆️
src/libxrpl/ledger/helpers/MPTokenHelpers.cpp 96.4% <100.0%> (ø)
src/libxrpl/ledger/helpers/RippleStateHelpers.cpp 92.9% <100.0%> (+<0.1%) ⬆️
src/libxrpl/ledger/helpers/TokenHelpers.cpp 95.3% <100.0%> (ø)
src/libxrpl/tx/ApplyContext.cpp 100.0% <100.0%> (ø)
...tx/transactors/lending/LoanBrokerCoverWithdraw.cpp 92.6% <100.0%> (+0.2%) ⬆️
... and 10 more

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

Comment thread include/xrpl/ledger/helpers/MPTokenHelpers.h
@mvadari mvadari marked this pull request as ready for review June 26, 2026 15:52
Copilot AI review requested due to automatic review settings June 26, 2026 15:52
@mvadari mvadari removed the DraftRunCI Normally CI does not run on draft PRs. This opts in. label Jun 26, 2026
@mvadari mvadari changed the title PoC: ApplyViewContext refactor: Use ApplyViewContext everywhere instead of ApplyView+STTx Jun 26, 2026

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

No issues.

Review by Claude Sonnet 4.6 · Prompt: V15

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

Refactors transaction application helpers and transactors to pass a unified ApplyViewContext (view + tx) instead of separate ApplyView and STTx parameters, aiming to simplify call sites and reduce parameter threading across the tx/ledger helper layer.

Changes:

  • Introduces ApplyViewContext and updates many helper APIs (doWithdraw, token/escrow/sponsor helpers, etc.) to take it.
  • Adds ApplyContext::getApplyViewContext() and updates many transactors to use it.
  • Updates internal implementations to read ctx.view / ctx.tx instead of separate parameters.

Reviewed changes

Copilot reviewed 38 out of 38 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/libxrpl/tx/transactors/vault/VaultWithdraw.cpp Switches helper calls to pass ctx_.getApplyViewContext() instead of (view(), ctx_.tx).
src/libxrpl/tx/transactors/vault/VaultDeposit.cpp Updates MPToken authorization/enforcement calls to use ApplyViewContext.
src/libxrpl/tx/transactors/vault/VaultDelete.cpp Updates holding removal calls to use ApplyViewContext.
src/libxrpl/tx/transactors/vault/VaultCreate.cpp Updates empty-holding creation and MPToken issuance/authorization to use ApplyViewContext.
src/libxrpl/tx/transactors/vault/VaultClawback.cpp Updates holding removal to use ApplyViewContext.
src/libxrpl/tx/transactors/token/TrustSet.cpp Uses getTxReserveSponsor(ctx_.getApplyViewContext()).
src/libxrpl/tx/transactors/token/MPTokenIssuanceCreate.cpp Changes create() signature to accept ApplyViewContext& and updates sponsor lookup.
src/libxrpl/tx/transactors/token/MPTokenAuthorize.cpp Updates authorizeMPToken call to use ApplyViewContext.
src/libxrpl/tx/transactors/Sponsor/SponsorshipSet.cpp Updates sponsor lookup to use ApplyViewContext.
src/libxrpl/tx/transactors/payment/DepositPreauth.cpp Updates sponsor lookup to use ApplyViewContext in reserve checks.
src/libxrpl/tx/transactors/payment_channel/PaymentChannelFund.cpp Updates sponsor lookup to use ApplyViewContext.
src/libxrpl/tx/transactors/payment_channel/PaymentChannelCreate.cpp Updates sponsor lookup to use ApplyViewContext.
src/libxrpl/tx/transactors/lending/LoanSet.cpp Updates addEmptyHolding calls to use ApplyViewContext.
src/libxrpl/tx/transactors/lending/LoanPay.cpp Updates addEmptyHolding calls to use ApplyViewContext.
src/libxrpl/tx/transactors/lending/LoanBrokerSet.cpp Updates addEmptyHolding calls to use ApplyViewContext.
src/libxrpl/tx/transactors/lending/LoanBrokerDelete.cpp Updates removeEmptyHolding call to use ApplyViewContext.
src/libxrpl/tx/transactors/lending/LoanBrokerCoverWithdraw.cpp Updates doWithdraw call to use ApplyViewContext.
src/libxrpl/tx/transactors/escrow/EscrowFinish.cpp Updates escrow unlock helper call to use ApplyViewContext.
src/libxrpl/tx/transactors/escrow/EscrowCreate.cpp Updates sponsor lookup to use ApplyViewContext.
src/libxrpl/tx/transactors/escrow/EscrowCancel.cpp Updates escrow unlock helper call to use ApplyViewContext.
src/libxrpl/tx/transactors/delegate/DelegateSet.cpp Updates sponsor lookup to use ApplyViewContext.
src/libxrpl/tx/transactors/check/CheckCreate.cpp Updates sponsor lookup to use ApplyViewContext.
src/libxrpl/tx/transactors/check/CheckCash.cpp Introduces a local ApplyViewContext for sponsor lookup.
src/libxrpl/tx/transactors/account/SignerListSet.cpp Updates sponsor lookup to use ApplyViewContext.
src/libxrpl/tx/ApplyContext.cpp Constructs/stores viewCtx_ and initializes view_ in the initializer list.
src/libxrpl/ledger/View.cpp Changes doWithdraw to accept ApplyViewContext& and routes through ctx.view/ctx.tx.
src/libxrpl/ledger/helpers/TokenHelpers.cpp Updates asset-dispatching helpers to accept ApplyViewContext&.
src/libxrpl/ledger/helpers/RippleStateHelpers.cpp Updates IOU trustline holding helpers to accept ApplyViewContext&.
src/libxrpl/ledger/helpers/MPTokenHelpers.cpp Updates MPToken holding/auth helpers to accept ApplyViewContext& and use ctx.tx.
include/xrpl/tx/transactors/token/MPTokenIssuanceCreate.h Public header signature change: create(ApplyViewContext&, ...).
include/xrpl/tx/ApplyContext.h Adds getApplyViewContext() and stores an ApplyViewContext member.
include/xrpl/ledger/View.h Public header signature change: doWithdraw(ApplyViewContext&, ...).
include/xrpl/ledger/helpers/TokenHelpers.h Public header signature changes for add/remove empty holdings.
include/xrpl/ledger/helpers/SponsorHelpers.h Public header signature change: getTxReserveSponsor(ApplyViewContext&).
include/xrpl/ledger/helpers/RippleStateHelpers.h Public header signature changes to accept ApplyViewContext&.
include/xrpl/ledger/helpers/MPTokenHelpers.h Public header signature changes to accept ApplyViewContext&.
include/xrpl/ledger/helpers/EscrowHelpers.h Public header template signature changes to accept ApplyViewContext&.
include/xrpl/ledger/ApplyView.h Introduces the ApplyViewContext struct type.

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

Comment thread src/libxrpl/tx/ApplyContext.cpp
Comment thread include/xrpl/tx/transactors/token/MPTokenIssuanceCreate.h

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

Review by Claude Sonnet 4.6 · Prompt: V15


auto const sponsorSle = getTxReserveSponsor(psb, ctx_.tx);
ApplyViewContext ctx(psb, ctx_.tx);
auto const sponsorSle = getTxReserveSponsor(ctx);

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.

getTxReserveSponsor( ApplyViewContext (psb, ctx_.tx));

// A temporary helper object that passes around ApplyContext info
// Only necessary (for now) because the ApplyContext can't be passed into helpers due to
// levelization
ApplyViewContext viewCtx_;

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.

It is not needed

inline ApplyViewContext
    getApplyViewContext()
    {
        XRPL_ASSERT(&viewCtx_.view == &view_, "Previous view discarded");
        return ApplyViewContext(view_, tx_);
    }

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.

@Tapanito wanted it to be passed by reference

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.

Additional object == synchronization burden. No one need it. You still can pass it as right reference (which is perfect for the object consists only from references)

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.

By synchronization do you mean from a development perspective? I wouldn't worry about that too much, in the next couple months at worst we're going to migrate ApplyViewContext to be ApplyContext (see the PR description).

Comment thread src/libxrpl/tx/ApplyContext.cpp Outdated
, flags_(flags)
, view_{std::in_place, &base_, flags_}
, parentBatchId_(parentBatchId)
, viewCtx_{*view_, tx}

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.

Not needed, see comment above

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

Review by Claude Sonnet 4.6 · Prompt: V15

@mvadari mvadari marked this pull request as draft June 26, 2026 20:44
@mvadari

mvadari commented Jun 26, 2026

Copy link
Copy Markdown
Collaborator Author

Converting to Draft to avoid CI being run, this is still ready for review

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.

4 participants