From eade3f9b2e538256f0b765ecd9684aa142e2d6e7 Mon Sep 17 00:00:00 2001 From: Ouziel Slama Date: Sun, 5 Jan 2025 16:55:13 +0000 Subject: [PATCH] Clean transaction not in the mempool --- counterparty-core/counterpartycore/lib/mempool.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/counterparty-core/counterpartycore/lib/mempool.py b/counterparty-core/counterpartycore/lib/mempool.py index 9d10e984d..deed57813 100644 --- a/counterparty-core/counterpartycore/lib/mempool.py +++ b/counterparty-core/counterpartycore/lib/mempool.py @@ -2,7 +2,7 @@ import logging import time -from counterpartycore.lib import blocks, config, deserialize, exceptions, ledger, util +from counterpartycore.lib import backend, blocks, config, deserialize, exceptions, ledger, util from counterpartycore.lib.api.api_watcher import EVENTS_ADDRESS_FIELDS logger = logging.getLogger(config.LOGGER_NAME) @@ -119,7 +119,7 @@ def clean_transaction_events(db, tx_hash): def clean_mempool(db): - logger.debug("Cleaning mempool...") + logger.debug("Remove validated transactions from mempool...") cursor = db.cursor() cursor.execute("SELECT * FROM mempool") mempool_events = cursor.fetchall() @@ -128,3 +128,11 @@ def clean_mempool(db): tx = ledger.get_transaction(db, event["tx_hash"]) if tx: clean_transaction_events(db, event["tx_hash"]) + # remove transactions removed from the mempool + logger.debug("Remove transactions removed from the mempool...") + cursor.execute("SELECT distinct tx_hash FROM mempool") + tx_hashes = cursor.fetchall() + raw_mempool = backend.bitcoind.getrawmempool(verbose=False) + for tx_hash in tx_hashes: + if tx_hash["tx_hash"] not in raw_mempool: + clean_transaction_events(db, tx_hash["tx_hash"])