fix(cold-sql): pool starvation and query inefficiencies#45
Open
fix(cold-sql): pool starvation and query inefficiencies#45
Conversation
Addresses single-connection pool starvation, query inefficiencies, and integer conversion safety in the PostgreSQL cold storage backend. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
6-task plan covering pool configuration, get_logs LIMIT optimization, get_receipt consolidation, drain_above batch override, and integer conversion safety. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Replace bare `as` casts in `to_i64`/`from_i64` with `debug_assert!` guards, and replace the truncating `i32 as u8` cast in `tx_from_row` with a checked `try_into()` that returns a proper error on out-of-range values. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…lder Add `PoolOverrides` and `SqlColdBackend::connect_with` so PostgreSQL defaults to 10 connections instead of 1, fixing write starvation under concurrent load. SQLite retains 1 connection (required for in-memory shared state). Add builder methods `with_max_connections` and `with_acquire_timeout` on `SqlConnector` for caller overrides. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
get_receipt: merge header, receipt+tx metadata, and prior cumulative gas into a single JOIN query with COALESCE subquery. Reduces 5 sequential queries to 2-3. drain_above: override default N+1 implementation with batched single-transaction approach. 9 queries regardless of block count vs 3N+7 in the default. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
New public API in signet-cold-sql: PoolOverrides, connect_with, SqlConnector builder methods. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
prestwich
added a commit
to init4tech/node-components
that referenced
this pull request
Apr 3, 2026
Update all signet-storage family crates (signet-storage, signet-cold, signet-hot, signet-hot-mdbx, signet-cold-mdbx, signet-storage-types) to 0.7 from init4tech/storage#45. Bump workspace version to 0.17.1. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes ENG-2124
SqlColdBackend::connect()created a single-connection pool for all backends including PostgreSQL, serializing 64 concurrent readers + 8 stream producers. Now uses per-backend defaults (SQLite: 1, PostgreSQL: 10) withacquire_timeout(5s). AddsPoolOverridesstruct andSqlConnectorbuilder for production tunability.get_logsoptimization: Replace COUNT(*) + SELECT with single LIMIT query — faster in both under-limit and over-limit cases.get_receiptconsolidation: Merge 5 sequential queries (header, receipt+tx, logs, prior gas) into 2-3 via combined JOIN with COALESCE subquery.drain_abovebatch override: Replace default N+1 implementation (3N+7 queries) with batched single-transaction approach (9 queries regardless of block count).to_i64/from_i64, checkedtx_typeconversion throughout.Test plan
cargo t -p signet-cold-sql --all-features— SQLite + PG conformance passingcargo clippy -p signet-cold-sql --all-features --all-targets— cleancargo clippy -p signet-cold-sql --no-default-features --all-targets— cleancargo clippy --workspace --all-features --all-targets— cleancargo +nightly fmt— clean./scripts/test-postgres.sh— PostgreSQL conformance against real database🤖 Generated with Claude Code