XRPLF / xrpl.js

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

Feature request: submitAndWait for a batch of transactions #1767

Open shortthefomo opened 3 years ago

shortthefomo commented 3 years ago

auto sequence not functioning

Screen Shot 2021-10-24 at 13 43 47
            async getOffers() {
                offers = await client.request({
                    "id": 9,
                    "command": "account_offers",
                    "account": wallet.classicAddress,
                })
                log('offers')

                for (let index = 0; index < offers.result.offers.length; index++) {
                    const element = offers.result.offers[index]
                    log(element)
                }
            },

Some times this gets a valid response other times this returns a faulty sequence. My guess here is that I am also firing off other transactions that increment the sequence number async and this causes the sequence number issues.

natenichols commented 3 years ago

Good morning @lathanbritz, thanks for opening an issue.

Are you using a BroadcastClient or a Client?

shortthefomo commented 3 years ago

Client not played with the BroadcastClient yet

natenichols commented 3 years ago

This error is thrown in submitAndWait() when the transaction has not been validated before ledger with ledger_index < LastLedgerSequence.

From your stack trace, you likely have a pending submitAndWait() that is throwing this error. I don't think that the code snippet you provided should throw that error.

shortthefomo commented 3 years ago

That pointed me in the right direction thank you. I had x2 async functions firing the submitAndWait() that were not waiting for the responses hence they could fire in any order and caused the out of sequence error.

Basically i need to wait for the response of submitAndWait and cant simply fire X of those requests off and forget about them.

Important note here is this is a slow process. ~3sec response.

Is there a submitAndWait for a batch of TX's? Say i had x5 OfferCreate transactions I wanted to append.

intelliot commented 3 years ago

Such a function does not currently exist, but it's a great feature request. The trick is that you'll need to set up the sequence numbers correctly, which requires additional logic and error handling.

This would be good as a new snippet. After more extensive testing, it could be added as a new method on Client, or even just a separate utility function.

In case it's useful, there's a more thorough version of "submit and wait" here: https://github.com/XRPLF/xrpl-dev-portal/blob/master/content/_code-samples/submit-and-verify/submit-and-verify2.js

This should be adapted into a snippet as well.

ckniffen commented 1 year ago

@khancode will this be covered by #2149?

khancode commented 1 year ago

@khancode will this be covered by #2149?

@ckniffen Yes, that's goal of my PR.