From 9fac3e984d9785379c1ed1366050b3c2fe0a9a05 Mon Sep 17 00:00:00 2001 From: kenshin-samourai Date: Fri, 15 May 2020 14:38:35 +0200 Subject: [PATCH 1/4] remove txCache from Transactions --- lib/bitcoind-rpc/transactions.js | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/lib/bitcoind-rpc/transactions.js b/lib/bitcoind-rpc/transactions.js index 27efc0d..a0b8b15 100644 --- a/lib/bitcoind-rpc/transactions.js +++ b/lib/bitcoind-rpc/transactions.js @@ -23,15 +23,6 @@ class Transactions { */ constructor() { // Caches - this.txCache = LRU({ - // Maximum number of transactions to store - max: 10000, - // Function used to compute length of item - length: (n, key) => 1, - // Maximum age for items in the cache. Items do not expire - maxAge: Infinity - }) - this.prevCache = LRU({ // Maximum number of transactions to store max: 100000, @@ -85,19 +76,9 @@ class Transactions { * @returns {Promise} */ async getTransaction(txid, fees) { - const keyCache = `${txid}-${fees ? '1' : '0'}` - - // Return transaction from cache when possible - if (this.txCache.has(keyCache)) - return this.txCache.get(keyCache) - try { const tx = await this.rpcClient.getrawtransaction(txid, true) - const ret = await this._prepareTxResult(tx) - // Store the result in cache - if (ret.block && ret.block.hash) - this.txCache.set(txid, ret) - return ret + return this._prepareTxResult(tx) } catch(e) { Logger.error(e, 'Bitcoind RPC : Transaction.getTransaction()') return Promise.reject(errors.generic.GEN) From 15bd5af6a1b131a6c18454c7c7d2a2e4acd6ce09 Mon Sep 17 00:00:00 2001 From: kenshin-samourai Date: Fri, 15 May 2020 14:41:37 +0200 Subject: [PATCH 2/4] decrease size of prevCache in Transactions --- lib/bitcoind-rpc/transactions.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bitcoind-rpc/transactions.js b/lib/bitcoind-rpc/transactions.js index a0b8b15..b46b3b3 100644 --- a/lib/bitcoind-rpc/transactions.js +++ b/lib/bitcoind-rpc/transactions.js @@ -25,7 +25,7 @@ class Transactions { // Caches this.prevCache = LRU({ // Maximum number of transactions to store - max: 100000, + max: 20000, // Function used to compute length of item length: (n, key) => 1, // Maximum age for items in the cache. Items do not expire From 4dffecab8239268b2232438d0474bf486bd4c49f Mon Sep 17 00:00:00 2001 From: kenshin-samourai Date: Fri, 15 May 2020 14:50:25 +0200 Subject: [PATCH 3/4] remove depreacated code --- lib/bitcoind-rpc/transactions.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/bitcoind-rpc/transactions.js b/lib/bitcoind-rpc/transactions.js index b46b3b3..d135110 100644 --- a/lib/bitcoind-rpc/transactions.js +++ b/lib/bitcoind-rpc/transactions.js @@ -178,10 +178,7 @@ class Transactions { ptx = this.prevCache.get(inTxid) } else { ptx = await this.rpcClient.getrawtransaction(inTxid, true) - if (ptx.blockhash && ptx.confirmations && ptx.blocktime) { - ptx.height = rpcLatestBlock.height - ptx.confirmations + 1 - this.prevCache.set(inTxid, ptx) - } + this.prevCache.set(inTxid, ptx) } const outpoint = ptx.vout[txin.outpoint.vout] From e90672d506d9bf44698147e0066332b9d9601406 Mon Sep 17 00:00:00 2001 From: kenshin-samourai Date: Fri, 15 May 2020 15:19:17 +0200 Subject: [PATCH 4/4] add missing fees parameter --- lib/bitcoind-rpc/transactions.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bitcoind-rpc/transactions.js b/lib/bitcoind-rpc/transactions.js index d135110..1aec6ac 100644 --- a/lib/bitcoind-rpc/transactions.js +++ b/lib/bitcoind-rpc/transactions.js @@ -78,7 +78,7 @@ class Transactions { async getTransaction(txid, fees) { try { const tx = await this.rpcClient.getrawtransaction(txid, true) - return this._prepareTxResult(tx) + return this._prepareTxResult(tx, fees) } catch(e) { Logger.error(e, 'Bitcoind RPC : Transaction.getTransaction()') return Promise.reject(errors.generic.GEN)