Skip to content

refactor: Use SeqProxy instead of uint32 for all sequence-based keylets - #7890

Open
mvadari wants to merge 5 commits into
developfrom
mvadari/keylet-seq-proxy
Open

refactor: Use SeqProxy instead of uint32 for all sequence-based keylets#7890
mvadari wants to merge 5 commits into
developfrom
mvadari/keylet-seq-proxy

Conversation

@mvadari

@mvadari mvadari commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

High Level Overview of Change

This PR refactors any keylet function that uses a sequence to take a SeqProxy instead of a std::uint32_t, and all downstream changes.

Context of Change

Preventing bugs

API Impact

N/A

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

This PR refactors sequence-based keylet APIs to accept SeqProxy (instead of std::uint32_t) and updates RPC handlers, transactors, ledger helpers, and tests accordingly, aiming to reduce bugs caused by mixing account sequence numbers and ticket sequences.

Changes:

  • Update keylet computation functions (e.g., offer/check/escrow/payChannel/nftokenOffer/vault/loan/permissionedDomain) to take SeqProxy.
  • Update core transactors and RPC parsing paths to pass SeqProxy (including using STTx::getSeqProxy() where appropriate).
  • Update a wide set of unit/integration tests and helper utilities to construct and pass SeqProxy values.

Reviewed changes

Copilot reviewed 51 out of 51 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/xrpld/rpc/handlers/VaultInfo.cpp Wrap vault sequence parameter as SeqProxy when computing vault keylets.
src/xrpld/rpc/handlers/ledger/LedgerEntry.cpp Use SeqProxy for escrow/offer/loan/vault/permissioned-domain keylet parsing.
src/tests/libxrpl/tx/AccountSet.cpp Update ticket-sequence handling to use SeqProxy and extract .value() where builders still take integers.
src/test/rpc/Subscribe_test.cpp Update NFToken offer keylet derivations to use SeqProxy.
src/test/rpc/LedgerEntry_test.cpp Update check/NFToken offer/paychan/permissioned-domain keylet derivations to use SeqProxy.
src/test/rpc/AccountTx_test.cpp Update paychan/check keylet derivations to use SeqProxy.
src/test/rpc/AccountObjects_test.cpp Update check keylet derivation to use SeqProxy.
src/test/jtx/TestHelpers.h Add SeqProxy include and update getCheckIndex implementation to use SeqProxy.
src/test/jtx/impl/vault.cpp Update vault keylet derivation to use SeqProxy.
src/test/jtx/impl/TestHelpers.cpp Update pay-channel helper to construct a SeqProxy for keylet derivation.
src/test/jtx/impl/escrow.cpp Update escrow read keylet derivation to use SeqProxy.
src/test/app/Vault_test.cpp Update vault/loanBroker/loan keylet derivations to use SeqProxy.
src/test/app/Sponsor_test.cpp Update check/ticket/escrow/vault/loanBroker/loan keylet derivations to use SeqProxy.
src/test/app/PermissionedDomains_test.cpp Update permissioned-domain keylet derivations to use SeqProxy.
src/test/app/PermissionedDEX_test.cpp Update offer keylet derivations to use SeqProxy.
src/test/app/PayChan_test.cpp Update pay-channel keylet derivation to use SeqProxy.
src/test/app/Offer_test.cpp Update offer keylet derivations to use SeqProxy.
src/test/app/NFTokenDir_test.cpp Update NFToken offer keylet derivations to use SeqProxy.
src/test/app/NFTokenBurn_test.cpp Update NFToken offer keylet derivations to use SeqProxy.
src/test/app/NFTokenAuth_test.cpp Update NFToken offer keylet derivations to use SeqProxy.
src/test/app/NFToken_test.cpp Update NFToken offer/check keylet derivations to use SeqProxy.
src/test/app/MPToken_test.cpp Update check/escrow/vault keylet derivations to use SeqProxy.
src/test/app/LPTokenTransfer_test.cpp Update check/NFToken offer keylet derivations to use SeqProxy.
src/test/app/LoanBroker_test.cpp Update vault/loanBroker/loan keylet derivations to use SeqProxy.
src/test/app/Loan_test.cpp Update loanBroker/loan/vault keylet derivations to use SeqProxy.
src/test/app/Invariants_test.cpp Update offer/check/escrow/vault/permissioned-domain keylet derivations to use SeqProxy.
src/test/app/Freeze_test.cpp Update NFToken offer/check keylet derivations to use SeqProxy.
src/test/app/FlowMPT_test.cpp Update offer keylet derivation to use SeqProxy.
src/test/app/Flow_test.cpp Update offer keylet derivation to use SeqProxy.
src/test/app/FixNFTokenPageLinks_test.cpp Update NFToken offer keylet derivations to use SeqProxy.
src/test/app/EscrowToken_test.cpp Update escrow keylet derivations to use SeqProxy.
src/test/app/Escrow_test.cpp Update escrow keylet derivations to use SeqProxy.
src/test/app/Check_test.cpp Update check keylet derivation to use SeqProxy.
src/test/app/Batch_test.cpp Update check/loanBroker/loan keylet derivations to use SeqProxy.
src/test/app/AccountDelete_test.cpp Update offer/ticket/check/paychan keylet derivations to use SeqProxy.
src/libxrpl/tx/transactors/vault/VaultCreate.cpp Use getSeqProxy() for vault keylet derivation and store sequence numeric with .value().
src/libxrpl/tx/transactors/system/TicketCreate.cpp Update ticket keylet derivation to pass a SeqProxy.
src/libxrpl/tx/transactors/permissioned_domain/PermissionedDomainSet.cpp Wrap domain sequence as SeqProxy for keylet derivation.
src/libxrpl/tx/transactors/payment_channel/PaymentChannelCreate.cpp Use getSeqProxy() for paychan keylet derivation.
src/libxrpl/tx/transactors/lending/LoanSet.cpp Wrap loan sequence as SeqProxy for loan keylet derivation.
src/libxrpl/tx/transactors/lending/LoanBrokerSet.cpp Use getSeqProxy() for broker keylet derivation and store numeric with .value().
src/libxrpl/tx/transactors/escrow/EscrowFinish.cpp Wrap OfferSequence as SeqProxy for escrow keylet lookup.
src/libxrpl/tx/transactors/escrow/EscrowCreate.cpp Use getSeqProxy() for escrow keylet derivation.
src/libxrpl/tx/transactors/escrow/EscrowCancel.cpp Wrap OfferSequence as SeqProxy for escrow keylet lookup.
src/libxrpl/tx/transactors/dex/OfferCreate.cpp Use getSeqProxy() for offer sequence and .value() when storing numeric fields; wrap cancel sequence.
src/libxrpl/tx/transactors/dex/OfferCancel.cpp Wrap offer sequence as SeqProxy for keylet derivation.
src/libxrpl/tx/transactors/check/CheckCreate.cpp Use getSeqProxy() for check keylet derivation while storing numeric sequence.
src/libxrpl/protocol/Indexes.cpp Change sequence-based keylet function signatures to accept SeqProxy and use .value() for hashing.
src/libxrpl/ledger/helpers/NFTokenHelpers.cpp Pass SeqProxy directly into keylet::nftokenOffer.
include/xrpl/protocol/SeqProxy.h Add ticket() factory and arithmetic operators for SeqProxy.
include/xrpl/protocol/Indexes.h Update public keylet function declarations to accept SeqProxy and include SeqProxy.h.

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

