XRPLF / xrpl.js

A JavaScript/TypeScript API for interacting with the XRP Ledger in Node.js and the browser
https://xrpl.org/
1.2k stars 511 forks source link

transactions in parallel-->same sequence #781

Closed tuloski closed 7 years ago

tuloski commented 7 years ago

Sending multiple (different) transactions in "parallel" results in all the transactions having the same sequence, so one succeeds and the others get tefPAST_SEQ.

sublimator commented 7 years ago

@clark800

wilsonianb commented 7 years ago

Hi @tuloski https://ripple.com/dev-blog/introducing-rippleapi/

RippleAPI merges ripple-lib and Ripple-REST into a single high-level interface for JavaScript that is fully-documented, fully-tested, schema-validated, stateless, and easier to use.

RippleAPI is stateless. It can only determine account sequence numbers from validated ledgers, which do not include in-flight transactions.

You can manage sequences locally and specify sequence in your transaction instructions. https://github.com/ripple/ripple-lib/blob/develop/docs/index.md#transaction-instructions

tuloski commented 7 years ago

I see, but it's weird to use a library for something asynchronous and with promises and then you have to manually do a "mutex" or something (global variable?) to take care of the sequence. So every time a transaction is submitted and the sequence is not included, the API has to send a request to the server to get the lastSequence number of the account?

wilsonianb commented 7 years ago

So every time a transaction is submitted and the sequence is not included, the API has to send a request to the server to get the lastSequence number of the account?

Correct. See here: https://github.com/ripple/ripple-lib/blob/b5564330f68a9bbf2fef9f68252a6a57299f27a5/src/transaction/utils.js#L85-L98

tuloski commented 7 years ago

What do you think is the best workflow if I have multiple APIs (on multiple machines potentially) accessing the same account and sending transactions in async way (i.e. I cannot coordinate them)? Just send the transactions, wait to fail and resubmit in case of failure?

matejr commented 7 years ago

@tuloski , you can use another process (Redis or something similar) to track (or coordinate) sequence numbers. You can also use something like Apache ZooKeeper, but this seems like overkill to me.

intelliot commented 7 years ago

I agree with @matejr's suggestion. You may need to be creative to devise a way to coordinate sequence numbers (perhaps a simple API between your machines), but it should be possible. If not, let us know what's unusual about your setup that prevents communication between your machines. Thanks!