diff --git a/README.md b/README.md index 0fa6495bc..e48f6cca1 100644 --- a/README.md +++ b/README.md @@ -96,7 +96,6 @@ Edit `mempool-config.json` to add your Bitcoin Core node RPC credentials: "HOST": "127.0.0.1", "PORT": 50002, "TLS_ENABLED": true, - "TX_LOOKUPS": false }, "DATABASE": { "ENABLED": true, diff --git a/backend/mempool-config.sample.json b/backend/mempool-config.sample.json index 7f10a4d14..c4cea1cbd 100644 --- a/backend/mempool-config.sample.json +++ b/backend/mempool-config.sample.json @@ -16,8 +16,7 @@ "ELECTRUM": { "HOST": "127.0.0.1", "PORT": 50002, - "TLS_ENABLED": true, - "TX_LOOKUPS": false + "TLS_ENABLED": true }, "ESPLORA": { "REST_API_URL": "http://127.0.0.1:3000" diff --git a/backend/src/api/bitcoin/electrum-api.ts b/backend/src/api/bitcoin/electrum-api.ts index 6c275356b..2832a9215 100644 --- a/backend/src/api/bitcoin/electrum-api.ts +++ b/backend/src/api/bitcoin/electrum-api.ts @@ -43,25 +43,6 @@ class BitcoindElectrsApi extends BitcoinApi implements AbstractBitcoinApi { }); } - async $getRawTransaction(txId: string, skipConversion = false, addPrevout = false): Promise { - if (!config.ELECTRUM.TX_LOOKUPS) { - return super.$getRawTransaction(txId, skipConversion, addPrevout); - } - const txInMempool = mempool.getMempool()[txId]; - if (txInMempool && addPrevout) { - return this.$addPrevouts(txInMempool); - } - const transaction: IBitcoinApi.Transaction = await this.electrumClient.blockchainTransaction_get(txId, true); - if (!transaction) { - throw new Error('Unable to get transaction: ' + txId); - } - if (skipConversion) { - // @ts-ignore - return transaction; - } - return this.$convertTransaction(transaction, addPrevout); - } - async $getAddress(address: string): Promise { const addressInfo = await this.$validateAddress(address); if (!addressInfo || !addressInfo.isvalid) { diff --git a/backend/src/api/blocks.ts b/backend/src/api/blocks.ts index e567fb459..3e4d3466e 100644 --- a/backend/src/api/blocks.ts +++ b/backend/src/api/blocks.ts @@ -67,23 +67,6 @@ class Blocks { let transactionsFound = 0; for (let i = 0; i < txIds.length; i++) { - // When using bitcoind, just fetch the coinbase tx for now - if (config.MEMPOOL.BACKEND !== 'esplora' && i === 0) { - let txFound = false; - let findCoinbaseTxTries = 0; - // It takes Electrum Server a few seconds to index the transaction after a block is found - while (findCoinbaseTxTries < 5 && !txFound) { - try { - const tx = await transactionUtils.$getTransactionExtended(txIds[i]); - txFound = true; - transactions.push(tx); - } catch (e) { - logger.debug('Coinbase transaction fetch error: ' + e.message || e); - await Common.sleep(1000); - findCoinbaseTxTries++; - } - } - } if (mempool[txIds[i]]) { transactions.push(mempool[txIds[i]]); transactionsFound++; diff --git a/backend/src/api/mempool.ts b/backend/src/api/mempool.ts index cccb532e2..39d23b352 100644 --- a/backend/src/api/mempool.ts +++ b/backend/src/api/mempool.ts @@ -104,7 +104,7 @@ class Mempool { for (const txid of transactions) { if (!this.mempoolCache[txid]) { try { - const transaction = await transactionUtils.$getTransactionExtended(txid, true); + const transaction = await transactionUtils.$getTransactionExtended(txid); this.mempoolCache[txid] = transaction; txCount++; if (this.inSync) { diff --git a/backend/src/api/transaction-utils.ts b/backend/src/api/transaction-utils.ts index 471d9304f..8c6b89a6b 100644 --- a/backend/src/api/transaction-utils.ts +++ b/backend/src/api/transaction-utils.ts @@ -20,13 +20,8 @@ class TransactionUtils { }; } - public async $getTransactionExtended(txId: string, forceBitcoind = false, addPrevouts = false): Promise { - let transaction: IEsploraApi.Transaction; - if (forceBitcoind) { - transaction = await bitcoinApi.$getRawTransactionBitcoind(txId, false, addPrevouts); - } else { - transaction = await bitcoinApi.$getRawTransaction(txId, false, addPrevouts); - } + public async $getTransactionExtended(txId: string, addPrevouts = false): Promise { + const transaction: IEsploraApi.Transaction = await bitcoinApi.$getRawTransaction(txId, false, addPrevouts); return this.extendTransaction(transaction); } diff --git a/backend/src/api/websocket-handler.ts b/backend/src/api/websocket-handler.ts index 9c75d8369..0d758100c 100644 --- a/backend/src/api/websocket-handler.ts +++ b/backend/src/api/websocket-handler.ts @@ -220,7 +220,7 @@ class WebsocketHandler { if (tx) { if (config.MEMPOOL.BACKEND !== 'esplora') { try { - const fullTx = await transactionUtils.$getTransactionExtended(tx.txid, false, true); + const fullTx = await transactionUtils.$getTransactionExtended(tx.txid, true); response['tx'] = fullTx; } catch (e) { logger.debug('Error finding transaction in mempool: ' + e.message || e); @@ -240,7 +240,7 @@ class WebsocketHandler { if (someVin) { if (config.MEMPOOL.BACKEND !== 'esplora') { try { - const fullTx = await transactionUtils.$getTransactionExtended(tx.txid, false, true); + const fullTx = await transactionUtils.$getTransactionExtended(tx.txid, true); foundTransactions.push(fullTx); } catch (e) { logger.debug('Error finding transaction in mempool: ' + e.message || e); @@ -254,7 +254,7 @@ class WebsocketHandler { if (someVout) { if (config.MEMPOOL.BACKEND !== 'esplora') { try { - const fullTx = await transactionUtils.$getTransactionExtended(tx.txid, false, true); + const fullTx = await transactionUtils.$getTransactionExtended(tx.txid, true); foundTransactions.push(fullTx); } catch (e) { logger.debug('Error finding transaction in mempool: ' + e.message || e); @@ -305,7 +305,7 @@ class WebsocketHandler { const rbfTx = rbfTransactions[rbfTransaction]; if (config.MEMPOOL.BACKEND !== 'esplora') { try { - const fullTx = await transactionUtils.$getTransactionExtended(rbfTransaction, false, true); + const fullTx = await transactionUtils.$getTransactionExtended(rbfTransaction, true); response['rbfTransaction'] = fullTx; } catch (e) { logger.debug('Error finding transaction in mempool: ' + e.message || e); diff --git a/backend/src/config.ts b/backend/src/config.ts index 7c559026f..d6546284a 100644 --- a/backend/src/config.ts +++ b/backend/src/config.ts @@ -16,7 +16,6 @@ interface IConfig { HOST: string; PORT: number; TLS_ENABLED: boolean; - TX_LOOKUPS: boolean; }; CORE_RPC: { HOST: string; @@ -76,7 +75,6 @@ const defaults: IConfig = { 'HOST': '127.0.0.1', 'PORT': 3306, 'TLS_ENABLED': true, - 'TX_LOOKUPS': false }, 'CORE_RPC': { 'HOST': '127.0.0.1', diff --git a/backend/src/routes.ts b/backend/src/routes.ts index fc0357bb2..425fa6620 100644 --- a/backend/src/routes.ts +++ b/backend/src/routes.ts @@ -531,7 +531,7 @@ class Routes { public async getTransaction(req: Request, res: Response) { try { - const transaction = await transactionUtils.$getTransactionExtended(req.params.txId, false, true); + const transaction = await transactionUtils.$getTransactionExtended(req.params.txId, true); res.json(transaction); } catch (e) { let statusCode = 500; @@ -599,7 +599,7 @@ class Routes { const endIndex = Math.min(startingIndex + 10, txIds.length); for (let i = startingIndex; i < endIndex; i++) { try { - const transaction = await transactionUtils.$getTransactionExtended(txIds[i], false, true); + const transaction = await transactionUtils.$getTransactionExtended(txIds[i], true); transactions.push(transaction); loadingIndicators.setProgress('blocktxs-' + req.params.hash, (i + 1) / endIndex * 100); } catch (e) {