Sponsored Content
Skip to content

refactor: Use isFlag where possible instead of bitwise math - #7278

Merged
bthomee merged 7 commits into
developfrom
mvadari/is-flag
May 15, 2026
Merged

refactor: Use isFlag where possible instead of bitwise math#7278
bthomee merged 7 commits into
developfrom
mvadari/is-flag

Conversation

@mvadari

@mvadari mvadari commented May 14, 2026

Copy link
Copy Markdown
Contributor

High Level Overview of Change

Title pretty much says it all. I did some additional refactors to remove flags variables where relevant. A few ternaries of the form !bool ? X : Y were also flipped (to bool ? Y : X).

No functionality changes, this is a pure refactor.

Context of Change

Bitwise math is harder to read/reason about

API Impact

N/A

Copilot AI review requested due to automatic review settings May 14, 2026 17:39
@mvadari mvadari added the Trivial Simple change with minimal effect, or already tested. Only needs one approval. label May 14, 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

A pure refactor that replaces verbose bitwise expressions on sfFlags (e.g., (sle->getFlags() & lsfX) != 0u) with the more readable sle->isFlag(lsfX) helper across transactors, ledger helpers, RPC handlers, and tests. No behavior changes.

Changes:

  • Substitutes (getFlags()/getFieldU32(sfFlags) & FLAG) patterns with isFlag(FLAG) throughout the codebase.
  • In RippleStateHelpers.cpp::updateTrustLine, factors out per-side flag selectors into named locals and replaces a setFieldU32(sfFlags, flags & ~mask) with clearFlag(mask).
  • Updates relevant tests to use isFlag for clarity.

Reviewed changes

Copilot reviewed 39 out of 39 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/xrpld/rpc/handlers/orderbook/DepositAuthorized.cpp Use isFlag for deposit/credential flag checks
src/xrpld/rpc/handlers/account/NoRippleCheck.cpp Use isFlag for default-ripple/no-ripple checks
src/xrpld/rpc/handlers/account/AccountLines.cpp Use isFlag for low/high reserve checks
src/xrpld/rpc/detail/PathRequest.cpp Use isFlag for lsfDisallowXRP
src/xrpld/rpc/detail/Pathfinder.cpp Use isFlag for noRipple/requireAuth checks
src/test/jtx/impl/flags.cpp Replace (flags & mask) == mask with isFlag(mask)
src/test/app/SetRegularKey_test.cpp Use isFlag(lsfPasswordSpent) in assertions
src/test/app/DepositAuth_test.cpp Use isFlag(lsfDepositAuth)
src/test/app/Credentials_test.cpp Use isFlag(lsfAccepted) in assertions
src/libxrpl/tx/transactors/vault/VaultSet.cpp Use isFlag(lsfMPTRequireAuth)
src/libxrpl/tx/transactors/vault/VaultCreate.cpp Use isFlag(tfVaultPrivate)
src/libxrpl/tx/transactors/token/TrustSet.cpp Use isFlag for require-auth/disallow-incoming/default-ripple
src/libxrpl/tx/transactors/token/MPTokenIssuanceCreate.cpp Use isFlag(tfMPTRequireAuth)
src/libxrpl/tx/transactors/token/MPTokenAuthorize.cpp Use isFlag(tfMPTUnauthorize)
src/libxrpl/tx/transactors/token/Clawback.cpp Use isFlag(lsfMPTCanClawback)
src/libxrpl/tx/transactors/system/Batch.cpp Use isFlag(tfInnerBatchTxn)
src/libxrpl/tx/transactors/payment/Payment.cpp Use isFlag for require-dest-tag/password-spent
src/libxrpl/tx/transactors/payment_channel/PaymentChannelClaim.cpp Use isFlag(tfRenew/tfClose)
src/libxrpl/tx/transactors/nft/NFTokenAcceptOffer.cpp Use isFlag(lsfSellNFToken)
src/libxrpl/tx/transactors/escrow/EscrowCreate.cpp Use isFlag(lsfRequireDestTag)
src/libxrpl/tx/transactors/dex/OfferCreate.cpp Use isFlag for auth checks
src/libxrpl/tx/transactors/dex/AMMDeposit.cpp Use isFlag for AMM deposit flags
src/libxrpl/tx/transactors/dex/AMMCreate.cpp Use isFlag(lsfDefaultRipple)
src/libxrpl/tx/transactors/credentials/CredentialAccept.cpp Use isFlag(lsfAccepted)
src/libxrpl/tx/transactors/check/CheckCash.cpp Use isFlag plus comment alignment update
src/libxrpl/tx/transactors/bridge/XChainBridge.cpp Use isFlag across multiple bridge flag checks
src/libxrpl/tx/transactors/account/SignerListSet.cpp Use isFlag(lsfOneOwnerCount)
src/libxrpl/tx/transactors/account/SetRegularKey.cpp Use isFlag(lsfPasswordSpent)
src/libxrpl/tx/transactors/account/AccountDelete.cpp Use isFlag for require-dest-tag/deposit-auth
src/libxrpl/tx/paths/DirectStep.cpp Use isFlag for require-auth/no-ripple
src/libxrpl/tx/paths/BookStep.cpp Use isFlag for no-ripple checks
src/libxrpl/tx/invariants/AMMInvariant.cpp Use isFlag(lsfAMMNode)
src/libxrpl/ledger/helpers/TokenHelpers.cpp Use isFlag(lsfDefaultRipple) for the SLE-side check
src/libxrpl/ledger/helpers/RippleStateHelpers.cpp Refactor to named flag selectors, isFlag/clearFlag
src/libxrpl/ledger/helpers/NFTokenHelpers.cpp Use isFlag for sell-NFT/disallow-incoming-offer
src/libxrpl/ledger/helpers/MPTokenHelpers.cpp Use isFlag(lsfMPTRequireAuth) in assert
src/libxrpl/ledger/helpers/CredentialHelpers.cpp Use isFlag for accepted/deposit-auth checks
include/xrpl/tx/paths/detail/StepChecks.h Use isFlag for no-ripple checks in checkNoRipple
include/xrpl/ledger/helpers/EscrowHelpers.h Use isFlag(lsfDefaultRipple) and reformat comments

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

