From 1b82acd7fffdae696fdbb760357a82b2c1a44ba8 Mon Sep 17 00:00:00 2001 From: Alex Sharov <AskAlexSharov@gmail.com> Date: Thu, 12 May 2022 15:14:16 +0700 Subject: [PATCH] it's ok to not have snapshots dir (#4135) * save * save * save --- cmd/rpcdaemon/cli/config.go | 5 ++++- turbo/snapshotsync/snap/files.go | 6 ++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/cmd/rpcdaemon/cli/config.go b/cmd/rpcdaemon/cli/config.go index e573581b02..69fc159b8c 100644 --- a/cmd/rpcdaemon/cli/config.go +++ b/cmd/rpcdaemon/cli/config.go @@ -297,6 +297,9 @@ func RemoteServices(ctx context.Context, cfg httpcfg.HttpCfg, logger log.Logger, if err != nil { return err } + if genesisBlock == nil { + return fmt.Errorf("genesis not found in DB. Likely Erigon was never started on this datadir") + } cc, err = rawdb.ReadChainConfig(tx, genesisBlock.Hash()) if err != nil { return err @@ -348,7 +351,7 @@ func RemoteServices(ctx context.Context, cfg httpcfg.HttpCfg, logger log.Logger, if cfg.Snapshot.Enabled { allSnapshots := snapshotsync.NewRoSnapshots(cfg.Snapshot, filepath.Join(cfg.DataDir, "snapshots")) if err := allSnapshots.Reopen(); err != nil { - return nil, nil, nil, nil, nil, nil, nil, nil, ff, err + return nil, nil, nil, nil, nil, nil, nil, nil, ff, fmt.Errorf("allSnapshots.Reopen: %w", err) } log.Info("[Snapshots] see new", "blocks", allSnapshots.BlocksAvailable()) // don't reopen it right here, because snapshots may be not ready yet diff --git a/turbo/snapshotsync/snap/files.go b/turbo/snapshotsync/snap/files.go index 0e8f90a7f5..ef60ed1aa8 100644 --- a/turbo/snapshotsync/snap/files.go +++ b/turbo/snapshotsync/snap/files.go @@ -143,6 +143,9 @@ func Segments(dir string) (res []FileInfo, err error) { return FilesWithExt(dir, func TmpFiles(dir string) (res []string, err error) { files, err := os.ReadDir(dir) if err != nil { + if errors.Is(err, os.ErrNotExist) { + return []string{}, nil + } return nil, err } for _, f := range files { @@ -162,6 +165,9 @@ var ErrSnapshotMissed = fmt.Errorf("snapshot missed") func ParseDir(dir string) (res []FileInfo, err error) { files, err := os.ReadDir(dir) if err != nil { + if errors.Is(err, os.ErrNotExist) { + return []FileInfo{}, nil + } return nil, err } for _, f := range files { -- GitLab