Skip to content

fix(cold-sql): pool starvation and query inefficiencies#45

Open
prestwich wants to merge 7 commits intomainfrom
prestwich/fix-cold-sql-pool-and-queries
Open

fix(cold-sql): pool starvation and query inefficiencies#45
prestwich wants to merge 7 commits intomainfrom
prestwich/fix-cold-sql-pool-and-queries

Conversation

@prestwich
Copy link
Copy Markdown
Member

Summary

Fixes ENG-2124

  • Pool configuration: 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) with acquire_timeout(5s). Adds PoolOverrides struct and SqlConnector builder for production tunability.
  • get_logs optimization: Replace COUNT(*) + SELECT with single LIMIT query — faster in both under-limit and over-limit cases.
  • get_receipt consolidation: Merge 5 sequential queries (header, receipt+tx, logs, prior gas) into 2-3 via combined JOIN with COALESCE subquery.
  • drain_above batch override: Replace default N+1 implementation (3N+7 queries) with batched single-transaction approach (9 queries regardless of block count).
  • Integer safety: Debug assertions on to_i64/from_i64, checked tx_type conversion throughout.

Test plan

  • cargo t -p signet-cold-sql --all-features — SQLite + PG conformance passing
  • cargo clippy -p signet-cold-sql --all-features --all-targets — clean
  • cargo clippy -p signet-cold-sql --no-default-features --all-targets — clean
  • cargo clippy --workspace --all-features --all-targets — clean
  • cargo +nightly fmt — clean
  • ./scripts/test-postgres.sh — PostgreSQL conformance against real database

🤖 Generated with Claude Code

prestwich and others added 7 commits April 3, 2026 14:58
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>
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.

1 participant