refactor: Use ApplyViewContext everywhere instead of ApplyView+STTx#7618
refactor: Use ApplyViewContext everywhere instead of ApplyView+STTx#7618mvadari wants to merge 27 commits into
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ 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
🚀 New features to boost your workflow:
|
… mvadari/sponsor/apply-view-context
There was a problem hiding this comment.
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
ApplyViewContextand 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.txinstead 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.
|
Converting to Draft to avoid CI being run, this is still ready for review |
|
This PR has conflicts, please resolve them in order for the PR to be reviewed. |
| 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); |
There was a problem hiding this comment.
so this should be changed too, like getTxReserveSponsor
There was a problem hiding this comment.
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.
|
|
||
| struct ApplyViewContext | ||
| { | ||
| ApplyView& view; |
There was a problem hiding this comment.
you should disable copy constructors
There was a problem hiding this comment.
I tried this, it doesn't work because we're passing by value not reference so we are copying
There was a problem hiding this comment.
better to disable copy constructors and pass it by right reference, or forgotten copy can appear somewhere
This reverts commit 9485c3c.
… mvadari/sponsor/apply-view-context
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
txparameter is a bit messyFuture Tasks
Long term, once #7404 is merged, we can switch this to just use
ApplyContextdirectly. But to avoid that being a blocker for Sponsor, we're doing this instead temporarily.