Merge pull request #2916 from mempool/nymkappa/bugfix/esplora-coinbase-tx
Fetch coinbase tx with core when esplora fails to do so
This commit is contained in:
commit
0d7c52817e
@ -1,10 +1,5 @@
|
|||||||
import config from '../config';
|
import config from '../config';
|
||||||
import bitcoinApi from './bitcoin/bitcoin-api-factory';
|
import { TransactionExtended, MempoolBlockWithTransactions } from '../mempool.interfaces';
|
||||||
import { Common } from './common';
|
|
||||||
import { TransactionExtended, MempoolBlockWithTransactions, AuditScore } from '../mempool.interfaces';
|
|
||||||
import blocksRepository from '../repositories/BlocksRepository';
|
|
||||||
import blocksAuditsRepository from '../repositories/BlocksAuditsRepository';
|
|
||||||
import blocks from '../api/blocks';
|
|
||||||
|
|
||||||
const PROPAGATION_MARGIN = 180; // in seconds, time since a transaction is first seen after which it is assumed to have propagated to all miners
|
const PROPAGATION_MARGIN = 180; // in seconds, time since a transaction is first seen after which it is assumed to have propagated to all miners
|
||||||
|
|
||||||
|
@ -17,4 +17,6 @@ function bitcoinApiFactory(): AbstractBitcoinApi {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const bitcoinCoreApi = new BitcoinApi(bitcoinClient);
|
||||||
|
|
||||||
export default bitcoinApiFactory();
|
export default bitcoinApiFactory();
|
||||||
|
@ -101,12 +101,23 @@ class Blocks {
|
|||||||
transactions.push(tx);
|
transactions.push(tx);
|
||||||
transactionsFetched++;
|
transactionsFetched++;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (i === 0) {
|
try {
|
||||||
const msg = `Cannot fetch coinbase tx ${txIds[i]}. Reason: ` + (e instanceof Error ? e.message : e);
|
if (config.MEMPOOL.BACKEND === 'esplora') {
|
||||||
logger.err(msg);
|
// Try again with core
|
||||||
throw new Error(msg);
|
const tx = await transactionUtils.$getTransactionExtended(txIds[i], false, false, true);
|
||||||
} else {
|
transactions.push(tx);
|
||||||
logger.err(`Cannot fetch tx ${txIds[i]}. Reason: ` + (e instanceof Error ? e.message : e));
|
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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
import bitcoinApi from './bitcoin/bitcoin-api-factory';
|
|
||||||
import { TransactionExtended, TransactionMinerInfo } from '../mempool.interfaces';
|
import { TransactionExtended, TransactionMinerInfo } from '../mempool.interfaces';
|
||||||
import { IEsploraApi } from './bitcoin/esplora-api.interface';
|
import { IEsploraApi } from './bitcoin/esplora-api.interface';
|
||||||
import config from '../config';
|
|
||||||
import { Common } from './common';
|
import { Common } from './common';
|
||||||
|
import bitcoinApi, { bitcoinCoreApi } from './bitcoin/bitcoin-api-factory';
|
||||||
|
|
||||||
class TransactionUtils {
|
class TransactionUtils {
|
||||||
constructor() { }
|
constructor() { }
|
||||||
@ -21,8 +20,19 @@ class TransactionUtils {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public async $getTransactionExtended(txId: string, addPrevouts = false, lazyPrevouts = false): Promise<TransactionExtended> {
|
/**
|
||||||
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<TransactionExtended> {
|
||||||
|
let transaction: IEsploraApi.Transaction;
|
||||||
|
if (forceCore === true) {
|
||||||
|
transaction = await bitcoinCoreApi.$getRawTransaction(txId, true);
|
||||||
|
} else {
|
||||||
|
transaction = await bitcoinApi.$getRawTransaction(txId, false, addPrevouts, lazyPrevouts);
|
||||||
|
}
|
||||||
return this.extendTransaction(transaction);
|
return this.extendTransaction(transaction);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user