Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use broadcast_tx_sync and no burst (experimental) #274

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
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,
};
};