@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 Opus 4.6 · Prompt: V15

@mvadari
mvadari requested review from Tapanito, bthomee and godexsoft May 14, 2026 17:42
@codecov

codecov Bot commented May 14, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.04878% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.1%. Comparing base (cce4cfe) to head (2d8e5c6).
⚠️ Report is 1 commits behind head on develop.

Files with missing lines Patch % Lines
src/xrpld/rpc/handlers/account/AccountLines.cpp 0.0% 2 Missing ⚠️
src/libxrpl/ledger/helpers/RippleStateHelpers.cpp 92.9% 1 Missing ⚠️
src/xrpld/rpc/detail/Pathfinder.cpp 50.0% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##           develop   #7278     +/-   ##
=========================================
- Coverage     82.1%   82.1%   -0.0%     
=========================================
  Files         1010    1010             
  Lines        76268   76224     -44     
  Branches      7445    7413     -32     
=========================================
- Hits         62608   62555     -53     
- Misses       13660   13669      +9     
Files with missing lines Coverage Δ
include/xrpl/ledger/helpers/EscrowHelpers.h 98.6% <100.0%> (ø)
include/xrpl/tx/paths/detail/StepChecks.h 100.0% <100.0%> (ø)
src/libxrpl/ledger/helpers/CredentialHelpers.cpp 98.2% <100.0%> (ø)
src/libxrpl/ledger/helpers/MPTokenHelpers.cpp 96.1% <ø> (ø)
src/libxrpl/ledger/helpers/NFTokenHelpers.cpp 90.4% <100.0%> (ø)
src/libxrpl/ledger/helpers/TokenHelpers.cpp 95.4% <100.0%> (+<0.1%) ⬆️
src/libxrpl/tx/invariants/AMMInvariant.cpp 95.2% <100.0%> (ø)
src/libxrpl/tx/invariants/InvariantCheck.cpp 95.7% <100.0%> (-<0.1%) ⬇️
src/libxrpl/tx/paths/BookStep.cpp 95.9% <100.0%> (ø)
src/libxrpl/tx/paths/DirectStep.cpp 84.9% <100.0%> (-<0.1%) ⬇️
... and 35 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.

