From f4fad9b8c54c0a5d293451b8eec5836072b7267e Mon Sep 17 00:00:00 2001 From: Pantamis Date: Mon, 3 Apr 2023 16:37:03 +0200 Subject: [PATCH 1/3] Add contributor agreement --- contributors/pantamis.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 contributors/pantamis.txt diff --git a/contributors/pantamis.txt b/contributors/pantamis.txt new file mode 100644 index 000000000..94bb5c312 --- /dev/null +++ b/contributors/pantamis.txt @@ -0,0 +1,3 @@ +I hereby accept the terms of the Contributor License Agreement in the CONTRIBUTING.md file of the mempool/mempool git repository as of 03 April, 2023. + +Signed: pantamis From e6ab91d68f5b61b9c4da5d1a14535eee6358585c Mon Sep 17 00:00:00 2001 From: Pantamis Date: Mon, 3 Apr 2023 15:05:33 +0200 Subject: [PATCH 2/3] Support spending transactions with Core txospenderindex --- backend/src/api/bitcoin/bitcoin-api.ts | 39 +++++++++++++++---- backend/src/rpc-api/commands.ts | 1 + .../src/tasks/lightning/forensics.service.ts | 5 ++- 3 files changed, 35 insertions(+), 10 deletions(-) diff --git a/backend/src/api/bitcoin/bitcoin-api.ts b/backend/src/api/bitcoin/bitcoin-api.ts index e20fe9e34..de515ae1b 100644 --- a/backend/src/api/bitcoin/bitcoin-api.ts +++ b/backend/src/api/bitcoin/bitcoin-api.ts @@ -4,6 +4,7 @@ import { IBitcoinApi } from './bitcoin-api.interface'; import { IEsploraApi } from './esplora-api.interface'; import blocks from '../blocks'; import mempool from '../mempool'; +import indexer from '../../indexer'; import { TransactionExtended } from '../../mempool.interfaces'; class BitcoinApi implements AbstractBitcoinApi { @@ -150,15 +151,37 @@ class BitcoinApi implements AbstractBitcoinApi { async $getOutspends(txId: string): Promise { const outSpends: IEsploraApi.Outspend[] = []; const tx = await this.$getRawTransaction(txId, true, false); - for (let i = 0; i < tx.vout.length; i++) { - if (tx.status && tx.status.block_height === 0) { + if (indexer.isCoreIndexReady('txospenderindex') === null) { + for (let i = 0; i < tx.vout.length; i++) { + if (tx.status && tx.status.block_height === 0) { + outSpends.push({ + spent: false + }); + } else { + const txOut = await this.bitcoindClient.getTxOut(txId, i); + outSpends.push({ + spent: txOut === null, + }); + } + } + } else { + const batchedOutpoints = Array.from(Array(tx.vout.length).keys()).map(x =>({txid: txId, vout:x})); + const spendingsResume = await this.bitcoindClient.getTxSpendingPrevOut(batchedOutpoints); + for (const outpointStatus of spendingsResume) { + if (outpointStatus.spendingtxid === undefined) { + outSpends.push({spent: false}); + continue; + } + const spendingTx = await this.$getRawTransaction(outpointStatus.spendingtxid, true, false); + const inputIndex = spendingTx.vin.findIndex(x => x.txid === txId); outSpends.push({ - spent: false - }); - } else { - const txOut = await this.bitcoindClient.getTxOut(txId, i); - outSpends.push({ - spent: txOut === null, + spent: true, + txid: outpointStatus.spendingtxid, + vin: inputIndex, + status: { + confirmed: true, + } + }); } } diff --git a/backend/src/rpc-api/commands.ts b/backend/src/rpc-api/commands.ts index 78f5e12f4..58c4d21b0 100644 --- a/backend/src/rpc-api/commands.ts +++ b/backend/src/rpc-api/commands.ts @@ -51,6 +51,7 @@ module.exports = { getTxOut: 'gettxout', // bitcoind v0.7.0+ getTxOutProof: 'gettxoutproof', // bitcoind v0.11.0+ getTxOutSetInfo: 'gettxoutsetinfo', // bitcoind v0.7.0+ + getTxSpendingPrevOut: 'gettxspendingprevout', // bitcoind #24539 getUnconfirmedBalance: 'getunconfirmedbalance', // bitcoind v0.9.0+ getWalletInfo: 'getwalletinfo', // bitcoind v0.9.2+ help: 'help', diff --git a/backend/src/tasks/lightning/forensics.service.ts b/backend/src/tasks/lightning/forensics.service.ts index 7837cb4d5..58ed3f564 100644 --- a/backend/src/tasks/lightning/forensics.service.ts +++ b/backend/src/tasks/lightning/forensics.service.ts @@ -3,6 +3,7 @@ import logger from '../../logger'; import channelsApi from '../../api/explorer/channels.api'; import bitcoinApi from '../../api/bitcoin/bitcoin-api-factory'; import config from '../../config'; +import indexer from '../../indexer'; import { IEsploraApi } from '../../api/bitcoin/esplora-api.interface'; import { Common } from '../../api/common'; import { ILightningApi } from '../../api/lightning/lightning-api.interface'; @@ -29,7 +30,7 @@ class ForensicsService { try { logger.debug(`Running forensics scans`); - if (config.MEMPOOL.BACKEND === 'esplora') { + if (config.MEMPOOL.BACKEND === 'esplora' || indexer.isCoreIndexReady('txospenderindex')) { await this.$runClosedChannelsForensics(false); await this.$runOpenedChannelsForensics(); } @@ -66,7 +67,7 @@ class ForensicsService { */ public async $runClosedChannelsForensics(onlyNewChannels: boolean = false): Promise { - if (config.MEMPOOL.BACKEND !== 'esplora') { + if (config.MEMPOOL.BACKEND !== 'esplora' && indexer.isCoreIndexReady('txospenderindex') !== null) { return; } From 7d92a02a7f40fa60d6dfca7f0f5b6fd5cd35e2a5 Mon Sep 17 00:00:00 2001 From: Pantamis Date: Sun, 4 Feb 2024 10:36:10 +0100 Subject: [PATCH 3/3] fix: wrong merge of forensics.service.ts --- backend/src/tasks/lightning/forensics.service.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/backend/src/tasks/lightning/forensics.service.ts b/backend/src/tasks/lightning/forensics.service.ts index af92a4a6f..9019ad2af 100644 --- a/backend/src/tasks/lightning/forensics.service.ts +++ b/backend/src/tasks/lightning/forensics.service.ts @@ -64,7 +64,8 @@ class ForensicsService { └──────────────────┘ */ - +public async $runClosedChannelsForensics(onlyNewChannels: boolean = false): Promise { + // Only Esplora backend can retrieve spent transaction outputs if (config.MEMPOOL.BACKEND !== 'esplora' && indexer.isCoreIndexReady('txospenderindex') !== null) { return; }