Closed tuloski closed 7 years ago
@clark800
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
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?
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
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?
@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.
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!
Sending multiple (different) transactions in "parallel" results in all the transactions having the same sequence, so one succeeds and the others get tefPAST_SEQ.