From 6d8bfb40e41c2a56978b122c6f2d41edf6a97a24 Mon Sep 17 00:00:00 2001 From: devopsbo3 <69951731+devopsbo3@users.noreply.github.com> Date: Fri, 10 Nov 2023 12:27:53 -0600 Subject: [PATCH] Revert "cmd/utils: fix a startup issue on deleted chaindata but dangling ancients (#27989)" This reverts commit 22b083a1636d9990401b399167cae3d0a2fe935f. --- cmd/utils/flags.go | 6 +++--- core/rawdb/database.go | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 0e90fd4511..e2136feb85 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -2073,10 +2073,10 @@ func MakeChainDatabase(ctx *cli.Context, stack *node.Node, readonly bool) ethdb. // tryMakeReadOnlyDatabase try to open the chain database in read-only mode, // or fallback to write mode if the database is not initialized. func tryMakeReadOnlyDatabase(ctx *cli.Context, stack *node.Node) ethdb.Database { - // If the database doesn't exist we need to open it in write-mode to allow - // the engine to create files. + // If datadir doesn't exist we need to open db in write-mode + // so database engine can create files. readonly := true - if rawdb.PreexistingDatabase(stack.ResolvePath("chaindata")) == "" { + if !common.FileExist(stack.ResolvePath("chaindata")) { readonly = false } return MakeChainDatabase(ctx, stack, readonly) diff --git a/core/rawdb/database.go b/core/rawdb/database.go index 31edd0dcbb..981690f7bd 100644 --- a/core/rawdb/database.go +++ b/core/rawdb/database.go @@ -326,10 +326,10 @@ const ( dbLeveldb = "leveldb" ) -// PreexistingDatabase checks the given data directory whether a database is already +// hasPreexistingDb checks the given data directory whether a database is already // instantiated at that location, and if so, returns the type of database (or the // empty string). -func PreexistingDatabase(path string) string { +func hasPreexistingDb(path string) string { if _, err := os.Stat(filepath.Join(path, "CURRENT")); err != nil { return "" // No pre-existing db } @@ -367,7 +367,7 @@ func openKeyValueDatabase(o OpenOptions) (ethdb.Database, error) { } // Retrieve any pre-existing database's type and use that or the requested one // as long as there's no conflict between the two types - existingDb := PreexistingDatabase(o.Directory) + existingDb := hasPreexistingDb(o.Directory) if len(existingDb) != 0 && len(o.Type) != 0 && o.Type != existingDb { return nil, fmt.Errorf("db.engine choice was %v but found pre-existing %v database in specified data directory", o.Type, existingDb) }