From 901ade3e30071d04b8603213da9cf8b660f3bcb9 Mon Sep 17 00:00:00 2001 From: kenshin-samourai Date: Wed, 27 Nov 2019 15:59:12 +0100 Subject: [PATCH] optimize requests sent by RemoteImporter with batch rpc calls --- lib/remote-importer/remote-importer.js | 41 +++++++++++++------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/lib/remote-importer/remote-importer.js b/lib/remote-importer/remote-importer.js index 51df487..388357e 100644 --- a/lib/remote-importer/remote-importer.js +++ b/lib/remote-importer/remote-importer.js @@ -260,19 +260,21 @@ class RemoteImporter { Logger.info(` Got ${scanTx.length} transactions`) - await util.seriesCall(scanTx, async txid => { - try { - const tx = await rpcTxns.getTransaction(txid, false) - if (tx == null) { - Logger.info(` got null for ${txid}`) - return null + // Retrieve the transactions by batches of 100 transactions + const txsChunks = util.splitList(scanTx, 100) + try { + for (let txsChunk of txsChunks) { + const txs = await rpcTxns.getTransactions(txsChunk, false) + for (let tx of txs) { + if (tx != null) { + ret.transactions.push(tx) + txids[tx.txid] = true + } } - ret.transactions.push(tx) - txids[tx.txid] = true - } catch(e) { - Logger.error(e, `RemoteImporter.xpubScan() : rawTransaction error, txid ${txid}`) } - }) + } catch(e) { + Logger.error(e, `RemoteImporter.xpubScan() : getTransactions error`) + } if (gotTransactions) { // We must go deeper @@ -335,15 +337,14 @@ class RemoteImporter { Logger.info(` Got ${scanTx.length} transactions`) - // Get transaction s data from bitcoind - await util.seriesCall(scanTx, async txid => { - const tx = await rpcTxns.getTransaction(txid, false) - if (tx == null) { - Logger.info(` got null for ${txid}`) - return null - } - txns.push(tx) - }) + // Retrieve the transactions by batches of 100 transactions + const txsChunks = util.splitList(scanTx, 100) + for (let txsChunk of txsChunks) { + const txs = await rpcTxns.getTransactions(txsChunk, false) + for (let tx of txs) + if (tx != null) + txns.push(tx) + } // Import addresses and transactions into the database await db.addAddresses(imported)