From a951c7395b1052c5607c03a371321d26305d4090 Mon Sep 17 00:00:00 2001 From: Kosta Korenkov Date: Fri, 31 May 2019 19:41:52 +0300 Subject: [PATCH] feat: use broadcast_tx_sync and no burst (experimental) --- src/txHelpers/sendTx.js | 40 +++++++++------------------------------- 1 file changed, 9 insertions(+), 31 deletions(-) diff --git a/src/txHelpers/sendTx.js b/src/txHelpers/sendTx.js index eff8aea4..227a753c 100644 --- a/src/txHelpers/sendTx.js +++ b/src/txHelpers/sendTx.js @@ -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, + }; };