Skip to content

feat(storage): add drain_above to ColdStorage + UnifiedStorage#38

Merged
prestwich merged 3 commits intomainfrom
james/eng-1978
Mar 11, 2026
Merged

feat(storage): add drain_above to ColdStorage + UnifiedStorage#38
prestwich merged 3 commits intomainfrom
james/eng-1978

Conversation

@prestwich
Copy link
Member

@prestwich prestwich commented Mar 9, 2026

Summary

  • Adds drain_above as a native ColdStorage trait method with a default impl that composes get_latest_block + get_receipts_in_block + truncate_above
  • Overrides drain_above atomically in each backend:
    • MemColdBackend: holds write lock for entire operation
    • MdbxColdBackend: single read-write transaction (read receipts + delete in one commit)
    • SqlColdBackend: sequential reads + truncate (atomic via task runner's sequential write processing)
  • Adds DrainAbove variant to ColdWriteRequest and drain_above method on ColdStorageHandle
  • Simplifies UnifiedStorage::drain_above to use the new atomic cold method instead of N separate reads + dispatch_truncate
  • Adds DrainedBlock struct with header and receipts fields
  • Adds conformance test (test_drain_above) and 3 integration tests
  • Bumps workspace version 0.6.40.6.5

Resolves ENG-1978. Unblocks ENG-1968 (ChainEvent::Reorg notifications).

Test plan

  • Clippy clean (--all-features and --no-default-features) for signet-cold, signet-cold-mdbx, signet-cold-sql, signet-storage
  • cargo +nightly fmt
  • cargo t -p signet-cold — mem conformance passes (includes test_drain_above)
  • cargo t -p signet-cold-mdbx — MDBX conformance passes
  • cargo t -p signet-cold-sql --all-features — SQLite conformance passes
  • cargo t -p signet-storage — 5 tests pass including 3 new drain_above integration tests

🤖 Generated with Claude Code

Adds `DrainedBlock` type and `drain_above` method that reads removed
block headers and receipts before unwinding, enabling reorg notifications.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@prestwich prestwich requested a review from Evalir March 9, 2026 17:36
Add `drain_above` as a native `ColdStorage` trait method that atomically
reads receipts and truncates in one operation. Each backend overrides
with its own atomic version:

- MemColdBackend: holds write lock for entire operation
- MdbxColdBackend: single read-write transaction
- SqlColdBackend: sequential reads + truncate (atomic via task runner)

Update `UnifiedStorage::drain_above` to use the new atomic cold method
instead of N separate reads + dispatch_truncate. Add conformance test
and integration tests.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@prestwich prestwich changed the title feat(storage): add drain_above to UnifiedStorage feat(storage): add to + Mar 9, 2026
@prestwich prestwich changed the title feat(storage): add to + feat(storage): add drain_above to ColdStorage + UnifiedStorage Mar 9, 2026
@prestwich prestwich requested a review from Evalir March 9, 2026 18:12
@prestwich
Copy link
Member Author

@Evalir i have made this more complicated to avoid a class of concurrency issues

Copy link
Contributor

@Fraser999 Fraser999 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just blocking due to the potential TOCTOU issue. Mostly nitpicks otherwise.

- Use single writer tx in `drain_above` to eliminate TOCTOU race
- Extract `collect_headers_above` / `delete_blocks` helpers in MDBX
  backend to deduplicate `truncate_above_inner` and `drain_above_inner`
- Remove redundant `drain_above` override in SQL backend (identical to
  default trait impl)
- Fix stale doc comment on step 4
- Add cold storage assertions to drain tests

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Member

@Evalir Evalir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fraser addressed my comments, lgtm

@prestwich prestwich merged commit 08f3c12 into main Mar 11, 2026
6 checks passed
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.

3 participants