Unverified Commit 3b43d352 authored by Pavel Ševčík's avatar Pavel Ševčík
Browse files

Optimize RPC call in checkUnconfirmed()

parent 3b17a0dd
......@@ -259,31 +259,27 @@ class MempoolProcessor {
const unconfirmedTxs = await db.getUnconfirmedTransactions()
if (unconfirmedTxs.length > 0) {
const unconfirmedTxLists = util.splitList(unconfirmedTxs, 10)
const unconfirmedTxLists = util.splitList(unconfirmedTxs, 20)
await util.seriesCall(unconfirmedTxLists, async (txList) => {
return await util.parallelCall(txList, tx => {
try {
return this.client.getrawtransaction( { txid: tx.txnTxid, verbose: true })
.then(async rtx => {
if (!rtx.blockhash) return null
// Transaction is confirmed
const block = await db.getBlockByHash(rtx.blockhash)
if (block && block.blockID) {
Logger.info(`Tracker : Marking TXID ${tx.txnTxid} confirmed`)
return db.confirmTransactions([tx.txnTxid], block.blockID)
}
},
(e) => {
Logger.error(e, 'Tracker : MempoolProcessor.checkUnconfirmed()')
// Transaction not in mempool. Update LRU cache and database
TransactionsBundle.cache.del(tx.txnTxid)
// TODO: Notify clients of orphaned transaction
return db.deleteTransaction(tx.txnTxid)
}
)
} catch(e) {
Logger.error(e, 'Tracker : MempoolProcessor.checkUnconfirmed()')
const rpcRequests = txList.map((tx) => ({ method: 'getrawtransaction', params: { txid: tx.txnTxid, verbose: true }, id: tx.txnTxid }))
const txs = await this.client.batch(rpcRequests)
return await util.parallelCall(txs, async (rtx) => {
if (rtx.error) {
Logger.error(rtx.error.message, 'Tracker : MempoolProcessor.checkUnconfirmed()')
// Transaction not in mempool. Update LRU cache and database
TransactionsBundle.cache.del(rtx.id)
// TODO: Notify clients of orphaned transaction
return db.deleteTransaction(rtx.id)
} else {
if (!rtx.result.blockhash) return null
// Transaction is confirmed
const block = await db.getBlockByHash(rtx.result.blockhash)
if (block && block.blockID) {
Logger.info(`Tracker : Marking TXID ${rtx.id} confirmed`)
return db.confirmTransactions([rtx.id], block.blockID)
}
}
})
})
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment