3

I'm trying to post multiple transactions of payment to the network. Let's say 10 at a time. I used javascript in this context.

Problems:

  • If I try to post all of 10 transactions at the same time without delay, the result of transaction_hash of all of them are most likely the same. Maybe 9 of them or worst 10. This mean only 1 or 2 of transaction has submitted to the network.
  • If I delay 3s or 5s between each of them 2 or 3 the result still give the same transaction_hash.

I'm trying a lot of methods by adding more delay(seconds). It does give the different result (all of them are success 10/10). But are there many methods out there that would achieve this by not having much of delay?

3

For a transaction to be successful, it has to have a sequence number one greater than the current sequence number of the account funding the transaction.

Therefore, if you want to submit 10 transactions, they need distinct sequence numbers, and each one can only succeed if their sequence number is one greater than the current sequence number of the account at the time they are evaluated. This is why waiting before submitting improves your success rate - there is a higher chance of the previous transaction completing (the ledger being updated, and the account sequence number incremented) before you submit your next one.

To submit faster than this, I think your options are:

  1. Submit them from different accounts. You can submit 10 transactions simultaneously if you have 10 accounts.
  2. Submit multiple operations in a single transaction. If you can batch up multiple payment operations in a single transaction, then they can all be submitted together (with the same single sequence number).

It is true that if several transactions with incrementing sequence numbers make it into the same transaction set (ledger), then they will be ordered correctly, and can all succeed. However you have no guarantee that this will in fact happen.

Note also that the delay method is intrinsically vulnerable to racing: the delay only works because it is of the order of the average ledger close time. To really be sure, you should submit transactions with timebounds, and only submit (or resubmit) another transaction when either i) the timebound has expired, or ii) you receive confirmation of transaction success.

  • Thank a lot for your clarification. In summary, what you mean is an account cannot post multiple transactions at the same time. It's only one and after. The idea of multiple operations in a transaction is not work in my case. Maybe I have to think of another way to do this. – Him Hah Apr 23 at 6:34
  • Yes. It's possible they will make it into the same transaction set, but since you can't rely on that, it's not really a solution. – ire_and_curses Apr 23 at 16:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.