diff --git a/backend/src/api/blocks.ts b/backend/src/api/blocks.ts index 472ef48ef..8292fe241 100644 --- a/backend/src/api/blocks.ts +++ b/backend/src/api/blocks.ts @@ -101,12 +101,23 @@ class Blocks { transactions.push(tx); transactionsFetched++; } catch (e) { - if (i === 0) { - const msg = `Cannot fetch coinbase tx ${txIds[i]}. Reason: ` + (e instanceof Error ? e.message : e); - logger.err(msg); - throw new Error(msg); - } else { - logger.err(`Cannot fetch tx ${txIds[i]}. Reason: ` + (e instanceof Error ? e.message : e)); + try { + if (config.MEMPOOL.BACKEND === 'esplora') { + // Try again with core + const tx = await transactionUtils.$getTransactionExtended(txIds[i], false, false, true); + transactions.push(tx); + transactionsFetched++; + } else { + throw e; + } + } catch (e) { + if (i === 0) { + const msg = `Cannot fetch coinbase tx ${txIds[i]}. Reason: ` + (e instanceof Error ? e.message : e); + logger.err(msg); + throw new Error(msg); + } else { + logger.err(`Cannot fetch tx ${txIds[i]}. Reason: ` + (e instanceof Error ? e.message : e)); + } } } } diff --git a/backend/src/api/transaction-utils.ts b/backend/src/api/transaction-utils.ts index 5b92cea5f..5da168584 100644 --- a/backend/src/api/transaction-utils.ts +++ b/backend/src/api/transaction-utils.ts @@ -3,6 +3,7 @@ import { TransactionExtended, TransactionMinerInfo } from '../mempool.interfaces import { IEsploraApi } from './bitcoin/esplora-api.interface'; import config from '../config'; import { Common } from './common'; +import bitcoinClient from './bitcoin/bitcoin-client'; class TransactionUtils { constructor() { } @@ -21,8 +22,19 @@ class TransactionUtils { }; } - public async $getTransactionExtended(txId: string, addPrevouts = false, lazyPrevouts = false): Promise { - const transaction: IEsploraApi.Transaction = await bitcoinApi.$getRawTransaction(txId, false, addPrevouts, lazyPrevouts); + /** + * @param txId + * @param addPrevouts + * @param lazyPrevouts + * @param forceCore - See https://github.com/mempool/mempool/issues/2904 + */ + public async $getTransactionExtended(txId: string, addPrevouts = false, lazyPrevouts = false, forceCore = false): Promise { + let transaction: IEsploraApi.Transaction; + if (forceCore === true) { + transaction = await bitcoinClient.$getRawTransaction(txId, true); + } else { + transaction = await bitcoinApi.$getRawTransaction(txId, false, addPrevouts, lazyPrevouts); + } return this.extendTransaction(transaction); }