Comment thread include/xrpl/protocol/SeqProxy.h Outdated
Comment thread include/xrpl/protocol/SeqProxy.h Outdated
Comment thread src/libxrpl/tx/transactors/system/TicketCreate.cpp Outdated
Comment thread src/test/jtx/TestHelpers.h
Comment thread include/xrpl/protocol/Indexes.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.

Looks good to me

Comment thread src/libxrpl/tx/transactors/check/CheckCreate.cpp Outdated
Comment thread include/xrpl/protocol/SeqProxy.h
Comment thread src/libxrpl/protocol/STTx.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 great.

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

Solid refactoring. No issues here.

@codecov

codecov Bot commented Jul 28, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.30769% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/libxrpl/protocol/Indexes.cpp 90.0% 2 Missing ⚠️
src/xrpld/rpc/handlers/ledger/LedgerEntry.cpp 66.7% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@mvadari
mvadari requested review from bthomee and ximinez July 29, 2026 02:38

@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 to flag. Code review complete.

@bthomee bthomee left a comment

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.

I can't leave a comment on the exact line but please see what I wrote in the Indexes.h file, close to the actual intended line.


Keylet
permissionedDomain(AccountID const& account, std::uint32_t seq) noexcept;
permissionedDomain(AccountID const& account, SeqProxy seq) noexcept;

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.

Don't forget to delete the getTicketIndex(AccountID const&, std::uint32_t) below. (I can't leave a comment on the exact line).

It is still declared publicly right next to the SeqProxy overload, and it's still used directly by production code: LedgerEntry.cpp::parseTicket calls getTicketIndex(*id, *seq) with the raw uint32, which we wouldn't want.

* Factory function to return a sequence-based SeqProxy
* Factory function to return a sequence-based SeqProxy.
* Outside of tests, this function should only be used for "secondary" transaction sequences,
* e.g. `sfOfferSequence`, or sequence fields in an existing ledger object. DO NOT use this for

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.

Is there any way we can prevent anyone from using it for the "primary" sequence of a transaction?

Claude suggested that if you want to actually close this, the options are: restrict sequence()/ticket() to test builds only (the docstring already says that's their main intended audience) and require production code to go through named, context-specific factories or STTx::getSeqProxy(); or at minimum rename them to something self-flagging like unsafeSequence()/unsafeTicket() so a reviewer's eye catches direct use in a diff.

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