Skip to content

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

Open
mvadari wants to merge 27 commits into
xrplf/sponsorfrom
mvadari/sponsor/apply-view-context
Open

refactor: Use ApplyViewContext everywhere instead of ApplyView+STTx#7618
mvadari wants to merge 27 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 94.84536% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.1%. Comparing base (494391b) to head (4cbc050).
⚠️ Report is 17 commits behind head on xrplf/sponsor.

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

Impacted file tree graph

@@               Coverage Diff               @@
##           xrplf/sponsor   #7618     +/-   ##
===============================================
- Coverage           82.2%   82.1%   -0.1%     
===============================================
  Files               1016    1016             
  Lines              78375   78233    -142     
  Branches            8996    9003      +7     
===============================================
- Hits               64438   64267    -171     
- Misses             13928   13957     +29     
  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/EscrowHelpers.h 98.9% <100.0%> (+<0.1%) ⬆️
include/xrpl/ledger/helpers/RippleStateHelpers.h 100.0% <ø> (ø)
include/xrpl/ledger/helpers/SponsorHelpers.h 97.8% <100.0%> (-0.1%) ⬇️
include/xrpl/tx/ApplyContext.h 100.0% <100.0%> (ø)
.../xrpl/tx/transactors/token/MPTokenIssuanceCreate.h 100.0% <ø> (ø)
src/libxrpl/ledger/View.cpp 96.8% <100.0%> (+0.1%) ⬆️
src/libxrpl/ledger/helpers/MPTokenHelpers.cpp 96.5% <100.0%> (+0.1%) ⬆️
src/libxrpl/ledger/helpers/RippleStateHelpers.cpp 92.9% <100.0%> (+<0.1%) ⬆️
... and 25 more

... and 13 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 Outdated
Comment thread include/xrpl/tx/transactors/token/MPTokenIssuanceCreate.h 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.

Clean refactor. LGTM.

Review by Claude Sonnet 4.6 · Prompt: V15

Comment thread src/libxrpl/tx/transactors/check/CheckCash.cpp Outdated
Comment thread include/xrpl/tx/ApplyContext.h Outdated
Comment thread src/libxrpl/tx/ApplyContext.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.

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

@github-actions

Copy link
Copy Markdown

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

@mvadari mvadari marked this pull request as ready for review June 29, 2026 15:44

@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

Copilot reviewed 37 out of 37 changed files in this pull request and generated 3 comments.

Comment thread include/xrpl/ledger/ApplyView.h
Comment thread include/xrpl/ledger/helpers/SponsorHelpers.h
Comment thread include/xrpl/ledger/helpers/TokenHelpers.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.

No issues.

Review by Claude Sonnet 4.6 · Prompt: V15

if (auto const ret =
checkInsufficientReserve(view, tx, sleDest, xrpBalance, *sponsorSle, 1, 0, journal);
if (auto const ret = checkInsufficientReserve(
view, ctx.tx, sleDest, xrpBalance, *sponsorSle, 1, 0, journal);

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.

so this should be changed too, like getTxReserveSponsor

@mvadari mvadari Jun 29, 2026

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.

Yes, agreed. However, we can't do that in this PR - it currently takes a ReadView because it's called in preclaim in one place, so that needs to be fixed (in a separate PR) first.

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.

Will do after #7667, possibly in #7661


struct ApplyViewContext
{
ApplyView& view;

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.

you should disable copy constructors

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.

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.

I tried this, it doesn't work because we're passing by value not reference so we are copying

@oleks-rip oleks-rip Jun 29, 2026

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.

better to disable copy constructors and pass it by right reference, or forgotten copy can appear somewhere

@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 — nothing to flag.

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.

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.

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.

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.

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.

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.

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.

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.

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.

Clean refactor — no issues.

Review by Claude Sonnet 4.6 · Prompt: V15

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