db/snapshotsync: resume caplin state dump per-type to avoid overlapping files - #21901
Merged
Merged
Conversation
sudeepdino008
requested review from
AskAlexSharov,
domiwei and
yperbasis
as code owners
June 19, 2026 05:38
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes Caplin beacon-state snapshot dumping so it resumes per snapshot type rather than using a single global “from” slot, preventing already-covered types from being re-dumped into overlapping sub-files when a new snapshot type appears in an existing datadir.
Changes:
- Add per-type availability lookup (
blocksAvailableForType) and a deterministic per-type dump planner (planStateDump), then reworkDumpCaplinStateto execute that plan. - Remove the redundant
fromSlotargument fromDumpCaplinStateand update call sites. - Add focused tests for per-type resume planning and per-type availability semantics.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| db/snapshotsync/caplin_state_snapshots.go | Introduces per-type availability + planned dump jobs; updates DumpCaplinState to avoid overlapping files and to dump deterministically. |
| db/snapshotsync/caplin_state_dump_test.go | Adds unit tests for per-type resume planning and blocksAvailableForType last-segment semantics. |
| cmd/capcli/cli.go | Updates CLI call site to the new DumpCaplinState signature. |
| cl/antiquary/state_antiquary.go | Updates antiquary call site to the new DumpCaplinState signature. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
domiwei
reviewed
Jun 24, 2026
domiwei
left a comment
Member
There was a problem hiding this comment.
I left two correctness comments around per-type resume availability. Both are about avoiding new permanent gaps/overlaps in partial snapshot layouts.
domiwei
approved these changes
Jun 24, 2026
awskii
pushed a commit
that referenced
this pull request
Jul 8, 2026
…ng files (#21901) ### Problem When a new Caplin beacon-state snapshot type is added to an already-populated datadir (e.g. the GLOAS `BuilderPendingPayments` table), `seg publishable` starts failing with overlapping and/or short snapshot files. Root cause is in how state snapshots are dumped: - `BlocksAvailable()` reports the **minimum** `to` across *all* state types. A newly added type has no files, so the global available slot collapses to 0 (or to that one lagging type's progress). - `DumpCaplinState` used that single global `from` for **every** type and looped `outer over types, inner over slot ranges` with no per-type resume and no skip-if-exists. So a restart re-dumped already-caught-up types from the lagging floor, slicing their existing base file (e.g. `000000-007150`) into overlapping 50k sub-files, while the genuinely-new type never reliably caught up to head. Observed on a sepolia snapshotter: - `PendingDepositsDump` — clean layout **plus** spurious `000000-000050 … 001400-001450` files overlapping its `000000-007150` base. - `BuilderPendingPayments` — only reached 2.7M, never the head (10.4M). ### Fix Make the state dump resume **per-type** from each type's own coverage: - Add `blocksAvailableForType` — last visible segment `to` for a single type. - Add `planStateDump` — pure function that, given each type's availability and the target `to`, produces the per-type `[from,to)` dump jobs. A caught-up type yields no jobs (so its base file is never re-sliced); a new type still starts from genesis. - `DumpCaplinState` now builds per-type availability and dumps the plan; the redundant global `fromSlot` parameter is dropped (callers updated). This also makes dump order deterministic (sorted by type name) instead of relying on Go map iteration order. ### Tests - `TestPlanStateDumpResumesPerType` — covered types are not re-dumped, lagging types resume at their own availability, new/empty types start at 0. - `TestBlocksAvailableForType` — last-segment semantics. Written test-first (Red → Green); the initial failing version surfaced that a shared `fromSlot` floor would leave a genesis gap for brand-new types, which is why the parameter was removed. (cherry picked from commit 270a20b)
This was referenced Jul 8, 2026
AskAlexSharov
added a commit
that referenced
this pull request
Jul 8, 2026
…retire (#22317) Cherry-pick of #22256 (`e21f40c3dbab`) to `release/3.5`. ## r3.5-specific adaptations Also cherry-picks its prerequisite #21901 (`270a20b084`, `coveredRangesForType`) — not present on release/3.5, needed for the test to typecheck. --------- Co-authored-by: Alex Sharov <AskAlexSharov@gmail.com> Co-authored-by: moskud <sudeepdino008@gmail.com>
AskAlexSharov
added a commit
that referenced
this pull request
Jul 10, 2026
…ts (#22323) Backport of #22294 to `release/3.5`, stacked on #22317 (its caplin_state_snapshots.go base — #21901/#22256). Includes the fsync-grace-period removal. Retarget base to release/3.5 once #22317 merges. --------- Co-authored-by: Alex Sharov <AskAlexSharov@gmail.com> Co-authored-by: moskud <sudeepdino008@gmail.com>
awskii
added a commit
that referenced
this pull request
Jul 22, 2026
Main #22246 landed its own EL refcounted visible-generation retirement core (snapshotVisible), so adopt it for the block path as-is and drop this branch's generic visibleGenerations[P] and int CaplinStateType. Caplin keeps the reader-safe retirement it added — RemoveOverlaps defers the unlink while a live view pins the generation, and Close is drain-gated so it never closes fds an older pinned view still references — but now as a concrete caplin-local generation core over main's string-keyed model, preserving #21901's per-type dump planner and the string type API.
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.
Problem
When a new Caplin beacon-state snapshot type is added to an already-populated datadir (e.g. the GLOAS
BuilderPendingPaymentstable),seg publishablestarts failing with overlapping and/or short snapshot files.Root cause is in how state snapshots are dumped:
BlocksAvailable()reports the minimumtoacross all state types. A newly added type has no files, so the global available slot collapses to 0 (or to that one lagging type's progress).DumpCaplinStateused that single globalfromfor every type and loopedouter over types, inner over slot rangeswith no per-type resume and no skip-if-exists.So a restart re-dumped already-caught-up types from the lagging floor, slicing their existing base file (e.g.
000000-007150) into overlapping 50k sub-files, while the genuinely-new type never reliably caught up to head. Observed on a sepolia snapshotter:PendingDepositsDump— clean layout plus spurious000000-000050 … 001400-001450files overlapping its000000-007150base.BuilderPendingPayments— only reached 2.7M, never the head (10.4M).Fix
Make the state dump resume per-type from each type's own coverage:
blocksAvailableForType— last visible segmenttofor a single type.planStateDump— pure function that, given each type's availability and the targetto, produces the per-type[from,to)dump jobs. A caught-up type yields no jobs (so its base file is never re-sliced); a new type still starts from genesis.DumpCaplinStatenow builds per-type availability and dumps the plan; the redundant globalfromSlotparameter is dropped (callers updated).This also makes dump order deterministic (sorted by type name) instead of relying on Go map iteration order.
Tests
TestPlanStateDumpResumesPerType— covered types are not re-dumped, lagging types resume at their own availability, new/empty types start at 0.TestBlocksAvailableForType— last-segment semantics.Written test-first (Red → Green); the initial failing version surfaced that a shared
fromSlotfloor would leave a genesis gap for brand-new types, which is why the parameter was removed.