Sponsored Content
Skip to content

refactor: Clean up getFeePayer, mSourceBalance, and mPriorBalance - #6478

Merged
bthomee merged 18 commits into
XRPLF:developfrom
mvadari:get-fee-payer
Mar 17, 2026
Merged

refactor: Clean up getFeePayer, mSourceBalance, and mPriorBalance#6478
bthomee merged 18 commits into
XRPLF:developfrom
mvadari:get-fee-payer

Conversation

@mvadari

@mvadari mvadari commented Mar 4, 2026

Copy link
Copy Markdown
Contributor

High Level Overview of Change

This PR:

  • Introduces a new helper function on STTx, getFeePayer
  • Removes the usage of mSourceBalance (and replaces it with SLE balance lookups)
  • Renames mPriorBalance to preFeeBalance_

This simplifies some of the code in the transactors and makes it a lot more readable.

Context of Change

Simplifies Permission Delegation code (and will simplify #5887 a bit too). General improvement of the codebase.

Type of Change

  • Refactor (non-breaking change that only restructures code)

API Impact

N/A

Test Plan

CI passes.

This comment was marked as resolved.

Comment thread src/libxrpl/protocol/STTx.cpp
Comment thread src/libxrpl/tx/Transactor.cpp Outdated
@codecov

codecov Bot commented Mar 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.9%. Comparing base (5ae97fa) to head (25b2bc0).
⚠️ Report is 1 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##           develop   #6478   +/-   ##
=======================================
  Coverage     79.8%   79.9%           
=======================================
  Files          878     878           
  Lines        67894   67893    -1     
  Branches      7551    7547    -4     
=======================================
+ Hits         54211   54217    +6     
+ Misses       13683   13676    -7     
Files with missing lines Coverage Δ
include/xrpl/protocol/STTx.h 100.0% <ø> (ø)
include/xrpl/tx/Transactor.h 100.0% <ø> (ø)
src/libxrpl/protocol/STTx.cpp 88.8% <100.0%> (+0.1%) ⬆️
src/libxrpl/tx/Transactor.cpp 93.2% <100.0%> (-0.1%) ⬇️
...c/libxrpl/tx/transactors/account/DeleteAccount.cpp 96.4% <100.0%> (+<0.1%) ⬆️
...c/libxrpl/tx/transactors/account/SetSignerList.cpp 91.9% <100.0%> (ø)
src/libxrpl/tx/transactors/bridge/XChainBridge.cpp 91.2% <100.0%> (+<0.1%) ⬆️
src/libxrpl/tx/transactors/check/CashCheck.cpp 92.5% <100.0%> (ø)
src/libxrpl/tx/transactors/check/CreateCheck.cpp 100.0% <100.0%> (ø)
...pl/tx/transactors/credentials/CredentialAccept.cpp 100.0% <100.0%> (ø)
... and 23 more

... and 3 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 src/libxrpl/tx/Transactor.cpp Outdated
{
auto const idAccount = ctx.tx.isFieldPresent(sfDelegate) ? ctx.tx.getAccountID(sfDelegate)
: ctx.tx.getAccountID(sfAccount);
auto const idAccount = ctx.tx.getFeePayer();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The fee payer and the authorized signer don't necessarily mean the same thing, so don't you think we should avoid using a helper function here?

With the Sponsor feature, there are cases where the fee payer is not the same as the signature provider.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fair - I may have been a bit overzealous about ctrl-f-replace...

This came out of a conversation about how we can improve the architecture of xrpld transactors etc in order to have better guarantees about features like Delegate and Sponsor, btw - one of the options we came up with was more helper functions.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@mvadari

mvadari commented Mar 5, 2026

Copy link
Copy Markdown
Contributor Author

@yinyiqian1 @tequdev I was able to simplify the code (mainly payFee) even more by removing mSourceBalance and replacing it with a direct call to account_'s balance everywhere.
I also took the liberty of renaming mPriorBalance to preFeeBalance so it's clearer and isn't using the outdated Hungarian notation.

@mvadari mvadari changed the title refactor: add getFeePayer helper function refactor: clean up getFeePayer, mSourceBalance, and mPriorBalance Mar 5, 2026

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 30 out of 30 changed files in this pull request and generated 1 comment.


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

Comment on lines +389 to +394
// Deduct the fee, so it's not available during the transaction.
// Will only write the account back if the transaction succeeds.
sle->setFieldAmount(sfBalance, sle->getFieldAmount(sfBalance) - feePaid);
view().update(sle);

// VFALCO Should we call view().rawDestroyXRP() here as well?

Copilot AI Mar 5, 2026

Copy link

Choose a reason for hiding this comment

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

The comment says the fee deduction "will only write the account back if the transaction succeeds", but this code explicitly calls view().update(sle) immediately. That can be misleading for readers (and fees are generally charged on tec*/tef* results too). Consider rewording the comment to describe the actual semantics (fee deducted in the apply view and committed according to the transaction's applied result), or remove the claim about only writing on success.

Copilot uses AI. Check for mistakes.

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 30 out of 30 changed files in this pull request and generated 1 comment.


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

Comment thread include/xrpl/tx/Transactor.h
@mvadari mvadari changed the title refactor: clean up getFeePayer, mSourceBalance, and mPriorBalance refactor: Clean up getFeePayer, mSourceBalance, and mPriorBalance Mar 10, 2026

@yinyiqian1 yinyiqian1 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 to me.
Just a minor comment regarding the naming of the member in the Transactor class — preFeeBalance_ would be more consistent.

#6478 (comment)

@yinyiqian1
yinyiqian1 requested a review from shawnxie999 March 12, 2026 17:32
@mvadari mvadari added the Ready to merge *PR author* thinks it's ready to merge. Has passed code review. Perf sign-off may still be required. label Mar 12, 2026
@bthomee
bthomee requested a review from kuznetsss March 12, 2026 21:37

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

@tequdev tequdev mentioned this pull request Mar 17, 2026
5 tasks
@bthomee
bthomee enabled auto-merge (squash) March 17, 2026 14:07
@bthomee
bthomee merged commit 252c676 into XRPLF:develop Mar 17, 2026
1 check passed
@mvadari
mvadari deleted the get-fee-payer branch March 21, 2026 02:21
@mvadari mvadari added this to the 3.2.0 milestone May 20, 2026
beartec-jpg pushed a commit to beartec-jpg/FalconLedger that referenced this pull request Jun 1, 2026
…e` (XRPLF#6478)

This change:
* Introduces a new helper function on `STTx`, `getFeePayer`.
* Removes the usage of `mSourceBalance` and replaces it with SLE balance lookups.
* Renames `mPriorBalance` to `preFeeBalance_`

This simplifies some of the code in the transactors and makes it a lot more readable.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Ready to merge *PR author* thinks it's ready to merge. Has passed code review. Perf sign-off may still be required.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants