Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #2318

Merged
merged 21 commits into from
Oct 9, 2024
Merged

Fixes #2318

Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions counterparty-core/counterpartycore/lib/api/api_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
from flask_httpauth import HTTPBasicAuth
from sentry_sdk import capture_exception
from sentry_sdk import configure_scope as configure_sentry_scope
from sentry_sdk import start_span as start_sentry_span

multiprocessing.set_start_method("spawn", force=True)

Expand Down Expand Up @@ -203,9 +204,16 @@
) and not request.path.startswith("/v2/blocks/last"):
cache_key = request.url

if cache_key in BLOCK_CACHE:
result = BLOCK_CACHE[cache_key]
else:
with start_sentry_span(op="cache.get") as sentry_get_span:
sentry_get_span.set_data("cache.key", cache_key)
if cache_key in BLOCK_CACHE:

Check warning

Code scanning / pylint

Unnecessary "else" after "return", remove the "else" and de-indent the code inside it.

Unnecessary "else" after "return", remove the "else" and de-indent the code inside it.
result = BLOCK_CACHE[cache_key]
sentry_get_span.set_data("cache.hit", True)
return result
else:
sentry_get_span.set_data("cache.hit", False)

with start_sentry_span(op="cache.put") as sentry_put_span:
if function_needs_db(route["function"]):
result = route["function"](db, **function_args)
else:
Expand All @@ -216,11 +224,12 @@
and route["function"].__name__ != "redirect_to_api_v1"
and not request.path.startswith("/v2/mempool/")
):
sentry_put_span.set_data("cache.key", cache_key)
BLOCK_CACHE[cache_key] = result
if len(BLOCK_CACHE) > MAX_BLOCK_CACHE_SIZE:
BLOCK_CACHE.popitem(last=False)

return result
return result


def get_transaction_name(rule):
Expand Down
14 changes: 1 addition & 13 deletions counterparty-core/counterpartycore/lib/api/api_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -817,19 +817,7 @@ def get_running_info():
else:
caught_up = True

try:
cursor = db.cursor()
blocks = list(
cursor.execute(
"""SELECT * FROM blocks WHERE block_index = ?""",
(util.CURRENT_BLOCK_INDEX,),
)
)
assert len(blocks) == 1
last_block = blocks[0]
cursor.close()
except: # noqa: E722
last_block = None
last_block = ledger.get_last_block(db)

try:
last_message = ledger.last_message(db)
Expand Down
13 changes: 9 additions & 4 deletions counterparty-core/counterpartycore/lib/api/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from counterpartycore.lib import config
from counterpartycore.lib.api.util import divide
from flask import request
from sentry_sdk import start_span as start_sentry_span

OrderStatus = Literal["all", "open", "expired", "filled", "cancelled"]
OrderMatchesStatus = Literal["all", "pending", "completed", "expired"]
Expand Down Expand Up @@ -279,11 +280,15 @@ def select_rows(
query = f"{query} OFFSET ?"
bindings.append(offset)

cursor.execute(query, bindings)
result = cursor.fetchall()
with start_sentry_span(op="db.sql.execute", description=query) as sql_span:
sql_span.set_tag("db.system", "sqlite3")
cursor.execute(query, bindings)
result = cursor.fetchall()

cursor.execute(query_count, bindings_count)
result_count = cursor.fetchone()["count"]
with start_sentry_span(op="db.sql.execute", description=query_count) as sql_span:
sql_span.set_tag("db.system", "sqlite3")
cursor.execute(query_count, bindings_count)
result_count = cursor.fetchone()["count"]

if result and len(result) > limit:
next_cursor = result[-1][cursor_field]
Expand Down
1 change: 1 addition & 0 deletions counterparty-core/counterpartycore/lib/sentry.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def before_send(event, _hint):
event["tags"].append(["docker", data["dockerized"]])
event["tags"].append(["network", data["network"]])
event["tags"].append(["force_enabled", data["force_enabled"]])
event["tags"].append(["network", config.NETWORK_NAME])

event["extra"] = event.get("extra", {})
event["extra"]["last_block"] = data["last_block"]
Expand Down
20 changes: 10 additions & 10 deletions counterparty-core/counterpartycore/protocol_changes.json
Original file line number Diff line number Diff line change
Expand Up @@ -538,70 +538,70 @@
"enable_dispense_tx": {
"minimum_version_major": 10,
"minimum_version_minor": 4,
"minimum_version_revision": 0,
"minimum_version_revision": 4,
"block_index": 866000,
"testnet_block_index": 2925800
},
"disable_vanilla_btc_dispense": {
"minimum_version_major": 10,
"minimum_version_minor": 4,
"minimum_version_revision": 0,
"minimum_version_revision": 4,
"block_index": 866000,
"testnet_block_index": 2925800
},
"dispenser_must_be_created_by_source": {
"minimum_version_major": 10,
"minimum_version_minor": 4,
"minimum_version_revision": 0,
"minimum_version_revision": 4,
"block_index": 866000,
"testnet_block_index": 2925800
},
"expire_order_matches_then_orders": {
"minimum_version_major": 10,
"minimum_version_minor": 4,
"minimum_version_revision": 0,
"minimum_version_revision": 4,
"block_index": 866000,
"testnet_block_index": 2925800
},
"fairminter": {
"minimum_version_major": 10,
"minimum_version_minor": 4,
"minimum_version_revision": 0,
"minimum_version_revision": 4,
"block_index": 866000,
"testnet_block_index": 2925800
},
"lockable_issuance_descriptions": {
"minimum_version_major": 10,
"minimum_version_minor": 4,
"minimum_version_revision": 0,
"minimum_version_revision": 4,
"block_index": 866000,
"testnet_block_index": 2925800
},
"utxo_support": {
"minimum_version_major": 10,
"minimum_version_minor": 4,
"minimum_version_revision": 0,
"minimum_version_revision": 4,
"block_index": 866000,
"testnet_block_index": 2925800
},
"free_subassets": {
"minimum_version_major": 10,
"minimum_version_minor": 4,
"minimum_version_revision": 0,
"minimum_version_revision": 4,
"block_index": 866000,
"testnet_block_index": 2925800
},
"allow_subassets_on_numerics": {
"minimum_version_major": 10,
"minimum_version_minor": 4,
"minimum_version_revision": 0,
"minimum_version_revision": 4,
"block_index": 866000,
"testnet_block_index": 2925800
},
"fix_min_btc_quantity": {
"minimum_version_major": 10,
"minimum_version_minor": 4,
"minimum_version_revision": 0,
"minimum_version_revision": 4,
"block_index": 866000,
"testnet_block_index": 2925800
},
Expand Down
4 changes: 4 additions & 0 deletions release-notes/release-notes-v10.4.4.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
## Bugfixes

- Properly handle invalid scripts in outputs
- Bump Minimum Version to v10.4.4 for Block Index >= 866,000
- Fix `last_block` in `get_running_info` command (API v1)

## Codebase

Expand All @@ -20,6 +22,8 @@
## CLI

- Add `wsgi-server` (`werkzeug` or `gunicorn`) and `gunicorn-workers` flags
- Enable Sentry Caches and Queries pages
- Add `network` Sentry tag (`mainnet`, `testnet` or `regtest`)

# Credits

Expand Down
Loading