From bb2448a1fd6a56286c174d0d4d7146237cb222be Mon Sep 17 00:00:00 2001 From: Ouziel Slama Date: Fri, 13 Dec 2024 15:54:37 +0000 Subject: [PATCH] Get transaction by batch when parsing mempoool --- .../counterpartycore/lib/mempool.py | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/counterparty-core/counterpartycore/lib/mempool.py b/counterparty-core/counterpartycore/lib/mempool.py index 65f469271..29f28139a 100644 --- a/counterparty-core/counterpartycore/lib/mempool.py +++ b/counterparty-core/counterpartycore/lib/mempool.py @@ -131,22 +131,22 @@ def parse_raw_mempool(db): timestamps = {} cursor = db.cursor() logger.debug(f"Found {len(raw_mempool)} transaction(s) in the mempool...") + txhash_list = [] for txid, tx_info in raw_mempool.items(): existing_tx_in_mempool = cursor.execute( "SELECT * FROM mempool WHERE tx_hash = ? LIMIT 1", (txid,) ).fetchone() if existing_tx_in_mempool: continue - try: - logger.trace(f"Getting raw transaction `{txid}` from the mempool...") - raw_tx = backend.bitcoind.getrawtransaction(txid) - raw_tx_list.append(raw_tx) - timestamps[txid] = tx_info["time"] - except exceptions.BitcoindRPCError as e: - if "No such mempool or blockchain transaction" in str(e): - pass - else: - raise e + txhash_list.append(txid) + timestamps[txid] = tx_info["time"] + + logger.debug(f"Getting {len(raw_tx_list)} raw transactions by batch from the mempool...") + raw_transactions_by_hash = backend.addrindexrs.getrawtransaction_batch( + txhash_list, skip_missing=True + ) + raw_tx_list = raw_transactions_by_hash.values() + logger.debug(f"Parsing {len(raw_tx_list)} transaction(s) from the mempool...") parse_mempool_transactions(db, raw_tx_list, timestamps) logger.debug("Raw mempool parsed successfully.")