Skip to content

Commit

Permalink
Catch OverflowError on API calls
Browse files Browse the repository at this point in the history
  • Loading branch information
ouziel-slama authored and Ouziel committed Jan 6, 2025
2 parents de3b3e7 + eade3f9 commit 6668c5e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
6 changes: 3 additions & 3 deletions counterparty-core/counterpartycore/lib/api/api_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,10 +360,10 @@ def handle_route(**kwargs):
CBitcoinAddressError,
script.AddressError,
exceptions.ElectrsError,
OverflowError,
) as e:
import traceback

print(traceback.format_exc())
# import traceback
# print(traceback.format_exc())
return return_result(400, error=str(e), start_time=start_time, query_args=query_args)
except Exception as e:
capture_exception(e)
Expand Down
12 changes: 10 additions & 2 deletions counterparty-core/counterpartycore/lib/mempool.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand All @@ -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"])

0 comments on commit 6668c5e

Please sign in to comment.