Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f12e451

Browse files
authored
snapshots: fix filesByRange (erigontech#9472) (erigontech#9489)
The method was iterating over snapshots.segments.Min().segments, but passing the index to view.Segments(). This might lead to a crash, because those 2 collections are different, and the indexes might not match. view.Segments() only contains the snapshot files that are fully downloaded and indexed. The code is changed to only use the view files (as it was before).
1 parent ab1ee7b commit f12e451

2 files changed

Lines changed: 28 additions & 13 deletions

File tree

erigon-lib/downloader/snaptype/type.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,4 +325,13 @@ var (
325325
BorSnapshotTypes = []Type{BorEvents, BorSpans}
326326

327327
CaplinSnapshotTypes = []Type{BeaconBlocks}
328+
329+
AllTypes = []Type{
330+
Headers,
331+
Bodies,
332+
Transactions,
333+
BorEvents,
334+
BorSpans,
335+
BeaconBlocks,
336+
}
328337
)

turbo/snapshotsync/freezeblocks/block_snapshots.go

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2143,26 +2143,32 @@ func (m *Merger) FindMergeRanges(currentRanges []Range, maxBlockNum uint64) (toM
21432143

21442144
func (m *Merger) filesByRange(snapshots *RoSnapshots, from, to uint64) (map[snaptype.Enum][]string, error) {
21452145
toMerge := map[snaptype.Enum][]string{}
2146+
21462147
view := snapshots.View()
21472148
defer view.Close()
21482149

2149-
if _, first, ok := snapshots.segments.Min(); ok {
2150-
for i, sn := range first.segments {
2151-
if sn.from < from {
2152-
continue
2153-
}
2154-
if sn.to > to {
2155-
break
2156-
}
2150+
for _, t := range snaptype.AllTypes {
2151+
toMerge[t.Enum()] = m.filesByRangeOfType(view, from, to, t)
2152+
}
21572153

2158-
snapshots.segments.Scan(func(key snaptype.Enum, value *segments) bool {
2159-
toMerge[key] = append(toMerge[key], view.Segments(key.Type())[i].FilePath())
2160-
return true
2161-
})
2154+
return toMerge, nil
2155+
}
2156+
2157+
func (m *Merger) filesByRangeOfType(view *View, from, to uint64, snapshotType snaptype.Type) []string {
2158+
paths := make([]string, 0)
2159+
2160+
for _, sn := range view.Segments(snapshotType) {
2161+
if sn.from < from {
2162+
continue
21622163
}
2164+
if sn.to > to {
2165+
break
2166+
}
2167+
2168+
paths = append(paths, sn.FilePath())
21632169
}
21642170

2165-
return toMerge, nil
2171+
return paths
21662172
}
21672173

21682174
// Merge does merge segments in given ranges

0 commit comments

Comments
 (0)