feat(storage): add drain_above to ColdStorage + UnifiedStorage#38
Merged
feat(storage): add drain_above to ColdStorage + UnifiedStorage#38
Conversation
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>
Evalir
reviewed
Mar 9, 2026
Evalir
approved these changes
Mar 9, 2026
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>
drain_above to UnifiedStorage
Member
Author
|
@Evalir i have made this more complicated to avoid a class of concurrency issues |
Fraser999
requested changes
Mar 10, 2026
Contributor
Fraser999
left a comment
There was a problem hiding this comment.
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>
Fraser999
approved these changes
Mar 10, 2026
Evalir
approved these changes
Mar 10, 2026
Member
Evalir
left a comment
There was a problem hiding this comment.
Fraser addressed my comments, lgtm
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
drain_aboveas a nativeColdStoragetrait method with a default impl that composesget_latest_block+get_receipts_in_block+truncate_abovedrain_aboveatomically in each backend:MemColdBackend: holds write lock for entire operationMdbxColdBackend: single read-write transaction (read receipts + delete in one commit)SqlColdBackend: sequential reads + truncate (atomic via task runner's sequential write processing)DrainAbovevariant toColdWriteRequestanddrain_abovemethod onColdStorageHandleUnifiedStorage::drain_aboveto use the new atomic cold method instead of N separate reads +dispatch_truncateDrainedBlockstruct withheaderandreceiptsfieldstest_drain_above) and 3 integration tests0.6.4→0.6.5Resolves ENG-1978. Unblocks ENG-1968 (
ChainEvent::Reorgnotifications).Test plan
--all-featuresand--no-default-features) forsignet-cold,signet-cold-mdbx,signet-cold-sql,signet-storagecargo +nightly fmtcargo t -p signet-cold— mem conformance passes (includestest_drain_above)cargo t -p signet-cold-mdbx— MDBX conformance passescargo t -p signet-cold-sql --all-features— SQLite conformance passescargo t -p signet-storage— 5 tests pass including 3 newdrain_aboveintegration tests🤖 Generated with Claude Code