diff --git a/cl/antiquary/antiquary.go b/cl/antiquary/antiquary.go index 28e1a5d0e9f..7f49882bfcd 100644 --- a/cl/antiquary/antiquary.go +++ b/cl/antiquary/antiquary.go @@ -157,7 +157,7 @@ func (a *Antiquary) Loop() error { } logInterval := time.NewTicker(30 * time.Second) - if err := a.sn.ReopenFolder(); err != nil { + if err := a.sn.OpenFolder(); err != nil { return err } defer logInterval.Stop() @@ -294,7 +294,7 @@ func (a *Antiquary) antiquate() error { if err := freezeblocks.DumpBeaconBlocks(a.ctx, a.mainDB, from, to, a.sn.Salt, a.dirs, 1, log.LvlDebug, a.logger); err != nil { return err } - if err := a.sn.ReopenFolder(); err != nil { + if err := a.sn.OpenFolder(); err != nil { return err } tx, err := a.mainDB.BeginRw(a.ctx) @@ -312,7 +312,7 @@ func (a *Antiquary) antiquate() error { if err := tx.Commit(); err != nil { return err } - if err := a.sn.ReopenFolder(); err != nil { + if err := a.sn.OpenFolder(); err != nil { return err } @@ -393,7 +393,7 @@ func (a *Antiquary) antiquateBlobs() error { } to = (to / snaptype.CaplinMergeLimit) * snaptype.CaplinMergeLimit a.logger.Info("[Antiquary] Finished Antiquating blobs", "from", currentBlobsProgress, "to", to) - if err := a.sn.ReopenFolder(); err != nil { + if err := a.sn.OpenFolder(); err != nil { return err } diff --git a/cl/phase1/stages/stage_history_download.go b/cl/phase1/stages/stage_history_download.go index 08d5f738d27..18a6fc93095 100644 --- a/cl/phase1/stages/stage_history_download.go +++ b/cl/phase1/stages/stage_history_download.go @@ -197,7 +197,7 @@ func SpawnStageHistoryDownload(cfg StageHistoryReconstructionCfg, ctx context.Co continue } if cfg.sn != nil && cfg.sn.SegmentsMax() == 0 { - cfg.sn.ReopenFolder() + cfg.sn.OpenFolder() } logArgs = append(logArgs, "slot", currProgress, diff --git a/cmd/capcli/cli.go b/cmd/capcli/cli.go index 6256dbbd937..86e1e809841 100644 --- a/cmd/capcli/cli.go +++ b/cmd/capcli/cli.go @@ -432,7 +432,7 @@ func (c *CheckSnapshots) Run(ctx *Context) error { to = (to / snaptype.CaplinMergeLimit) * snaptype.CaplinMergeLimit csn := freezeblocks.NewCaplinSnapshots(ethconfig.BlocksFreezing{}, beaconConfig, dirs, log.Root()) - if err := csn.ReopenFolder(); err != nil { + if err := csn.OpenFolder(); err != nil { return err } @@ -517,7 +517,7 @@ func (c *LoopSnapshots) Run(ctx *Context) error { to = (to / snaptype.CaplinMergeLimit) * snaptype.CaplinMergeLimit csn := freezeblocks.NewCaplinSnapshots(ethconfig.BlocksFreezing{}, beaconConfig, dirs, log.Root()) - if err := csn.ReopenFolder(); err != nil { + if err := csn.OpenFolder(); err != nil { return err } @@ -559,7 +559,7 @@ func (r *RetrieveHistoricalState) Run(ctx *Context) error { defer tx.Rollback() allSnapshots := freezeblocks.NewRoSnapshots(ethconfig.BlocksFreezing{}, dirs.Snap, 0, log.Root()) - if err := allSnapshots.ReopenFolder(); err != nil { + if err := allSnapshots.OpenFolder(); err != nil { return err } if err := state_accessors.ReadValidatorsTable(tx, vt); err != nil { @@ -571,7 +571,7 @@ func (r *RetrieveHistoricalState) Run(ctx *Context) error { eth1Getter := getters.NewExecutionSnapshotReader(ctx, blockReader, db) eth1Getter.SetBeaconChainConfig(beaconConfig) csn := freezeblocks.NewCaplinSnapshots(ethconfig.BlocksFreezing{}, beaconConfig, dirs, log.Root()) - if err := csn.ReopenFolder(); err != nil { + if err := csn.OpenFolder(); err != nil { return err } snr := freezeblocks.NewBeaconSnapshotReader(csn, eth1Getter, beaconConfig) @@ -902,7 +902,7 @@ func (b *BlobArchiveStoreCheck) Run(ctx *Context) error { defer db.Close() csn := freezeblocks.NewCaplinSnapshots(ethconfig.BlocksFreezing{}, beaconConfig, dirs, log.Root()) - if err := csn.ReopenFolder(); err != nil { + if err := csn.OpenFolder(); err != nil { return err } snr := freezeblocks.NewBeaconSnapshotReader(csn, nil, beaconConfig) @@ -1017,7 +1017,7 @@ func (c *CheckBlobsSnapshots) Run(ctx *Context) error { defer tx.Rollback() csn := freezeblocks.NewCaplinSnapshots(ethconfig.BlocksFreezing{}, beaconConfig, dirs, log.Root()) - if err := csn.ReopenFolder(); err != nil { + if err := csn.OpenFolder(); err != nil { return err } to := csn.FrozenBlobs() @@ -1078,7 +1078,7 @@ func (c *CheckBlobsSnapshotsCount) Run(ctx *Context) error { defer tx.Rollback() csn := freezeblocks.NewCaplinSnapshots(ethconfig.BlocksFreezing{}, beaconConfig, dirs, log.Root()) - if err := csn.ReopenFolder(); err != nil { + if err := csn.OpenFolder(); err != nil { return err } to := csn.FrozenBlobs() @@ -1145,7 +1145,7 @@ func (c *DumpBlobsSnapshotsToStore) Run(ctx *Context) error { defer tx.Rollback() csn := freezeblocks.NewCaplinSnapshots(ethconfig.BlocksFreezing{}, beaconConfig, dirs, log.Root()) - if err := csn.ReopenFolder(); err != nil { + if err := csn.OpenFolder(); err != nil { return err } to := csn.FrozenBlobs() diff --git a/cmd/devnet/services/polygon/heimdallsim/heimdall_simulator.go b/cmd/devnet/services/polygon/heimdallsim/heimdall_simulator.go index 6772c88c3f6..e7a18a07d43 100644 --- a/cmd/devnet/services/polygon/heimdallsim/heimdall_simulator.go +++ b/cmd/devnet/services/polygon/heimdallsim/heimdall_simulator.go @@ -62,7 +62,7 @@ func NewHeimdallSimulator(ctx context.Context, snapDir string, logger log.Logger } } - if err = snapshots.ReopenFolder(); err != nil { + if err = snapshots.OpenFolder(); err != nil { return nil, err } diff --git a/cmd/hack/hack.go b/cmd/hack/hack.go index 2e860fa65e5..202427e16f5 100644 --- a/cmd/hack/hack.go +++ b/cmd/hack/hack.go @@ -281,7 +281,7 @@ func extractBodies(datadir string) error { KeepBlocks: true, ProduceE2: false, }, filepath.Join(datadir, "snapshots"), 0, log.New()) - snaps.ReopenFolder() + snaps.OpenFolder() /* method Iterate was removed, need re-implement snaps.Bodies.View(func(sns []*snapshotsync.BodySegment) error { diff --git a/cmd/integration/commands/stages.go b/cmd/integration/commands/stages.go index 0b3cd33ba82..e245af648fa 100644 --- a/cmd/integration/commands/stages.go +++ b/cmd/integration/commands/stages.go @@ -1300,11 +1300,11 @@ func allSnapshots(ctx context.Context, db kv.RoDB, logger log.Logger) (*freezebl g := &errgroup.Group{} g.Go(func() error { - _allSnapshotsSingleton.OptimisticalyReopenFolder() + _allSnapshotsSingleton.OptimisticalyOpenFolder() return nil }) g.Go(func() error { - _allBorSnapshotsSingleton.OptimisticalyReopenFolder() + _allBorSnapshotsSingleton.OptimisticalyOpenFolder() return nil }) g.Go(func() error { return _aggSingleton.OpenFolder() }) @@ -1314,7 +1314,7 @@ func allSnapshots(ctx context.Context, db kv.RoDB, logger log.Logger) (*freezebl _, beaconConfig, _, err = clparams.GetConfigsByNetworkName(chainConfig.ChainName) if err == nil { _allCaplinSnapshotsSingleton = freezeblocks.NewCaplinSnapshots(snapCfg, beaconConfig, dirs, logger) - if err = _allCaplinSnapshotsSingleton.ReopenFolder(); err != nil { + if err = _allCaplinSnapshotsSingleton.OpenFolder(); err != nil { return err } _allCaplinSnapshotsSingleton.LogStat("caplin") diff --git a/cmd/rpcdaemon/cli/config.go b/cmd/rpcdaemon/cli/config.go index e974b76ba0d..d314426db0e 100644 --- a/cmd/rpcdaemon/cli/config.go +++ b/cmd/rpcdaemon/cli/config.go @@ -423,8 +423,8 @@ func RemoteServices(ctx context.Context, cfg *httpcfg.HttpCfg, logger log.Logger return nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, err } if allSegmentsDownloadComplete { - allSnapshots.OptimisticalyReopenFolder() - allBorSnapshots.OptimisticalyReopenFolder() + allSnapshots.OptimisticalyOpenFolder() + allBorSnapshots.OptimisticalyOpenFolder() allSnapshots.LogStat("remote") allBorSnapshots.LogStat("bor:remote") @@ -452,12 +452,12 @@ func RemoteServices(ctx context.Context, cfg *httpcfg.HttpCfg, logger log.Logger logger.Warn("[snapshots] reopen", "err", err) return nil } - if err := allSnapshots.ReopenList(reply.BlocksFiles, true); err != nil { + if err := allSnapshots.OpenList(reply.BlocksFiles, true); err != nil { logger.Error("[snapshots] reopen", "err", err) } else { allSnapshots.LogStat("reopen") } - if err := allBorSnapshots.ReopenList(reply.BlocksFiles, true); err != nil { + if err := allBorSnapshots.OpenList(reply.BlocksFiles, true); err != nil { logger.Error("[bor snapshots] reopen", "err", err) } else { allBorSnapshots.LogStat("bor:reopen") diff --git a/cmd/snapshots/cmp/cmp.go b/cmd/snapshots/cmp/cmp.go index c66c13493db..9df90cc8fad 100644 --- a/cmd/snapshots/cmp/cmp.go +++ b/cmd/snapshots/cmp/cmp.go @@ -482,7 +482,7 @@ func (c comparitor) compareHeaders(ctx context.Context, f1ents []fs.DirEntry, f2 NoDownloader: true, }, info1.Dir(), info1.From, logger) - f1snaps.ReopenList([]string{ent1.Name()}, false) + f1snaps.OpenList([]string{ent1.Name()}, false) info2, _, _ := snaptype.ParseFileName(c.session2.LocalFsRoot(), ent1.Name()) @@ -491,7 +491,7 @@ func (c comparitor) compareHeaders(ctx context.Context, f1ents []fs.DirEntry, f2 NoDownloader: true, }, info2.Dir(), info2.From, logger) - f2snaps.ReopenList([]string{ent2.Name()}, false) + f2snaps.OpenList([]string{ent2.Name()}, false) err = func() error { logger.Info(fmt.Sprintf("Comparing %s %s", ent1.Name(), ent2.Name())) @@ -761,7 +761,7 @@ func (c comparitor) compareBodies(ctx context.Context, f1ents []*BodyEntry, f2en NoDownloader: true, }, info1.Dir(), info1.From, logger) - f1snaps.ReopenList([]string{ent1.Body.Name(), ent1.Transactions.Name()}, false) + f1snaps.OpenList([]string{ent1.Body.Name(), ent1.Transactions.Name()}, false) info2, _, _ := snaptype.ParseFileName(c.session2.LocalFsRoot(), ent2.Body.Name()) @@ -770,7 +770,7 @@ func (c comparitor) compareBodies(ctx context.Context, f1ents []*BodyEntry, f2en NoDownloader: true, }, info2.Dir(), info2.From, logger) - f2snaps.ReopenList([]string{ent2.Body.Name(), ent2.Transactions.Name()}, false) + f2snaps.OpenList([]string{ent2.Body.Name(), ent2.Transactions.Name()}, false) err := func() error { logger.Info(fmt.Sprintf("Comparing %s %s", ent1.Body.Name(), ent2.Body.Name())) diff --git a/eth/backend.go b/eth/backend.go index 32940b3dfe5..c2a0fab4c90 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -1447,9 +1447,9 @@ func setUpBlockReader(ctx context.Context, db kv.RwDB, dirs datadir.Dirs, snConf return nil, nil, nil, nil, nil, err } if allSegmentsDownloadComplete { - allSnapshots.OptimisticalyReopenFolder() + allSnapshots.OptimisticalyOpenFolder() if isBor { - allBorSnapshots.OptimisticalyReopenFolder() + allBorSnapshots.OptimisticalyOpenFolder() } _ = agg.OpenFolder() } else { diff --git a/eth/stagedsync/stage_snapshots.go b/eth/stagedsync/stage_snapshots.go index 6d0d0140c70..78631bf81fb 100644 --- a/eth/stagedsync/stage_snapshots.go +++ b/eth/stagedsync/stage_snapshots.go @@ -241,12 +241,12 @@ func DownloadAndIndexSnapshotsIfNeed(s *StageState, ctx context.Context, tx kv.R } } - if err := cfg.blockReader.Snapshots().ReopenFolder(); err != nil { + if err := cfg.blockReader.Snapshots().OpenFolder(); err != nil { return err } if cfg.chainConfig.Bor != nil { - if err := cfg.blockReader.BorSnapshots().ReopenFolder(); err != nil { + if err := cfg.blockReader.BorSnapshots().OpenFolder(); err != nil { return err } } @@ -275,7 +275,7 @@ func DownloadAndIndexSnapshotsIfNeed(s *StageState, ctx context.Context, tx kv.R return err } - if err := cfg.blockReader.Snapshots().ReopenSegments([]snaptype.Type{coresnaptype.Headers, coresnaptype.Bodies}, true); err != nil { + if err := cfg.blockReader.Snapshots().OpenSegments([]snaptype.Type{coresnaptype.Headers, coresnaptype.Bodies}, true); err != nil { return err } @@ -1268,11 +1268,11 @@ func (u *snapshotUploader) removeBefore(before uint64) { if len(toRemove) > 0 { if snapshots, ok := u.cfg.blockReader.Snapshots().(*freezeblocks.RoSnapshots); ok { snapshots.SetSegmentsMin(before) - snapshots.ReopenList(toReopen, true) + snapshots.OpenList(toReopen, true) } if snapshots, ok := u.cfg.blockReader.BorSnapshots().(*freezeblocks.BorRoSnapshots); ok { - snapshots.ReopenList(borToReopen, true) + snapshots.OpenList(borToReopen, true) snapshots.SetSegmentsMin(before) } diff --git a/p2p/enode/nodedb_test.go b/p2p/enode/nodedb_test.go index ae0b5a58623..42e05e79d3c 100644 --- a/p2p/enode/nodedb_test.go +++ b/p2p/enode/nodedb_test.go @@ -333,7 +333,7 @@ func TestDBPersistency(t *testing.T) { } db.Close() - // ReopenSegments the database and check the value + // OpenSegments the database and check the value db, err = OpenDB(context.Background(), filepath.Join(root, "database"), root, log.Root()) if err != nil { t.Fatalf("failed to open persistent database: %v", err) diff --git a/p2p/sentry/simulator/sentry_simulator.go b/p2p/sentry/simulator/sentry_simulator.go index 52d0b34f0b4..4bb69c3f9b7 100644 --- a/p2p/sentry/simulator/sentry_simulator.go +++ b/p2p/sentry/simulator/sentry_simulator.go @@ -98,13 +98,13 @@ func NewSentry(ctx context.Context, chain string, snapshotLocation string, peerC knownSnapshots.InitSegments(files) - //s.knownSnapshots.ReopenList([]string{ent2.Name()}, false) + //s.knownSnapshots.OpenList([]string{ent2.Name()}, false) activeSnapshots := freezeblocks.NewRoSnapshots(ethconfig.BlocksFreezing{ ProduceE2: false, NoDownloader: true, }, torrentDir, 0, logger) - if err := activeSnapshots.ReopenFolder(); err != nil { + if err := activeSnapshots.OpenFolder(); err != nil { return nil, err } @@ -439,7 +439,7 @@ func (s *server) getHeader(ctx context.Context, blockNum uint64) (*coretypes.Hea } } - s.activeSnapshots.ReopenSegments([]snaptype.Type{coresnaptype.Headers}, true) + s.activeSnapshots.OpenSegments([]snaptype.Type{coresnaptype.Headers}, true) header, err = s.blockReader.Header(ctx, nil, common.Hash{}, blockNum) diff --git a/turbo/app/snapshots_cmd.go b/turbo/app/snapshots_cmd.go index 3c46de4bdf4..b9d2666838f 100644 --- a/turbo/app/snapshots_cmd.go +++ b/turbo/app/snapshots_cmd.go @@ -1058,13 +1058,13 @@ func openSnaps(ctx context.Context, dirs datadir.Dirs, chainDB kv.RwDB, logger l cfg := ethconfig.NewSnapCfg(false, true, true, chainConfig.ChainName) blockSnaps = freezeblocks.NewRoSnapshots(cfg, dirs.Snap, 0, logger) - if err = blockSnaps.ReopenFolder(); err != nil { + if err = blockSnaps.OpenFolder(); err != nil { return } blockSnaps.LogStat("block") borSnaps = freezeblocks.NewBorRoSnapshots(cfg, dirs.Snap, 0, logger) - if err = borSnaps.ReopenFolder(); err != nil { + if err = borSnaps.OpenFolder(); err != nil { return } @@ -1072,7 +1072,7 @@ func openSnaps(ctx context.Context, dirs datadir.Dirs, chainDB kv.RwDB, logger l _, beaconConfig, _, err = clparams.GetConfigsByNetworkName(chainConfig.ChainName) if err == nil { csn = freezeblocks.NewCaplinSnapshots(cfg, beaconConfig, dirs, logger) - if err = csn.ReopenFolder(); err != nil { + if err = csn.OpenFolder(); err != nil { return } csn.LogStat("caplin") diff --git a/turbo/services/interfaces.go b/turbo/services/interfaces.go index dcb7ca661dd..735a25e3f14 100644 --- a/turbo/services/interfaces.go +++ b/turbo/services/interfaces.go @@ -135,8 +135,8 @@ type FullBlockReader interface { type BlockSnapshots interface { LogStat(label string) - ReopenFolder() error - ReopenSegments(types []snaptype.Type, allowGaps bool) error + OpenFolder() error + OpenSegments(types []snaptype.Type, allowGaps bool) error SegmentsMax() uint64 SegmentsMin() uint64 Delete(fileName string) error diff --git a/turbo/snapshotsync/freezeblocks/block_reader_test.go b/turbo/snapshotsync/freezeblocks/block_reader_test.go index 7d2aaca6f5e..2b3232742a5 100644 --- a/turbo/snapshotsync/freezeblocks/block_reader_test.go +++ b/turbo/snapshotsync/freezeblocks/block_reader_test.go @@ -46,7 +46,7 @@ func TestBlockReaderLastFrozenSpanIdWhenSegmentFilesArePresent(t *testing.T) { createTestSegmentFile(t, 0, 500_000, borsnaptype.Enums.BorSpans, dir, 1, logger) borRoSnapshots := NewBorRoSnapshots(ethconfig.BlocksFreezing{ChainName: networkname.BorMainnetChainName}, dir, 0, logger) defer borRoSnapshots.Close() - err := borRoSnapshots.ReopenFolder() + err := borRoSnapshots.OpenFolder() require.NoError(t, err) blockReader := &BlockReader{borSn: borRoSnapshots} @@ -60,7 +60,7 @@ func TestBlockReaderLastFrozenSpanIdWhenSegmentFilesAreNotPresent(t *testing.T) dir := t.TempDir() borRoSnapshots := NewBorRoSnapshots(ethconfig.BlocksFreezing{ChainName: networkname.BorMainnetChainName}, dir, 0, logger) defer borRoSnapshots.Close() - err := borRoSnapshots.ReopenFolder() + err := borRoSnapshots.OpenFolder() require.NoError(t, err) blockReader := &BlockReader{borSn: borRoSnapshots} @@ -84,7 +84,7 @@ func TestBlockReaderLastFrozenSpanIdReturnsLastSegWithIdx(t *testing.T) { require.NoError(t, err) borRoSnapshots := NewBorRoSnapshots(ethconfig.BlocksFreezing{ChainName: networkname.BorMainnetChainName}, dir, 0, logger) defer borRoSnapshots.Close() - err = borRoSnapshots.ReopenFolder() + err = borRoSnapshots.OpenFolder() require.NoError(t, err) blockReader := &BlockReader{borSn: borRoSnapshots} @@ -114,7 +114,7 @@ func TestBlockReaderLastFrozenSpanIdReturnsZeroWhenAllSegmentsDoNotHaveIdx(t *te require.NoError(t, err) borRoSnapshots := NewBorRoSnapshots(ethconfig.BlocksFreezing{ChainName: networkname.BorMainnetChainName}, dir, 0, logger) defer borRoSnapshots.Close() - err = borRoSnapshots.ReopenFolder() + err = borRoSnapshots.OpenFolder() require.NoError(t, err) blockReader := &BlockReader{borSn: borRoSnapshots} @@ -130,7 +130,7 @@ func TestBlockReaderLastFrozenEventIdWhenSegmentFilesArePresent(t *testing.T) { createTestSegmentFile(t, 0, 500_000, borsnaptype.Enums.BorSpans, dir, 1, logger) borRoSnapshots := NewBorRoSnapshots(ethconfig.BlocksFreezing{ChainName: networkname.BorMainnetChainName}, dir, 0, logger) defer borRoSnapshots.Close() - err := borRoSnapshots.ReopenFolder() + err := borRoSnapshots.OpenFolder() require.NoError(t, err) blockReader := &BlockReader{borSn: borRoSnapshots} @@ -144,7 +144,7 @@ func TestBlockReaderLastFrozenEventIdWhenSegmentFilesAreNotPresent(t *testing.T) dir := t.TempDir() borRoSnapshots := NewBorRoSnapshots(ethconfig.BlocksFreezing{ChainName: networkname.BorMainnetChainName}, dir, 0, logger) defer borRoSnapshots.Close() - err := borRoSnapshots.ReopenFolder() + err := borRoSnapshots.OpenFolder() require.NoError(t, err) blockReader := &BlockReader{borSn: borRoSnapshots} @@ -168,7 +168,7 @@ func TestBlockReaderLastFrozenEventIdReturnsLastSegWithIdx(t *testing.T) { require.NoError(t, err) borRoSnapshots := NewBorRoSnapshots(ethconfig.BlocksFreezing{ChainName: networkname.BorMainnetChainName}, dir, 0, logger) defer borRoSnapshots.Close() - err = borRoSnapshots.ReopenFolder() + err = borRoSnapshots.OpenFolder() require.NoError(t, err) blockReader := &BlockReader{borSn: borRoSnapshots} @@ -198,7 +198,7 @@ func TestBlockReaderLastFrozenEventIdReturnsZeroWhenAllSegmentsDoNotHaveIdx(t *t require.NoError(t, err) borRoSnapshots := NewBorRoSnapshots(ethconfig.BlocksFreezing{ChainName: networkname.BorMainnetChainName}, dir, 0, logger) defer borRoSnapshots.Close() - err = borRoSnapshots.ReopenFolder() + err = borRoSnapshots.OpenFolder() require.NoError(t, err) blockReader := &BlockReader{borSn: borRoSnapshots} diff --git a/turbo/snapshotsync/freezeblocks/block_snapshots.go b/turbo/snapshotsync/freezeblocks/block_snapshots.go index f5ed79c7842..95be4e269b2 100644 --- a/turbo/snapshotsync/freezeblocks/block_snapshots.go +++ b/turbo/snapshotsync/freezeblocks/block_snapshots.go @@ -290,7 +290,7 @@ func (s *DirtySegment) isSubSetOf(j *DirtySegment) bool { return (j.from <= s.from && s.to <= j.to) && (j.from != s.from || s.to != j.to) } -func (s *DirtySegment) reopenSeg(dir string) (err error) { +func (s *DirtySegment) openSegIfNeed(dir string) (err error) { if s.Decompressor != nil { return nil } @@ -348,8 +348,8 @@ func (s *DirtySegment) openFiles() []string { return files } -func (s *DirtySegment) reopenIdxIfNeed(dir string, optimistic bool) (err error) { - err = s.reopenIdx(dir) +func (s *DirtySegment) openIdxIfNeed(dir string, optimistic bool) (err error) { + err = s._openIdxIfNeed(dir) if err != nil { if !errors.Is(err, os.ErrNotExist) { if optimistic { @@ -363,7 +363,7 @@ func (s *DirtySegment) reopenIdxIfNeed(dir string, optimistic bool) (err error) return nil } -func (s *DirtySegment) reopenIdx(dir string) (err error) { +func (s *DirtySegment) _openIdxIfNeed(dir string) (err error) { if s.Decompressor == nil { return nil } @@ -755,15 +755,15 @@ func (s *RoSnapshots) OpenFiles() (list []string) { return list } -// ReopenList stops on optimistic=false, continue opening files on optimistic=true -func (s *RoSnapshots) ReopenList(fileNames []string, optimistic bool) error { +// OpenList stops on optimistic=false, continue opening files on optimistic=true +func (s *RoSnapshots) OpenList(fileNames []string, optimistic bool) error { defer s.recalcVisibleFiles() s.dirtySegmentsLock.Lock() defer s.dirtySegmentsLock.Unlock() s.closeWhatNotInList(fileNames) - if err := s.rebuildSegments(fileNames, true, optimistic); err != nil { + if err := s.openSegments(fileNames, true, optimistic); err != nil { return err } return nil @@ -776,13 +776,13 @@ func (s *RoSnapshots) InitSegments(fileNames []string) error { defer s.dirtySegmentsLock.Unlock() s.closeWhatNotInList(fileNames) - if err := s.rebuildSegments(fileNames, false, true); err != nil { + if err := s.openSegments(fileNames, false, true); err != nil { return err } return nil } -func (s *RoSnapshots) rebuildSegments(fileNames []string, open bool, optimistic bool) error { +func (s *RoSnapshots) openSegments(fileNames []string, open bool, optimistic bool) error { var segmentsMax uint64 var segmentsMaxSet bool @@ -824,7 +824,7 @@ func (s *RoSnapshots) rebuildSegments(fileNames []string, open bool, optimistic } if open { - if err := sn.reopenSeg(s.dir); err != nil { + if err := sn.openSegIfNeed(s.dir); err != nil { if errors.Is(err, os.ErrNotExist) { if optimistic { continue @@ -847,7 +847,7 @@ func (s *RoSnapshots) rebuildSegments(fileNames []string, open bool, optimistic } if open { - if err := sn.reopenIdxIfNeed(s.dir, optimistic); err != nil { + if err := sn.openIdxIfNeed(s.dir, optimistic); err != nil { return err } } @@ -872,8 +872,8 @@ func (s *RoSnapshots) Ranges() []Range { return view.Ranges() } -func (s *RoSnapshots) OptimisticalyReopenFolder() { _ = s.ReopenFolder() } -func (s *RoSnapshots) ReopenFolder() error { +func (s *RoSnapshots) OptimisticalyOpenFolder() { _ = s.OpenFolder() } +func (s *RoSnapshots) OpenFolder() error { defer s.recalcVisibleFiles() s.dirtySegmentsLock.Lock() @@ -890,13 +890,13 @@ func (s *RoSnapshots) ReopenFolder() error { list = append(list, fName) } s.closeWhatNotInList(list) - if err := s.rebuildSegments(list, true, false); err != nil { + if err := s.openSegments(list, true, false); err != nil { return err } return nil } -func (s *RoSnapshots) ReopenSegments(types []snaptype.Type, allowGaps bool) error { +func (s *RoSnapshots) OpenSegments(types []snaptype.Type, allowGaps bool) error { defer s.recalcVisibleFiles() s.dirtySegmentsLock.Lock() @@ -913,7 +913,7 @@ func (s *RoSnapshots) ReopenSegments(types []snaptype.Type, allowGaps bool) erro list = append(list, fName) } - if err := s.rebuildSegments(list, true, false); err != nil { + if err := s.openSegments(list, true, false); err != nil { return err } return nil @@ -1005,10 +1005,10 @@ func (s *RoSnapshots) buildMissedIndicesIfNeed(ctx context.Context, logPrefix st return fmt.Errorf("can't build missed indices: %w", err) } - if err := s.ReopenFolder(); err != nil { + if err := s.OpenFolder(); err != nil { return err } - s.LogStat("missed-idx:reopen") + s.LogStat("missed-idx:open") if notifier != nil { notifier.OnNewSnapshot() } @@ -1554,8 +1554,8 @@ func (br *BlockRetire) retireBlocks(ctx context.Context, minBlockNum uint64, max return ok, fmt.Errorf("DumpBlocks: %w", err) } - if err := snapshots.ReopenFolder(); err != nil { - return ok, fmt.Errorf("reopen: %w", err) + if err := snapshots.OpenFolder(); err != nil { + return ok, fmt.Errorf("open: %w", err) } snapshots.LogStat("blocks:retire") if notifier != nil && !reflect.ValueOf(notifier).IsNil() { // notify about new snapshots of any size @@ -2278,7 +2278,7 @@ func (m *Merger) mergeSubSegment(ctx context.Context, v *View, sn snaptype.FileI if err = buildIdx(ctx, sn, m.chainConfig, m.tmpDir, p, m.lvl, m.logger); err != nil { return } - err = newDirtySegment.reopenIdx(snapDir) + err = newDirtySegment.openIdxIfNeed(snapDir, false) if err != nil { return } @@ -2452,7 +2452,7 @@ func (m *Merger) merge(ctx context.Context, v *View, toMerge []*DirtySegment, ta sn := &DirtySegment{segType: targetFile.Type, version: targetFile.Version, Range: Range{targetFile.From, targetFile.To}, frozen: snapcfg.IsFrozen(v.s.cfg.ChainName, targetFile)} - err = sn.reopenSeg(snapDir) + err = sn.openSegIfNeed(snapDir) if err != nil { return nil, err } diff --git a/turbo/snapshotsync/freezeblocks/block_snapshots_test.go b/turbo/snapshotsync/freezeblocks/block_snapshots_test.go index 5dfdc78f004..26ee815ec42 100644 --- a/turbo/snapshotsync/freezeblocks/block_snapshots_test.go +++ b/turbo/snapshotsync/freezeblocks/block_snapshots_test.go @@ -214,11 +214,11 @@ func TestMergeSnapshots(t *testing.T) { } s := NewRoSnapshots(ethconfig.BlocksFreezing{ChainName: networkname.MainnetChainName}, dir, 0, logger) defer s.Close() - require.NoError(s.ReopenFolder()) + require.NoError(s.OpenFolder()) { merger := NewMerger(dir, 1, log.LvlInfo, nil, params.MainnetChainConfig, logger) merger.DisableFsync() - s.ReopenSegments(coresnaptype.BlockSnapshotTypes, false) + s.OpenSegments(coresnaptype.BlockSnapshotTypes, false) ranges := merger.FindMergeRanges(s.Ranges(), s.SegmentsMax()) require.Equal(3, len(ranges)) err := merger.Merge(context.Background(), s, coresnaptype.BlockSnapshotTypes, ranges, s.Dir(), false, nil, nil) @@ -235,7 +235,7 @@ func TestMergeSnapshots(t *testing.T) { { merger := NewMerger(dir, 1, log.LvlInfo, nil, params.MainnetChainConfig, logger) merger.DisableFsync() - s.ReopenFolder() + s.OpenFolder() ranges := merger.FindMergeRanges(s.Ranges(), s.SegmentsMax()) require.Equal(0, len(ranges)) err := merger.Merge(context.Background(), s, coresnaptype.BlockSnapshotTypes, ranges, s.Dir(), false, nil, nil) @@ -257,7 +257,7 @@ func TestMergeSnapshots(t *testing.T) { // } // s = NewRoSnapshots(ethconfig.BlocksFreezing{Enabled: true}, dir, start, logger) // defer s.Close() - // require.NoError(s.ReopenFolder()) + // require.NoError(s.OpenFolder()) // { // merger := NewMerger(dir, 1, log.LvlInfo, nil, params.MainnetChainConfig, logger) // merger.DisableFsync() @@ -279,7 +279,7 @@ func TestMergeSnapshots(t *testing.T) { // { // merger := NewMerger(dir, 1, log.LvlInfo, nil, params.MainnetChainConfig, logger) // merger.DisableFsync() - // s.ReopenSegments(coresnaptype.BlockSnapshotTypes, false) + // s.OpenSegments(coresnaptype.BlockSnapshotTypes, false) // ranges := merger.FindMergeRanges(s.Ranges(), s.SegmentsMax()) // require.True(len(ranges) == 0) // err := merger.Merge(context.Background(), s, coresnaptype.BlockSnapshotTypes, ranges, s.Dir(), false, nil, nil) @@ -315,7 +315,7 @@ func TestDeleteSnapshots(t *testing.T) { "v1-000000-000010-headers.seg", "v1-000000-000010-transactions.seg", } - require.NoError(s.ReopenFolder()) + require.NoError(s.OpenFolder()) for _, f := range retireFiles { require.NoError(s.Delete(f)) require.False(slices.Contains(s.Files(), f)) @@ -356,7 +356,7 @@ func TestRemoveOverlaps(t *testing.T) { s := NewRoSnapshots(ethconfig.BlocksFreezing{ChainName: networkname.MainnetChainName}, dir, 0, logger) defer s.Close() - require.NoError(s.ReopenSegments(coresnaptype.BlockSnapshotTypes, false)) + require.NoError(s.OpenSegments(coresnaptype.BlockSnapshotTypes, false)) list, err := snaptype.Segments(s.dir) require.NoError(err) @@ -414,7 +414,7 @@ func TestOpenAllSnapshot(t *testing.T) { } s := NewRoSnapshots(cfg, dir, 0, logger) defer s.Close() - err := s.ReopenFolder() + err := s.OpenFolder() require.NoError(err) require.NotNil(s.segments.Get(coresnaptype.Enums.Headers)) getSegs := func(e snaptype.Enum) *segments { @@ -434,10 +434,10 @@ func TestOpenAllSnapshot(t *testing.T) { createFile(step, step*2, coresnaptype.Headers) createFile(step, step*2, coresnaptype.Transactions) s = NewRoSnapshots(cfg, dir, 0, logger) - err = s.ReopenFolder() + err = s.OpenFolder() require.NoError(err) require.NotNil(getSegs(coresnaptype.Enums.Headers)) - s.ReopenSegments(coresnaptype.BlockSnapshotTypes, false) + s.OpenSegments(coresnaptype.BlockSnapshotTypes, false) // require.Equal(1, len(getSegs(coresnaptype.Enums.Headers).visibleSegments)) s.Close() @@ -447,7 +447,7 @@ func TestOpenAllSnapshot(t *testing.T) { s = NewRoSnapshots(cfg, dir, 0, logger) defer s.Close() - err = s.ReopenFolder() + err = s.OpenFolder() require.NoError(err) require.NotNil(getSegs(coresnaptype.Enums.Headers)) require.Equal(2, len(getSegs(coresnaptype.Enums.Headers).VisibleSegments)) @@ -470,7 +470,7 @@ func TestOpenAllSnapshot(t *testing.T) { // ExpectedBlocks - says only how much block must come from Torrent chainSnapshotCfg.ExpectBlocks = 500_000 - 1 s = NewRoSnapshots(cfg, dir, 0, logger) - err = s.ReopenFolder() + err = s.OpenFolder() require.NoError(err) defer s.Close() require.NotNil(getSegs(coresnaptype.Enums.Headers)) @@ -482,7 +482,7 @@ func TestOpenAllSnapshot(t *testing.T) { chainSnapshotCfg.ExpectBlocks = math.MaxUint64 s = NewRoSnapshots(cfg, dir, 0, logger) defer s.Close() - err = s.ReopenFolder() + err = s.OpenFolder() require.NoError(err) } } @@ -552,7 +552,7 @@ func TestCalculateVisibleSegments(t *testing.T) { defer s.Close() { - require.NoError(s.ReopenFolder()) + require.NoError(s.OpenFolder()) idx := s.idxAvailability() require.Equal(2_500_000-1, int(idx)) @@ -569,7 +569,7 @@ func TestCalculateVisibleSegments(t *testing.T) { { createFile(6*500_000, 7*500_000, coresnaptype.Transactions) - require.NoError(s.ReopenFolder()) + require.NoError(s.OpenFolder()) idx := s.idxAvailability() require.Equal(2_500_000-1, int(idx)) @@ -586,7 +586,7 @@ func TestCalculateVisibleSegments(t *testing.T) { { createFile(4*500_000, 4*500_000+250_000, coresnaptype.Transactions) - require.NoError(s.ReopenFolder()) + require.NoError(s.OpenFolder()) idx := s.idxAvailability() require.Equal(2_500_000-1, int(idx)) @@ -621,7 +621,7 @@ func TestCalculateVisibleSegmentsWhenGapsInIdx(t *testing.T) { s := NewRoSnapshots(cfg, dir, 0, logger) defer s.Close() - require.NoError(s.ReopenFolder()) + require.NoError(s.OpenFolder()) idx := s.idxAvailability() require.Equal(500_000-1, int(idx)) diff --git a/turbo/snapshotsync/freezeblocks/bor_snapshots.go b/turbo/snapshotsync/freezeblocks/bor_snapshots.go index 5ba8e4d2957..7078b2f9ac7 100644 --- a/turbo/snapshotsync/freezeblocks/bor_snapshots.go +++ b/turbo/snapshotsync/freezeblocks/bor_snapshots.go @@ -96,7 +96,7 @@ func (br *BlockRetire) retireBorBlocks(ctx context.Context, minBlockNum uint64, } if blocksRetired { - if err := snapshots.ReopenFolder(); err != nil { + if err := snapshots.OpenFolder(); err != nil { return blocksRetired, fmt.Errorf("reopen: %w", err) } snapshots.LogStat("bor:retire") @@ -238,7 +238,7 @@ func removeBorOverlaps(dir string, active []snaptype.FileInfo, max uint64) { } } -func (s *BorRoSnapshots) ReopenFolder() error { +func (s *BorRoSnapshots) OpenFolder() error { files, _, err := typedSegments(s.dir, borsnaptype.BorSnapshotTypes(), false) if err != nil { return err @@ -249,7 +249,7 @@ func (s *BorRoSnapshots) ReopenFolder() error { _, fName := filepath.Split(f.Path) list = append(list, fName) } - if err := s.ReopenList(list, false); err != nil { + if err := s.OpenList(list, false); err != nil { return err } return nil diff --git a/turbo/snapshotsync/freezeblocks/caplin_snapshots.go b/turbo/snapshotsync/freezeblocks/caplin_snapshots.go index 6a037e71bf2..2329004313f 100644 --- a/turbo/snapshotsync/freezeblocks/caplin_snapshots.go +++ b/turbo/snapshotsync/freezeblocks/caplin_snapshots.go @@ -185,8 +185,8 @@ func (s *CaplinSnapshots) Close() { s.closeWhatNotInList(nil) } -// ReopenList stops on optimistic=false, continue opening files on optimistic=true -func (s *CaplinSnapshots) ReopenList(fileNames []string, optimistic bool) error { +// OpenList stops on optimistic=false, continue opening files on optimistic=true +func (s *CaplinSnapshots) OpenList(fileNames []string, optimistic bool) error { defer s.recalcVisibleFiles() s.dirtySegmentsLock.Lock() @@ -227,7 +227,7 @@ Loop: frozen: snapcfg.IsFrozen(s.cfg.ChainName, f), } } - if err := sn.reopenSeg(s.dir); err != nil { + if err := sn.openSegIfNeed(s.dir); err != nil { if errors.Is(err, os.ErrNotExist) { if optimistic { continue Loop @@ -248,7 +248,7 @@ Loop: // then make segment available even if index open may fail s.BeaconBlocks.DirtySegments.Set(sn) } - if err := sn.reopenIdxIfNeed(s.dir, optimistic); err != nil { + if err := sn.openIdxIfNeed(s.dir, optimistic); err != nil { return err } // Only bob sidecars count for progression @@ -284,7 +284,7 @@ Loop: frozen: snapcfg.IsFrozen(s.cfg.ChainName, f), } } - if err := sn.reopenSeg(s.dir); err != nil { + if err := sn.openSegIfNeed(s.dir); err != nil { if errors.Is(err, os.ErrNotExist) { if optimistic { continue Loop @@ -305,7 +305,7 @@ Loop: // then make segment available even if index open may fail s.BlobSidecars.DirtySegments.Set(sn) } - if err := sn.reopenIdxIfNeed(s.dir, optimistic); err != nil { + if err := sn.openIdxIfNeed(s.dir, optimistic); err != nil { return err } } @@ -365,7 +365,7 @@ func (s *CaplinSnapshots) idxAvailability() uint64 { return s.BeaconBlocks.maxVisibleBlock.Load() } -func (s *CaplinSnapshots) ReopenFolder() error { +func (s *CaplinSnapshots) OpenFolder() error { files, _, err := SegmentsCaplin(s.dir, s.segmentsMin.Load()) if err != nil { return err @@ -375,7 +375,7 @@ func (s *CaplinSnapshots) ReopenFolder() error { _, fName := filepath.Split(f.Path) list = append(list, fName) } - return s.ReopenList(list, false) + return s.OpenList(list, false) } func (s *CaplinSnapshots) closeWhatNotInList(l []string) { @@ -711,7 +711,7 @@ func (s *CaplinSnapshots) BuildMissingIndices(ctx context.Context, logger log.Lo return nil } - return s.ReopenFolder() + return s.OpenFolder() } func (s *CaplinSnapshots) ReadHeader(slot uint64) (*cltypes.SignedBeaconBlockHeader, uint64, libcommon.Hash, error) { diff --git a/turbo/snapshotsync/snapshotsync.go b/turbo/snapshotsync/snapshotsync.go index 15cf8d84e46..8c1ac058652 100644 --- a/turbo/snapshotsync/snapshotsync.go +++ b/turbo/snapshotsync/snapshotsync.go @@ -271,11 +271,11 @@ func WaitForDownloader(ctx context.Context, logPrefix string, dirs datadir.Dirs, // Find minimum block to download. if blockReader.FreezingCfg().NoDownloader || snapshotDownloader == nil { - if err := snapshots.ReopenFolder(); err != nil { + if err := snapshots.OpenFolder(); err != nil { return err } if cc.Bor != nil { - if err := borSnapshots.ReopenFolder(); err != nil { + if err := borSnapshots.OpenFolder(); err != nil { return err } } @@ -382,12 +382,12 @@ func WaitForDownloader(ctx context.Context, logPrefix string, dirs datadir.Dirs, } } - if err := snapshots.ReopenFolder(); err != nil { + if err := snapshots.OpenFolder(); err != nil { return err } if cc.Bor != nil { - if err := borSnapshots.ReopenFolder(); err != nil { + if err := borSnapshots.OpenFolder(); err != nil { return err } }