Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 9 additions & 31 deletions src/txHelpers/sendTx.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,16 @@

const axios = require('axios');

const TX_BACKLOG = [];
let AWAITS_DRAIN = false;

// Drain the tx queue every ~1000ms.
// The goal here is to increase performance and mitigate block congestion.
// Bursting calls to `broadcast_tx_async` archieves that.

function drainBacklog() {
AWAITS_DRAIN = false;

while (TX_BACKLOG.length) {
const func = TX_BACKLOG.shift();

func();
}
}

module.exports = async (tendermintPort, rawTx) => {
const tendermintRpcUrl = `http://localhost:${tendermintPort}/broadcast_tx_async`;
const tendermintRpcUrl = `http://localhost:${tendermintPort}/broadcast_tx_sync`;

TX_BACKLOG.push(
() => {
axios.get(tendermintRpcUrl, {
params: {
tx: rawTx,
},
})
}
);
const result = await axios.get(tendermintRpcUrl, {
params: {
tx: rawTx,
},
});

if (!AWAITS_DRAIN) {
setTimeout(drainBacklog, 1000);
AWAITS_DRAIN = true;
}
return {
result: result.data.result,
};
};