diff --git a/cmd/nitro/init.go b/cmd/nitro/init.go index 0d10cb3294..426abd4c13 100644 --- a/cmd/nitro/init.go +++ b/cmd/nitro/init.go @@ -303,20 +303,6 @@ func databaseEmpty(path string) bool { } func openInitializeChainDb(ctx context.Context, stack *node.Node, config *NodeConfig, chainId *big.Int, cacheConfig *core.CacheConfig, persistentConfig *conf.PersistentConfig, l1Client arbutil.L1Interface, rollupAddrs chaininfo.RollupAddresses) (ethdb.Database, *core.BlockChain, error) { - if !dirExists(path.Join(stack.InstanceDir(), "l2chaindata")) { - const errorFmt = "database was not found in %s, but it was found in %s (have you placed the database in the wrong directory?)" - parentDir := filepath.Dir(stack.InstanceDir()) - if dirExists(path.Join(parentDir, "l2chaindata")) { - return nil, nil, fmt.Errorf(errorFmt, stack.InstanceDir(), parentDir) - } - grandParentDir := filepath.Dir(parentDir) - if dirExists(path.Join(grandParentDir, "l2chaindata")) { - return nil, nil, fmt.Errorf(errorFmt, stack.InstanceDir(), grandParentDir) - } - if !databaseEmpty(stack.InstanceDir()) { - return nil, nil, fmt.Errorf("found unexpected files in database directory '%s' (have you set --persistent.chain and --persistent.global-config correctly? If so, delete the database directory and try again)", stack.InstanceDir()) - } - } if !config.Init.Force { if readOnlyDb, err := stack.OpenDatabaseWithFreezerWithExtraOptions("l2chaindata", 0, 0, "", "l2chaindata/", true, persistentConfig.Pebble.ExtraOptions("l2chaindata")); err == nil { if chainConfig := gethexec.TryReadStoredChainConfig(readOnlyDb); chainConfig != nil { @@ -356,10 +342,21 @@ func openInitializeChainDb(ctx context.Context, stack *node.Node, config *NodeCo } readOnlyDb.Close() } + } else if !databaseEmpty(stack.InstanceDir()) { + return nil, nil, fmt.Errorf("trying to overwrite old database directory '%s' (delete the database directory and try again)", stack.InstanceDir()) } + const errorFmt = "database was not found in %s, but it was found in %s (have you placed the database in the wrong directory?)" + parentDir := filepath.Dir(stack.InstanceDir()) + if dirExists(path.Join(parentDir, "l2chaindata")) { + return nil, nil, fmt.Errorf(errorFmt, stack.InstanceDir(), parentDir) + } + grandParentDir := filepath.Dir(parentDir) + if dirExists(path.Join(grandParentDir, "l2chaindata")) { + return nil, nil, fmt.Errorf(errorFmt, stack.InstanceDir(), grandParentDir) + } if !databaseEmpty(stack.InstanceDir()) { - return nil, nil, fmt.Errorf("trying to overwrite old database directory '%s' (delete the database directory and try again)", stack.InstanceDir()) + return nil, nil, fmt.Errorf("found unexpected files in database directory '%s' (have you set --persistent.chain and --persistent.global-config correctly? If so, delete the database directory and try again)", stack.InstanceDir()) } initFile, err := downloadInit(ctx, &config.Init)