Comment thread src/libxrpl/ledger/helpers/RippleStateHelpers.cpp Outdated
Comment thread src/libxrpl/ledger/helpers/TokenHelpers.cpp

@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 Opus 4.6 · Prompt: V15

Comment on lines 580 to 581
// FIXME This NEEDS to be cleaned up and simplified. It's impossible
// for anyone to understand.

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.

Maybe this comment can now be removed after the improvements made in this PR?

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.

I would say there's still room for improvement

Comment thread src/libxrpl/ledger/helpers/TokenHelpers.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.

No issues.

Review by Claude Opus 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 49 out of 49 changed files in this pull request and generated 7 comments.

Comments suppressed due to low confidence (3)

src/libxrpl/tx/transactors/token/MPTokenIssuanceSet.cpp:160

  • isFlag(tfMPTokenIssuanceSetMask) is true only if all mask bits are set, but the original (txFlags & tfMPTokenIssuanceSetMask) != 0u was true if any masked bit was set. This refactor changes the meaning of the permission check. Use (tx.getFlags() & tfMPTokenIssuanceSetMask) != 0u.
    src/libxrpl/tx/transactors/dex/AMMWithdraw.cpp:300
  • isFlag(tfLPToken | tfWithdrawAll) requires both bits to be set, but the original (ctx.tx.getFlags() & (tfLPToken | tfWithdrawAll)) != 0u was true if either was set. The two flags are mutually exclusive, so this branch will no longer execute, skipping the checkAmount validation. Use ctx.tx.isFlag(tfLPToken) || ctx.tx.isFlag(tfWithdrawAll).
    if (ctx.tx.isFlag(tfLPToken | tfWithdrawAll))

src/libxrpl/tx/transactors/dex/AMMWithdraw.cpp:1144

  • isFlag(tfWithdrawAll | tfOneAssetWithdrawAll) requires both bits to be set, while the original (tx[sfFlags] & (tfWithdrawAll | tfOneAssetWithdrawAll)) != 0u was true when either was set. Because these flags are mutually exclusive, isWithdrawAll will now always return WithdrawAll::No, which is a silent regression. Use tx.isFlag(tfWithdrawAll) || tx.isFlag(tfOneAssetWithdrawAll).
    if (tx.isFlag(tfWithdrawAll | tfOneAssetWithdrawAll))

Comment thread src/libxrpl/tx/transactors/token/TrustSet.cpp Outdated
Comment thread src/libxrpl/tx/transactors/token/TrustSet.cpp Outdated
Comment thread src/libxrpl/tx/transactors/token/MPTokenIssuanceSet.cpp Outdated
Comment thread src/libxrpl/tx/transactors/account/AccountSet.cpp Outdated
Comment thread src/libxrpl/tx/transactors/system/Batch.cpp Outdated
Comment thread src/libxrpl/tx/transactors/dex/AMMWithdraw.cpp Outdated
Comment thread src/libxrpl/tx/transactors/dex/OfferCreate.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.

Looks good.

Review by Claude Opus 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 Opus 4.6 · Prompt: V15

@mvadari
mvadari requested a review from bthomee May 14, 2026 21:17
@cyng140-netizen

cyng140-netizen commented May 15, 2026 via email

Copy link
Copy Markdown

@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 May 15, 2026
@bthomee
bthomee added this pull request to the merge queue May 15, 2026
Merged via the queue into develop with commit 028f0cb May 15, 2026
3 checks passed
@bthomee
bthomee deleted the mvadari/is-flag branch May 15, 2026 14:19
@mvadari mvadari added this to the 3.2.0 milestone May 20, 2026
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. Trivial Simple change with minimal effect, or already tested. Only needs one approval.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants