Skip to content

db/snapshotsync: remove overlapping caplin state snapshots on retire - #22256

Merged
AskAlexSharov merged 3 commits into
mainfrom
awskii/caplin-state-seg-cleanup
Jul 6, 2026
Merged

AskAlexSharov merged 3 commits into
mainfrom
awskii/caplin-state-seg-cleanup

Conversation

@awskii

@awskii awskii commented Jul 6, 2026

Copy link
Copy Markdown
Member

Caplin state snapshots have no on-disk overlap cleanup. When a genesis-rooted superset (e.g. PendingDepositsDump 000000-020350) coexists with an interior 50k chunk it covers (020250-020300), both stay on disk and snapshots retire leaves a directory the publishable integrity check rejects as overlapping. Unlike block snapshots, caplin state has no merger to mark constituents for deletion, its segments are opened frozen so the refcount-based deletion path is skipped, and the recalcVisibleFiles subset check only hid a subset that sorted before its superset.

Changes

  • Add CaplinStateSnapshots.RemoveOverlaps: deletes state .seg/.idx files fully covered by a larger indexed segment of the same type.
  • Call it from doRetireCommand, after the block RemoveOverlaps.
  • Make the recalcVisibleFiles subset check symmetric so interior/trailing subsets are hidden from the visible list.
  • Make DirtySegment.closeAndRemoveFiles nil-safe for segments opened without an index.

Caplin state snapshots had no on-disk overlap cleanup. A genesis-rooted
superset (e.g. PendingDepositsDump 000000-020350) and an interior 50k
subset chunk it covers both stayed on disk, so `snapshots retire` left a
directory the publishable integrity check rejects as overlapping. Unlike
block snapshots, caplin state has no merger to set canDelete, its
segments are opened frozen so the refcount deletion path is skipped, and
recalcVisibleFiles' subset check only hid a subset that sorted before its
superset.

Add CaplinStateSnapshots.RemoveOverlaps to delete subset files covered by
a larger indexed segment, call it from doRetireCommand, make the
recalcVisibleFiles subset check symmetric, and make closeAndRemoveFiles
nil-safe for segments opened without an index.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses on-disk overlap cleanup for Caplin state snapshots during snapshots retire, ensuring publishable integrity checks don’t fail when a genesis-rooted “superset” segment coexists with fully-covered subset segments.

Changes:

  • Add CaplinStateSnapshots.RemoveOverlaps() to delete fully-covered subset .seg/.idx pairs when a larger indexed segment of the same type exists.
  • Fix CaplinStateSnapshots.recalcVisibleFiles() to symmetrically hide subset ranges regardless of sort order.
  • Add CLI wiring to invoke caplin-state overlap cleanup during retire, and add regression tests.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
db/snapshotsync/snapshots.go Makes closeAndRemoveFiles tolerate nil index entries (but see review comment about closeIdx()).
db/snapshotsync/caplin_state_snapshots.go Adds overlap-removal logic and improves subset hiding in visible segment recalculation.
db/snapshotsync/caplin_state_overlap_test.go Adds tests reproducing and preventing caplin-state overlap and missing-index scenarios.
cmd/utils/app/snapshots_cmd.go Calls caplin-state overlap cleanup from snapshots retire.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread db/snapshotsync/snapshots.go
@awskii awskii added the Caplin Caplin: Consensus Layer, Beacon API label Jul 6, 2026
@awskii awskii added this to the 3.6.0 milestone Jul 6, 2026
@awskii
awskii enabled auto-merge July 6, 2026 08:39
@awskii
awskii added this pull request to the merge queue Jul 6, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jul 6, 2026
@AskAlexSharov
AskAlexSharov enabled auto-merge July 6, 2026 12:27
@AskAlexSharov
AskAlexSharov added this pull request to the merge queue Jul 6, 2026
Merged via the queue into main with commit e21f40c Jul 6, 2026
91 checks passed
@AskAlexSharov
AskAlexSharov deleted the awskii/caplin-state-seg-cleanup branch July 6, 2026 15:27
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Caplin Caplin: Consensus Layer, Beacon API

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants