db/snapshotsync: resume caplin state dump per-type to avoid overlapping files#21901
Merged
Conversation
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
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.