Skip to content

Commit

Permalink
hotfix: temporary revert tx bursting in sendTx. Use previous implemen…
Browse files Browse the repository at this point in the history
…tation
  • Loading branch information
troggy committed Apr 20, 2019
1 parent 8f4d19f commit f95a11a
Showing 1 changed file with 10 additions and 33 deletions.
43 changes: 10 additions & 33 deletions src/txHelpers/sendTx.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,40 +8,17 @@
const axios = require('axios');
const encodeTx = require('../../lotion/lib/tx-encoding.js').encode;

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 nonce = Math.floor(Math.random() * (2 << 12)); // eslint-disable-line no-bitwise
const txBytes = `0x${encodeTx({ encoded: rawTx }, nonce).toString('hex')}`;

TX_BACKLOG.push(
() => {
axios.get(tendermintRpcUrl, {
params: {
tx: txBytes,
},
})
}
);

if (!AWAITS_DRAIN) {
setTimeout(drainBacklog, 1000);
AWAITS_DRAIN = true;
}
const tendermintRpcUrl = `http://localhost:${tendermintPort}/broadcast_tx_commit`;
const result = await axios.get(tendermintRpcUrl, {
params: {
tx: txBytes,
},
});

return {
result: result.data.result,
};
};

0 comments on commit f95a11a

Please sign in to comment.