Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

snapshots: fix filesByRange (#9472) #9489

Merged
merged 1 commit into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions erigon-lib/downloader/snaptype/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,4 +325,13 @@ var (
BorSnapshotTypes = []Type{BorEvents, BorSpans}

CaplinSnapshotTypes = []Type{BeaconBlocks}

AllTypes = []Type{
Headers,
Bodies,
Transactions,
BorEvents,
BorSpans,
BeaconBlocks,
}
)
32 changes: 19 additions & 13 deletions turbo/snapshotsync/freezeblocks/block_snapshots.go
Original file line number Diff line number Diff line change
Expand Up @@ -2143,26 +2143,32 @@ func (m *Merger) FindMergeRanges(currentRanges []Range, maxBlockNum uint64) (toM

func (m *Merger) filesByRange(snapshots *RoSnapshots, from, to uint64) (map[snaptype.Enum][]string, error) {
toMerge := map[snaptype.Enum][]string{}

view := snapshots.View()
defer view.Close()

if _, first, ok := snapshots.segments.Min(); ok {
for i, sn := range first.segments {
if sn.from < from {
continue
}
if sn.to > to {
break
}
for _, t := range snaptype.AllTypes {
toMerge[t.Enum()] = m.filesByRangeOfType(view, from, to, t)
}

snapshots.segments.Scan(func(key snaptype.Enum, value *segments) bool {
toMerge[key] = append(toMerge[key], view.Segments(key.Type())[i].FilePath())
return true
})
return toMerge, nil
}

func (m *Merger) filesByRangeOfType(view *View, from, to uint64, snapshotType snaptype.Type) []string {
paths := make([]string, 0)

for _, sn := range view.Segments(snapshotType) {
if sn.from < from {
continue
}
if sn.to > to {
break
}

paths = append(paths, sn.FilePath())
}

return toMerge, nil
return paths
}

// Merge does merge segments in given ranges
Expand Down