0056 XLS-56d: Atomic/Batch Transactions #162
Replies: 21 comments 32 replies
-
I'm not sure I like the name I would also just want non atomic batch. Try all 8 and return the responses of each. I will parse the results and handle accordingly. If atomic proves to be very difficult this will be a much easier implementation |
Beta Was this translation helpful? Give feedback.
-
my thoughts here
|
Beta Was this translation helpful? Give feedback.
-
Am i reading it correctly that this actually reduces the fee for the most complex types on the ledger, large count multisig and escrow finish? Batch fee either needs to be dynamic based on tx types in the batch, or worst case assumption for all 8 slots. |
Beta Was this translation helpful? Give feedback.
-
What will the value of There could be a impact on the exchange's deposit system. But it is a very valuable feature for the ecosystem as a whole! |
Beta Was this translation helpful? Give feedback.
-
I'd like to clarify the way transactions are counted. The spec mentions that it will be possible to nest the transactions, but the total number of transactions cannot exceed 8.
In the total transaction count is this considered 3 or 4 transactions? I.e. does the nested atomic contribute to the total transaction count? Also, is there any rationale behind allowing a user to submit 8 transactions as opposed to 10 or 6? |
Beta Was this translation helpful? Give feedback.
-
This feature supports nesting, which means we can do some arbitrary conditional transaction execution by combining different atomic types. IHMO this is pretty cool, and versatile. Who needs smart contracts when you have logic, am I right? :P We already have an For example, with 8 transactions users would already be able to express secondary boolean operations such as:
|
Beta Was this translation helpful? Give feedback.
-
For example, when using OfferCreate, Sequence is a component of OfferID. If multiple OfferCreate transactions are used in this transaction, what will the OfferID? |
Beta Was this translation helpful? Give feedback.
-
If AtmicType is ONLYONE or BATCH, it might be helpful to see which transactions were successful (meta field). |
Beta Was this translation helpful? Give feedback.
-
The spec was significantly updated on 2024-04-22. |
Beta Was this translation helpful? Give feedback.
-
I presume ticket sequences are intentionally excluded, which I think is good to reduce scope if they can still be supported in a future version. I could see Tickets being useful for atomic swaps because until all parties sign and submit, their accounts cannot submit any other transactions to the ledger otherwise they will invalidate their sequence numbers inside the batch transaction. |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
regarding FAQ 3, would this not guarantee that all transactions are part of the same ledger? |
Beta Was this translation helpful? Give feedback.
-
Although not directly related to the content, Outer Transaction Fee in 6.1.2 Sample Ledger is set to "0". Perhaps it should be "40". |
Beta Was this translation helpful? Give feedback.
-
If Multiple Account Batch and Inner Txn contains multiple transactions for the same account, will BatchTxn.Sequence be incremented for each? If so, Ledger Object ID should use Even if it is not increased and is processed with the same value,
|
Beta Was this translation helpful? Give feedback.
-
Is there any chance the processing could reach a deadlock state if there is any dependence between inner transactions or between inner and outer transaction? I have no knowledge of how the transactions are being processed within rippled, so this might be a nothing burger. I am just asking, because batch processing is a kind of traditional DB transactions and they are prone to deadlocks if not implemented right. |
Beta Was this translation helpful? Give feedback.
-
Question. How does it work with wallet providers? |
Beta Was this translation helpful? Give feedback.
-
After spending a bit of time looking at XLS-67d. I'm in favor of splitting the charge out of the batch, and removing the documentation to use it for service charges in the batch. In favor of both amendments moving forward with the caveat that charges use the chareback field vs bundling those into a batch. Motivation is mainly interfaces having a clear place to derive / find and display clearly display additional charges. This could become complicated if batch was used obscurely. |
Beta Was this translation helpful? Give feedback.
-
would love to see this go through. Trying to implement CRU (carbon credits) and CET (emissions data) linking and need atomic transactions. CRU and CET are defined by GBBC IWA TTF |
Beta Was this translation helpful? Give feedback.
-
Per the new XLS Contributing process, it is my opinion that we have reached a "well-refined standard." As such, I propose that we move this discussion to a file (via #197) and work on final changes using additional PRs, for better change-tracking. Please comment here if you would like to object to moving this spec/discussion forward in the process into a DRAFT spec. (Note that per the Contributing guidelines, moving a spec into the DRAFT state does not mean any kind of endorsement, nor does it mean that this specification will become adopted. It is solely meant as a mechanism to enable better change tracking using PRs.) |
Beta Was this translation helpful? Give feedback.
-
Instead of incrementing the new_seq_num by This does not completely eliminate wastage of the sequence numbers, however it reduces it. But, it comes with an increased computational overhead. |
Beta Was this translation helpful? Give feedback.
-
If the NFTokenOffer creation fails, I would retry the transaction after fixing the errors.
If I submit multiple offers on the DEX (with varying slippage), the offer-matching algorithm ensures that both buyer and seller obtain the optimal match. I can submit multiple offers with the
I can encapsulate the transaction submission code inside a try-catch or an if-else block. This helps me implement the required logic. Why would I need the
|
Beta Was this translation helpful? Give feedback.
-
Atomic/Batch Transactions
Abstract
The XRP Ledger has a robust set of built-in features, enabling fast and efficient transactions without the need for complex smart contracts on every step. However, a key limitation exists: multiple transactions cannot be executed atomically. This means that if a complex operation requires several transactions, a failure in one can leave the system in an incomplete or unexpected state. Imagine building a house: you wouldn't want to lay the foundation and build the walls, and then discover you can't afford the roof, leaving you with an unfinished and unusable structure.
This document proposes a design to allow multiple transactions to be packaged together and executed as a single unit. It's like laying the foundation, building the walls, and raising the roof all in one single secure step, leveraging the existing strengths of the XRP Ledger. If you're unable to afford the roof, you won't even bother laying the foundation.
This eliminates the risk of partial completion and unexpected outcomes, fostering a more reliable and predictable user experience for complex operations. By introducing these batch transactions, developers gain the ability to design innovative features and applications that were previously hindered by the lack of native smart contracts for conditional workflows. This empowers them to harness the full potential of the XRP Ledger's built-in features while ensuring robust execution of complex processes.
Some use-cases that may be enabled by batch transactions include (but are certainly not limited to):
1. Overview
This spec proposes one new transaction:
Batch
. It also proposes an addition to the common fields of all transactions. It will not require any new ledger objects, nor modifications to existing ledger objects. It will require an amendment, tentatively titledfeatureBatch
.The rough idea of this design is that users can include "sub-transactions" inside
Batch
, and these transactions are processed atomically. The design also supports transactions from different accounts in the sameBatch
wrapper transaction.1.1. Terminology
Batch
transaction, that are executed atomically.Batch
transaction itself.2. Transaction:
Batch
TransactionType
string
UInt16
Account
string
STAccount
Fee
string
STAmount
Flags
number
UInt32
RawTransactions
array
STArray
TxnIDs
array
Vector256
BatchSigners
array
STArray
2.1.
Fee
The fee for the outer transaction is:
(where
n
is the number of signatures included in the outer transaction)In other words, the fee is twice the base fee (a total of 20 drops when there is no fee escalation), plus the sum of the transaction fees of all the inner transactions (which incorporates factors like higher fees for multisign or
AMMCreate
).The fees for the individual inner transactions are paid here instead of in the inner transaction itself, to ensure that fee escalation is calculated on the total cost of the transaction instead of just the overhead.
2.2.
Flags
The
Flags
field represents the batch mode of the transaction. Exactly one must be specified in aBatch
transaction.This spec supports four modes:
ALLORNOTHING
ortfAllOrNothing
(with a value of0x00000001
)ONLYONE
ortfOnlyOne
(with a value of0x00000002
)UNTILFAILURE
ortfUntilFailure
(with a value of0x00000004
)INDEPENDENT
ortfIndependent
(with a value of0x00000008
)2.2.1.
ALLORNOTHING
All or nothing. All transactions must succeed for any of them to succeed.
2.2.2.
ONLYONE
The first transaction to succeed will be the only one to succeed; all other transactions either failed or were never tried.
While this can sort of be done by submitting multiple transactions with the same sequence number, there is no guarantee that the transactions are processed in the same order they are sent.
2.2.3.
UNTILFAILURE
All transactions will be applied until the first failure, and all transactions after the first failure will not be applied.
2.2.4.
INDEPENDENT
All transactions will be applied, regardless of failure.
2.3.
RawTransactions
RawTransactions
contains the list of transactions that will be applied. There can be up to 8 transactions included. These transactions can come from one account or multiple accounts.Each inner transaction:
BatchTxn
field (see section 3 for details).0
."0"
.""
) in theSigningPubKey
andTxnSignature
fields.A transaction will be considered a failure if it receives any result that is not
tesSUCCESS
.This field is not included in the validated transaction, nor is it used to compute the outer transaction signature(s), since all transactions are included separately as a part of the ledger.
2.4.
TxnIDs
TxnIDs
contains a list of the transaction hashes/IDs for all the transactions contained inRawTransactions
. This is the only part of the inner transactions that is saved as a part of the ledger within theBatch
transaction, since the inner transactions themselves will be their own transactions on-ledger. The hashes inTxnIDs
must be in the same order as the raw transactions inRawTransactions
.While this field seems complicated/confusing to work with, it can easily be abstracted away (e.g. as a part of autofilling) in tooling, and it's easy for
rippled
to check a hash doesn't match its corresponding transaction inRawTransaction
.2.5.
BatchSigners
This field operates similarly to multisign on the XRPL. It is only needed if multiple accounts' transactions are included in the
Batch
transaction; otherwise, the normal transaction signature provides the same security guarantees.Every account that has at least one inner transaction, excluding the outer account (if applicable), must have a
BatchSigners
field.Account
string
STAccount
SigningPubKey
string
STBlob
Signature
string
STBlob
Signers
array
STArray
2.5.1.
Account
This is an account that has at least one inner transaction.
2.5.2.
SigningPubKey
andSignature
These fields are included if the account is signing with a single signature (as opposed to multi-sign). They sign the
Flags
andTxnIDs
fields.2.5.3.
Signers
This field is included if the account is signing with multi-sign (as opposed to a single signature). It operates equivalently to the
Signers
field used in standard transaction multi-sign. This field holds the signatures for theFlags
andTxnIDs
fields.2.6. Metadata
The inner transactions will be committed separately to the ledger and will therefore have separate metadata. This is to ensure better backwards compatibility for legacy systems, so they can support
Batch
transactions without needing any changes to their systems.For example, a ledger that only has one
Batch
transaction containing 2 inner transactions would look like this:2.6.1. Outer Transactions
Each outer transaction will only contain the metadata for its sequence and fee processing, not for the inner transaction processing.
There will also be a list of which transactions were actually processed, which is useful for the
ONLYONE
andUNTILFAILURE
modes, since those may only process a subset of transactions, and for debugging with all modes. This section will be calledBatchExecutions
.It will contain a list of objects that have the following fields for every transaction that is processed (successfully or unsuccessfully):
TransactionHash
string
STUInt256
TransactionResult
string
STUInt8
Some important things to note:
ONLYONE
mode, if the first transaction succeeds, then the rest of the transactions will not even be processed.tesSUCCESS
and if the outer transaction has a result code oftesSUCCESS
. For example, the inner transaction might have a result code oftesSUCCESS
without being included in the ledger if theALLORNOTHING
mode is used, but one of the transaction fails.2.6.2. Inner Transactions
Each inner transaction will contain the metadata for its own processing. Only the inner transactions that were actually committed to the ledger will be included. This makes it easier for legacy systems to still be able to process
Batch
transactions as if they were normal.There will also be a pointer back to the parent outer transaction (
parent_batch
), for ease of development (similar to thenftoken_id
field).3. Transaction Common Fields
As a reference, here are the fields that all transactions currently have.
We propose these modifications:
BatchTxn
object
STObject
3.1.
BatchTxn
The
BatchTxn
inner object must be included in any inner transaction of aBatch
transaction. Its inclusion:The fields contained in this object are:
Account
string
AccountID
OuterSequence
number
UInt32
Sequence
number
UInt32
BatchIndex
number
UInt8
3.1.1.
Account
This is the account that is submitting the outer
Batch
transaction.3.1.2.
OuterSequence
This is the sequence number of the outer
Batch
transaction. Its inclusion ensures that there are no hash collisions with otherBatch
transactions.3.1.3.
Sequence
This is the next available sequence number for the inner transaction's account. This only needs to be included in a multi-account
Batch
transaction. See section 4.1 for an explanation as to why this is needed.3.1.4.
BatchIndex
This is the (0-indexed) index of the inner transaction within the existing
Batch
transaction. The first inner transaction will haveBatchIndex
value0
, the second will be1
, etc. Its inclusion ensures there are no hash collisions with other inner transactions within the sameBatch
transaction, and that the transactions are all placed in the right order.4. Edge Cases of Transaction Processing
Inner transactions don't have
Sequence
s orTicketSequence
s, unlike a normal transaction. This causes some problems when it comes to transaction processing, due to a few edge cases.4.1. Ledger Object ID Generation
Some objects, such as offers and escrows, use the sequence number of the creation transaction as a part of their ledger entry ID generation, to ensure uniqueness of the IDs.
To get around this, in single-account
Batch
transactions, a "phantom sequence number" will be used instead. The "phantom sequence number" will be equal toBatchTxn.OuterSequence + BatchTxn.BatchIndex
.Multi-account transactions use the same "phantom sequence number" strategy, but instead uses the equation
BatchTxn.Sequence + BatchTxn.BatchIndex
, since theOuterSequence
does not map to the inner transaction's account.4.2. Sequence Number Handling
Section 4.1 describes how sequence numbers are used in inner transactions.
The sequence numbers will always be consumed (i.e. the
AccountRoot
'sSequence
will be incremented) if any inner transactions are processed. A transaction counts as being "processed" if it is applied to the ledger, i.e. if atec
ortes
error is received. The sequence number for each account will be incremented by the total number of inner transactions included in theBatch
transaction, to avoid any hash collisions.In other words,
$$Sequence_{new} = Sequence_{old} + numInnerTxns$$
5. Security
5.1. Trust Assumptions
Regardless of how many accounts' transactions are included in a
Batch
transaction, all accounts need to sign the collection of transactions.5.1.1. Single Account
In the single account case, this is obvious; the single account must approve all of the transactions it is submitting. No other accounts are involved, so this is a pretty straightforward case.
5.1.2. Multi Account
The multi-account case is a bit more complicated and is best illustrated with an example. Let's say Alice and Bob are conducting a trustless swap via a multi-account
Batch
, with Alice providing 1000 XRP and Bob providing 1000 USD. Bob is going to submit theBatch
transaction, so Alice must provide her part of the swap to him.If Alice provides a fully autofilled and signed transaction to Bob, Bob could submit Alice's transaction on the ledger without submitting his and receive the 1000 XRP without losing his 1000 USD. Therefore, the inner transactions must be unsigned.
If Alice just signs her part of the
Batch
transaction, Bob could modify his transaction to only provide 1 USD instead, thereby getting his 1000 XRP at a much cheaper rate. Therefore, the entireBatch
transaction (and all its inner transactions) must be signed by all parties.6. Examples
6.1. One Account
In this example, the user is creating an offer while trading on a DEX UI, and the second transaction is a platform fee.
6.1.1. Sample Transaction
The inner transactions are not signed, and the
BatchSigners
field is not needed on the outer transaction, since there is only one account involved.6.1.2. Sample Ledger
This example shows what the ledger will look like after the transaction is confirmed.
Note that the inner transactions are committed as normal transactions, and the
RawTransactions
field is not included in the validated version of the outer transaction.6.2. Multiple Accounts
In this example, two users are atomically swapping their tokens, XRP for GKO.
6.2.1. Sample Transaction
The inner transactions are still not signed, but the
BatchSigners
field is needed on the outer transaction, since there are two accounts' inner transactions in thisBatch
transaction.6.2.2. Sample Ledger
This example shows what the ledger will look like after the transaction is confirmed.
Note that the inner transactions are committed as normal transactions, and the
RawTransactions
field is not included in the validated version of the outer transaction.Appendix
Appendix A: FAQ
A.1: What if I want a more complex tree of transactions that are AND/XORed together? Can I nest
Batch
transactions?The original version of this spec supported nesting
Batch
transactions. However, upon further analysis, that was deemed a bit too complicated for an initial version ofBatch
, as most of the benefit from this new feature does not require nested transactions. Based on user and community need, this could be added as part of a V2.A.2: What if all of the transactions fail? Will a fee still be claimed?
Yes, just as they would if they were individually submitted.
A.3: Would this feature enable greater frontrunning abilities?
That is definitely a concern. Ways to mitigate this are still being investigated. Some potential answers:
Batch
transactionsBatch
transactions at the end of the ledgerA.4: What error is returned if all the transactions fail in an
ONLYONE
/UNTILFAILURE
transaction?A general error,
temBATCH_FAILED
/tecBATCH_FAILED
, will be returned. A list of all the return codes encountered for the transactions that were processed will be included in the metadata, for easier debugging.A.5: Can another account sign/pay for the outer transaction if they don't have any of the inner transactions?
If there are multiple parties in the inner transactions, yes. Otherwise, no. This is because in a single party
Batch
transaction, the inner transaction's signoff is provided by the normal transaction signing fields (SigningPubKey
andTxnSignature
).A.6: How is the
UNTILFAILURE
mode any different than existing behavior with sequence numbers?Right now, if you submit a series of transactions with consecutive sequence numbers without the use of tickets or
Batch
, then if one fails in the middle, all subsequent transactions will also fail due to incorrect sequence numbers (since the one that failed would have the next sequence numbers).The difference between the
UNTILFAILURE
mode and this existing behavior is that right now, the subsequent transactions will only fail with a non-tec
error code. If the failed transaction receives an error code starting withtec
, then a fee is claimed and a sequence number is consumed, and the subsequent transactions will still be processed as usual.A.7: How is the
INDEPENDENT
mode any different than existing behavior with tickets?Tickets require temporarily having a reserve for all the tickets you want to create, but an
INDEPENDENT
modeBatch
transaction doesn't, for the low cost of 10 extra drops.On the flip side, tickets are still needed for other use-cases, such as needing to coordinate multiple signers or needing out-of-order transactions.
A.8: Is it possible for inner transactions to end up in a different ledger than the outer transaction?
No, because the inner transactions skip the transaction queue. They are already effectively processed by the queue via the outer transaction. Inner transactions will also be excluded from consensus for the same reason.
A.9: How does this work in conjunction with XLS-49d? If I give a signer list powers over the
Batch
transaction, can it effectively run all transaction types?The answer to this question is still being investigated. Some potential answers:
A.10: What if I want some error code types to be allowed to proceed, just as
tesSUCCESS
would, in e.g. anALLORNOTHING
case?This was deemed unnecessary. If you have a need for this, please provide example use-cases.
A.11: What if I want the inner transaction accounts to handle their own fees?
That is not supported in this version of the spec, as it is cleaner to just have one account pay the fee. This also allows fee escalation to be calculated on the total cost of the transaction, instead of just on the overhead.
Beta Was this translation helpful? Give feedback.
All reactions