From 2b873ffd51803881f891a4b95aac1d954d187632 Mon Sep 17 00:00:00 2001 From: Alex Sharov Date: Tue, 24 Sep 2024 15:51:31 +0200 Subject: [PATCH] block files: idxAvailability must rely on visibleFiles instead of atomics (#12078) reason: visible files guarantee consistency - between file types (because hide under same mutex). `maxVisibleBlock` atomic - doesn't give such guaranty (mutex doesn't guard them). for: https://github.com/erigontech/erigon/issues/12069 --- turbo/snapshotsync/freezeblocks/block_snapshots.go | 6 ++++-- turbo/snapshotsync/freezeblocks/caplin_snapshots.go | 4 +++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/turbo/snapshotsync/freezeblocks/block_snapshots.go b/turbo/snapshotsync/freezeblocks/block_snapshots.go index 44c67a86f2e..616579ba6ef 100644 --- a/turbo/snapshotsync/freezeblocks/block_snapshots.go +++ b/turbo/snapshotsync/freezeblocks/block_snapshots.go @@ -663,8 +663,10 @@ func (s *RoSnapshots) idxAvailability() uint64 { if !s.HasType(segtype.Type()) { return true } - maxIdx = value.maxVisibleBlock.Load() - return false // all types of segments have the same height. stop here + if len(value.VisibleSegments) > 0 { + maxIdx = value.VisibleSegments[len(value.VisibleSegments)-1].to - 1 + } + return false // all types of visible-segments have the same height. stop here }) return maxIdx diff --git a/turbo/snapshotsync/freezeblocks/caplin_snapshots.go b/turbo/snapshotsync/freezeblocks/caplin_snapshots.go index 8a069883e7e..3391f07a170 100644 --- a/turbo/snapshotsync/freezeblocks/caplin_snapshots.go +++ b/turbo/snapshotsync/freezeblocks/caplin_snapshots.go @@ -358,9 +358,11 @@ func (s *CaplinSnapshots) recalcVisibleFiles() { s.BeaconBlocks.VisibleSegments = getNewVisibleSegments(s.BeaconBlocks.DirtySegments) s.BlobSidecars.VisibleSegments = getNewVisibleSegments(s.BlobSidecars.DirtySegments) + var maxIdx uint64 if len(s.BeaconBlocks.VisibleSegments) > 0 { - s.BeaconBlocks.maxVisibleBlock.Store(s.BeaconBlocks.VisibleSegments[len(s.BeaconBlocks.VisibleSegments)-1].to - 1) + maxIdx = s.BeaconBlocks.VisibleSegments[len(s.BeaconBlocks.VisibleSegments)-1].to - 1 } + s.BeaconBlocks.maxVisibleBlock.Store(maxIdx) } func (s *CaplinSnapshots) idxAvailability() uint64 {