Skip to content

fix(api): order /blocks by slot when slot-filtered; fix logger.warning crash - #1002

Merged
PJColombo merged 2 commits into
mainfrom
fix/blocks-slow-query-and-logger-warn
Jul 15, 2026
Merged

fix(api): order /blocks by slot when slot-filtered; fix logger.warning crash#1002
PJColombo merged 2 commits into
mainfrom
fix/blocks-slow-query-and-logger-warn

Conversation

@PabloCastellano

Copy link
Copy Markdown
Member

Checklist

  • [] My change requires a documentation update, and I have done it.
  • I have added tests to cover my changes.
  • I have filled out the description and linked the related issues.

Description

Two production issues in the REST API:

  1. GET /blocks with a slot range took ~9.5s and starved Prisma's connection pool. The query filtered on slot but ordered by number, so Postgres scanned the entire number index and discarded millions of out-of-range rows (EXPLAIN: block_number_idx scan, "Rows Removed by Filter: 2740916", 8.6s). Since slot and number are monotonically correlated, ordering by slot when a slot filter is present lets Postgres range-scan the slot index for both the predicate and the ordering. Verified: 8712ms -> 5.5ms, identical result order.

  2. The Matomo middleware called logger.warning() on tracking failure, but the winston logger only defines warn(). This threw "logger.warning is not a function" as an unhandled promise rejection, crashing the API process (observed 684 restarts in production). Use logger.warn().

Motivation and Context (Optional)

Related Issue (Optional)

Screenshots (if appropriate):

…g crash

Two production issues in the REST API:

1. GET /blocks with a slot range took ~9.5s and starved Prisma's connection
   pool. The query filtered on `slot` but ordered by `number`, so Postgres
   scanned the entire `number` index and discarded millions of out-of-range
   rows (EXPLAIN: block_number_idx scan, "Rows Removed by Filter: 2740916",
   8.6s). Since `slot` and `number` are monotonically correlated, ordering by
   `slot` when a slot filter is present lets Postgres range-scan the `slot`
   index for both the predicate and the ordering. Verified: 8712ms -> 5.5ms,
   identical result order.

2. The Matomo middleware called logger.warning() on tracking failure, but the
   winston logger only defines warn(). This threw "logger.warning is not a
   function" as an unhandled promise rejection, crashing the API process
   (observed 684 restarts in production). Use logger.warn().

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@changeset-bot

changeset-bot Bot commented Jul 15, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: ebe9261

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@blobscan/api Patch
@blobscan/rest-api-server Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions

Copy link
Copy Markdown
Contributor

📦 Next.js Bundle Analysis for @blobscan/web

This analysis was generated by the Next.js Bundle Analysis action. 🤖

This PR introduced no changes to the JavaScript bundle! 🙌

@codecov

codecov Bot commented Jul 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.47%. Comparing base (5edb7da) to head (ebe9261).
⚠️ Report is 6 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1002      +/-   ##
==========================================
+ Coverage   83.46%   83.47%   +0.01%     
==========================================
  Files         190      190              
  Lines       15081    15093      +12     
  Branches     1464     1466       +2     
==========================================
+ Hits        12587    12599      +12     
  Misses       2494     2494              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@PJColombo
PJColombo merged commit b954d1e into main Jul 15, 2026
7 checks passed
@PJColombo
PJColombo deleted the fix/blocks-slow-query-and-logger-warn branch July 15, 2026 13:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants