Disable support for Electrum TX lookups (require -txindex).

This commit is contained in:
softsimon 2021-01-24 04:15:06 +07:00
parent 5b268794af
commit 47a449e1d9
No known key found for this signature in database
GPG key ID: 488D7DCFB5A430D7
9 changed files with 10 additions and 55 deletions

View file

@ -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,

View file

@ -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"

View file

@ -43,25 +43,6 @@ class BitcoindElectrsApi extends BitcoinApi implements AbstractBitcoinApi {
});
}
async $getRawTransaction(txId: string, skipConversion = false, addPrevout = false): Promise<IEsploraApi.Transaction> {
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<IEsploraApi.Address> {
const addressInfo = await this.$validateAddress(address);
if (!addressInfo || !addressInfo.isvalid) {

View file

@ -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++;

View file

@ -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) {

View file

@ -20,13 +20,8 @@ class TransactionUtils {
};
}
public async $getTransactionExtended(txId: string, forceBitcoind = false, addPrevouts = false): Promise<TransactionExtended> {
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<TransactionExtended> {
const transaction: IEsploraApi.Transaction = await bitcoinApi.$getRawTransaction(txId, false, addPrevouts);
return this.extendTransaction(transaction);
}

View file

@ -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);

View file

@ -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',

View file

@ -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) {