Skip to content

Commit

Permalink
Tweak Logging
Browse files Browse the repository at this point in the history
  • Loading branch information
adamkrellenstein committed Dec 13, 2024
1 parent d6e8e89 commit 7c5b89c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
22 changes: 14 additions & 8 deletions counterparty-core/counterpartycore/lib/backend/bitcoind.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def rpc_call(payload, retry=0):
"""Calls to bitcoin core and returns the response"""
url = config.BACKEND_URL
response = None
start_time = time.time()

tries = 0
broken_error = None
Expand Down Expand Up @@ -78,26 +79,31 @@ def rpc_call(payload, retry=0):

# Batch query returns a list
if isinstance(response_json, list):
return response_json
if "error" not in response_json.keys() or response_json["error"] is None: # noqa: E711
return response_json["result"]
if response_json["error"]["code"] == -5: # RPC_INVALID_ADDRESS_OR_KEY
result = response_json
elif "error" not in response_json.keys() or response_json["error"] is None: # noqa: E711
result = response_json["result"]
elif response_json["error"]["code"] == -5: # RPC_INVALID_ADDRESS_OR_KEY
raise exceptions.BitcoindRPCError(
f"{response_json['error']} Is `txindex` enabled in {config.BTC_NAME} Core?"
)
if response_json["error"]["code"] in [-28, -8, -2]:
# Verifying blocks... or Block height out of range or The network does not appear to fully agree!
elif response_json["error"]["code"] in [-28, -8, -2]:
# "Verifying blocks..." or "Block height out of range" or "The network does not appear to fully agree!"
logger.debug(f"Backend not ready. Sleeping for ten seconds. ({response_json['error']})")
logger.debug(f"Payload: {payload}")
if retry >= 10:
raise exceptions.BitcoindRPCError(
f"Backend not ready after {retry} retries. ({response_json['error']})"
)
# If Bitcoin Core takes more than `sys.getrecursionlimit() * 10 = 9970`
# seconds to start, thisll hit the maximum recursion depth limit.
# seconds to start, this'll hit the maximum recursion depth limit.
time.sleep(10)
return rpc_call(payload, retry=retry + 1)
raise exceptions.BitcoindRPCError(response_json["error"]["message"])
else:
raise exceptions.BitcoindRPCError(response_json["error"]["message"])

elapsed = time.time() - start_time
logger.trace(f"Bitcoin Core RPC call {payload['method']} took {elapsed:.3f}s")
return result


def rpc(method, params):
Expand Down
10 changes: 5 additions & 5 deletions counterparty-core/counterpartycore/lib/mempool.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def parse_mempool_transactions(db, raw_tx_list, timestamps=None):
# save the events in memory
transaction_events = cursor.fetchall()
# we raise an exception to rollback the transaction
raise exceptions.MempoolError("Mempool transaction parsed successfully")
raise exceptions.MempoolError("Mempool transaction parsed successfully.")
except exceptions.MempoolError:
# save events in the mempool table
for event in transaction_events:
Expand All @@ -103,7 +103,7 @@ def parse_mempool_transactions(db, raw_tx_list, timestamps=None):
)""",
event,
)
logger.trace("Mempool transaction parsed successfully")
logger.trace("Mempool transaction parsed successfully.")
util.PARSING_MEMPOOL = False


Expand All @@ -130,15 +130,15 @@ def parse_raw_mempool(db):
raw_tx_list = []
timestamps = {}
cursor = db.cursor()
logger.debug(f"{len(raw_mempool)} transaction(s) in the mempool...")
logger.debug(f"Found {len(raw_mempool)} transaction(s) in the mempool...")
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...")
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"]
Expand All @@ -149,4 +149,4 @@ def parse_raw_mempool(db):
raise e
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")
logger.debug("Raw mempool parsed successfully.")
2 changes: 1 addition & 1 deletion release-notes/release-notes-v10.8.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ This upgrade requires a mandatory, automatic reparse from block 871780.
- Use `multiprocessing.Event` to stop API process when the Ledger process dies
- Catch up with RPC when ZMQ is late
- Restart RSFetcher when it returns None too many times
- Exclude transaction with SIGHASH
- Exclude transactions by `SIGHASH`
- Add several checkpoints
- Be able to trigger a rollback on minor version change

Expand Down

0 comments on commit 7c5b89c

Please sign in to comment.