-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Labels
Description
Context
Related to #30.
When submitting transactions to the XRP Ledger, each transaction must use a unique and strictly increasing Sequence
number for a given account. The XRPL node enforces that only one transaction per (account, sequence)
may be queued at a time.
A problem arises if:
- The includer submits a transaction with sequence
N
and receives aterQUEUED
response (i.e. the transaction is accepted but pending). - Before that transaction is included or dropped, the includer submits another transaction and unknowingly reuses the same sequence
N
. - This can result in:
- The second transaction replacing the first if it has a higher fee, or
- A rejection (
telCAN_NOT_QUEUE_FEE
) if the fee isn't high enough.
To prevent this, we need a mechanism that guarantees the includer never reuses a pending sequence number for the same account unless doing so intentionally.
Goal
Implement a sequence allocator that:
- Returns the next safe
Sequence
number for a given account. - Prevents accidental reuse of pending sequence numbers.
Proposed Design
- Check for existing queued/submitted transactions in Postgres.
- If there are no pending transactions for the account:
- Use
account_info().account_data.Sequence
as the base. (default behavior of.prepare_transaction()
)
- Use
- If there are pending transactions:
- Use
MAX(sequence)
fromqueued_transactions
(withFOR UPDATE
) to compute the next safe sequence.
- Use