From 1208e0cac738e38c751d0a70182d44ce4183b56e Mon Sep 17 00:00:00 2001 From: Dustin Xie Date: Wed, 22 Jun 2022 12:31:38 -0700 Subject: [PATCH] [filedao] remove checkMasterChainDBFile() --- blockchain/filedao/filedao.go | 14 ++++++++------ blockchain/filedao/filedao_test.go | 2 +- blockchain/filedao/filedao_util.go | 17 ----------------- ioctl/newcmd/node/node.go | 2 +- 4 files changed, 10 insertions(+), 25 deletions(-) diff --git a/blockchain/filedao/filedao.go b/blockchain/filedao/filedao.go index 8a5caa0b0f..3d35250e52 100644 --- a/blockchain/filedao/filedao.go +++ b/blockchain/filedao/filedao.go @@ -84,12 +84,11 @@ type ( // NewFileDAO creates an instance of FileDAO func NewFileDAO(cfg db.Config) (FileDAO, error) { - header, err := checkMasterChainDBFile(cfg.DbPath) - if err == ErrFileInvalid || err == ErrFileCantAccess { - return nil, err - } - - if err == ErrFileNotExist { + header, err := readFileHeader(cfg.DbPath, FileAll) + if err != nil { + if err != ErrFileNotExist { + return nil, err + } // start new chain db using v2 format if err := createNewV2File(1, cfg); err != nil { return nil, err @@ -98,6 +97,9 @@ func NewFileDAO(cfg db.Config) (FileDAO, error) { } switch header.Version { + case FileLegacyAuxiliary: + // default chain db file is legacy format, but not master, the master file has been corrupted + return nil, ErrFileInvalid case FileLegacyMaster: // master file is legacy format return CreateFileDAO(true, cfg) diff --git a/blockchain/filedao/filedao_test.go b/blockchain/filedao/filedao_test.go index 840df82483..b286284b3d 100644 --- a/blockchain/filedao/filedao_test.go +++ b/blockchain/filedao/filedao_test.go @@ -140,7 +140,7 @@ func TestNewFileDAOSplitV2(t *testing.T) { defer os.RemoveAll(cfg.DbPath) // test non-existing file - _, err := checkMasterChainDBFile(cfg.DbPath) + _, err := readFileHeader(cfg.DbPath, FileAll) r.Equal(ErrFileNotExist, err) // test empty db file, this will create new v2 file diff --git a/blockchain/filedao/filedao_util.go b/blockchain/filedao/filedao_util.go index fd20c67ca5..6ff7388cc8 100644 --- a/blockchain/filedao/filedao_util.go +++ b/blockchain/filedao/filedao_util.go @@ -20,23 +20,6 @@ import ( "github.com/iotexproject/iotex-core/db" ) -func checkMasterChainDBFile(defaultName string) (*FileHeader, error) { - h, err := readFileHeader(defaultName, FileAll) - if err == ErrFileNotExist || err == ErrFileInvalid || err == ErrFileCantAccess { - return nil, err - } - - switch h.Version { - case FileLegacyAuxiliary: - // default chain db file is legacy format, but not master, the master file has been corrupted - return h, ErrFileInvalid - case FileLegacyMaster, FileV2: - return h, nil - default: - panic(fmt.Errorf("corrupted file version: %s", h.Version)) - } -} - func readFileHeader(filename, fileType string) (*FileHeader, error) { if err := fileExists(filename); err != nil { return nil, err diff --git a/ioctl/newcmd/node/node.go b/ioctl/newcmd/node/node.go index 2edadda33b..a6fd4a46c9 100644 --- a/ioctl/newcmd/node/node.go +++ b/ioctl/newcmd/node/node.go @@ -2,7 +2,7 @@ package node import ( "github.com/spf13/cobra" - + "github.com/iotexproject/iotex-core/ioctl" "github.com/iotexproject/iotex-core/ioctl/config" )