From 2e6a0c0967caab96f52394ba55d0d98b33b0e978 Mon Sep 17 00:00:00 2001 From: Mononaut Date: Sun, 12 Feb 2023 21:17:14 -0600 Subject: [PATCH] Track and display purged transaction status --- backend/src/api/mempool.ts | 30 +++++++++++++++++++ backend/src/api/websocket-handler.ts | 9 ++++++ .../transaction/transaction.component.html | 4 +++ .../transaction/transaction.component.ts | 7 +++++ .../src/app/interfaces/websocket.interface.ts | 1 + frontend/src/app/services/state.service.ts | 1 + .../src/app/services/websocket.service.ts | 4 +++ 7 files changed, 56 insertions(+) diff --git a/backend/src/api/mempool.ts b/backend/src/api/mempool.ts index db5de82b2..6f8011a12 100644 --- a/backend/src/api/mempool.ts +++ b/backend/src/api/mempool.ts @@ -16,6 +16,7 @@ class Mempool { private inSync: boolean = false; private mempoolCacheDelta: number = -1; private mempoolCache: { [txId: string]: TransactionExtended } = {}; + private minFeeMempool: { [txId: string]: boolean } = {}; private mempoolInfo: IBitcoinApi.MempoolInfo = { loaded: false, size: 0, bytes: 0, usage: 0, total_fee: 0, maxmempool: 300000000, mempoolminfee: 0.00001000, minrelaytxfee: 0.00001000 }; private mempoolChangedCallback: ((newMempool: {[txId: string]: TransactionExtended; }, newTransactions: TransactionExtended[], @@ -124,6 +125,7 @@ class Mempool { let hasChange: boolean = false; const currentMempoolSize = Object.keys(this.mempoolCache).length; const transactions = await bitcoinApi.$getRawMempool(); + await this.updateMinFeeMempool(); const diff = transactions.length - currentMempoolSize; const newTransactions: TransactionExtended[] = []; @@ -232,6 +234,34 @@ class Mempool { logger.debug(`Mempool updated in ${time / 1000} seconds. New size: ${Object.keys(this.mempoolCache).length} (${diff > 0 ? '+' + diff : diff})`); } + public isTxPurged(txid: string): boolean { + return !this.minFeeMempool[txid]; + } + + private async updateMinFeeMempool() { + const minFeeTransactions = await bitcoinSecondClient.getRawMemPool(); + const minFeeTxMap = {}; + for (const txid of minFeeTransactions) { + minFeeTxMap[txid] = true; + } + const removed: string[] = []; + const added: string[] = []; + for (const txid of Object.keys(this.minFeeMempool)) { + if (!minFeeTxMap[txid]) { + removed.push(txid); + } + } + for (const txid of minFeeTransactions) { + if (!this.minFeeMempool[txid]) { + added.push(txid); + this.minFeeMempool[txid] = true; + } + } + for (const txid of removed) { + delete this.minFeeMempool[txid]; + } + } + public handleRbfTransactions(rbfTransactions: { [txid: string]: TransactionExtended; }) { for (const rbfTransaction in rbfTransactions) { if (this.mempoolCache[rbfTransaction]) { diff --git a/backend/src/api/websocket-handler.ts b/backend/src/api/websocket-handler.ts index c89179ce7..c122fb052 100644 --- a/backend/src/api/websocket-handler.ts +++ b/backend/src/api/websocket-handler.ts @@ -19,6 +19,7 @@ import BlocksAuditsRepository from '../repositories/BlocksAuditsRepository'; import BlocksSummariesRepository from '../repositories/BlocksSummariesRepository'; import Audit from './audit'; import { deepClone } from '../utils/clone'; +import mempool from './mempool'; import priceUpdater from '../tasks/price-updater'; import { ApiPrice } from '../repositories/PricesRepository'; @@ -92,6 +93,9 @@ class WebsocketHandler { } } } + if (config.MEMPOOL.USE_SECOND_NODE_FOR_MINFEE && memPool.getMempool()[client['track-tx']]) { + response['txPurged'] = memPool.isTxPurged(client['track-tx']); + } } else { client['track-tx'] = null; } @@ -395,6 +399,11 @@ class WebsocketHandler { } } } + + // update purge status of unconfirmed tracked txs + if (config.MEMPOOL.USE_SECOND_NODE_FOR_MINFEE && newMempool[client['track-tx']]) { + response['txPurged'] = memPool.isTxPurged(client['track-tx']); + } } if (client['track-mempool-block'] >= 0) { diff --git a/frontend/src/app/components/transaction/transaction.component.html b/frontend/src/app/components/transaction/transaction.component.html index 04d13b07a..840e53aa5 100644 --- a/frontend/src/app/components/transaction/transaction.component.html +++ b/frontend/src/app/components/transaction/transaction.component.html @@ -1,6 +1,10 @@
+ +