Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[filedao] remove checkMasterChainDBFile() #3463

Merged
merged 2 commits into from
Jun 27, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions blockchain/filedao/filedao.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Copy link
Member Author

@dustinxie dustinxie Jun 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the only case (from removed func) that needs to be taken care of here

case FileLegacyMaster:
// master file is legacy format
return CreateFileDAO(true, cfg)
Expand Down
2 changes: 1 addition & 1 deletion blockchain/filedao/filedao_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 0 additions & 17 deletions blockchain/filedao/filedao_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

most code are redundant with those above, so remove it


func readFileHeader(filename, fileType string) (*FileHeader, error) {
if err := fileExists(filename); err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion ioctl/newcmd/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package node

import (
"github.com/spf13/cobra"

"github.com/iotexproject/iotex-core/ioctl"
"github.com/iotexproject/iotex-core/ioctl/config"
)
Expand Down