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

DisconnectedError(websocket was closed) when run multiple transactions at once. #1055

Closed StarNeit closed 4 years ago

StarNeit commented 4 years ago

When I run 1000 transactions using ripple-lib at once using Promise.all, there is DisconnectedError(websocket was closed).

Here is my code snippet. `

const api = new RippleAPI({
    server: 'wss://s1.ripple.com' // Public rippled server hosted by Ripple, Inc.
});
if (!api.isConnected()) {
    console.log(`\n Connecting Ripple Server .....`);
    await api.connect();
}

const users = await WalletAddress.find({}); // users is array of 1000 members

await Promise.all(users.map(async (user, index) => {
    console.log(index, user.phone, user.balance);
    if (user.balance > 0) {
        const xrpHashes = await sendXRP(api, user.fromXRPAddress, user.toXRPAddress, user.balance);
        console.log(index, user.phone, user.balance);
        console.log('xrpHashes:', xrpHashes);
    }
}));` 

In my project, I have to run every user's transactions together every 2 minutes.

Here are my questions. 1) How many transactions RippleAPI connection can process at once? 2) Is it okay to create multiple connections and connect to rippled server instead of one connection? Will that resolve DisconnectedError?

Please suggest any good solution to avoid this Disconnection error. Thank you.

StarNeit commented 4 years ago

image

StarNeit commented 4 years ago

Hello @intelliot Would you please give me one of your advices to avoid this issue?

intelliot commented 4 years ago

Public rippled servers like s1.ripple.com have rate limits in place. I recommend running your own instance of rippled and connecting to it with an admin connection. This will allow you to submit more transactions more quickly.

StarNeit commented 4 years ago

Ok we just deployed custom rippled server but couldn’t find a way how to connect to the server from your documentation. Should we add public domain for our rippled server? which port should we connect? @intelliot

intelliot commented 4 years ago

A public domain is not necessary, and in fact your server does not necessarily need to be publicly accessible. You can choose the port. The example rippled.cfg configuration offers an admin connection on port 6006 when connecting from the same machine (127.0.0.1).

dragonheaven commented 4 years ago

@intelliot Thanks for the advise. We successfully connected to our rippled server but still have an issue submitting transactions. We've got BAD_AUTH issue, still couldn't resolve this.

{ resultCode: 'tefBAD_AUTH', resultMessage: 'Transaction\'s public key is not authorized.', engine_result: 'tefBAD_AUTH', engine_result_code: -196, ...}

Could you please advise what additional configuration we need to add?

StarNeit commented 4 years ago

@intelliot , would you please help with the above issue? thank you a lot. tefBAD_AUTH: Transaction's public key is not authorized

intelliot commented 4 years ago

It sounds like your secret or private key is incorrect or does not match the account that you're trying to send from.

dragonheaven commented 4 years ago

@intelliot We submitted transactions signed offline. Should we do something on our rippled server?

ximinez commented 4 years ago

The only possible server configuration that I can think of is the choice of which network the server is connecting to. For example, if it's connected to the Altnet (https://xrpl.org/connect-your-rippled-to-the-xrp-test-net.html), and you submit a transaction signed for the Main Net, it will probably never succeed, and vice versa. (I only say "probably" because, even though it is strongly not recommended, accounts can be created on both networks using the same keys, but they won't have the same settings, unless they are manually configured that way on both networks.)

If that's not the issue, it's much more likely that the transaction is not being properly signed.

dragonheaven commented 4 years ago

@ximinez Thank you for the advise.