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

Problem: changeset verify command return wrong app-hash on old blocks (backport #985) #993

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- [#986](/~https://github.com/crypto-org-chain/cronos/pull/986) Use go 1.20.
- [#984](/~https://github.com/crypto-org-chain/cronos/pull/984) experimental integration of memiavl.
- [#985](/~https://github.com/crypto-org-chain/cronos/pull/985) Fix versiondb verify command on older versions

*April 13, 2023*

Expand Down
7 changes: 7 additions & 0 deletions versiondb/client/convert_to_sst.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ func convertSingleStore(store string, changeSetDir, sstDir string, sstFileSize u
if err != nil {
return err
}
if len(csFiles) == 0 {
return nil
}

prefix := []byte(fmt.Sprintf(tsrocksdb.StorePrefixTpl, store))
isEmpty := true
Expand Down Expand Up @@ -179,6 +182,10 @@ func scanChangeSetFiles(changeSetDir, store string) ([]FileWithVersion, error) {
storeDir := filepath.Join(changeSetDir, store)
entries, err := os.ReadDir(storeDir)
if err != nil {
// assume the change set files are taken from older versions, don't include all stores.
if os.IsNotExist(err) {
return nil, nil
}
return nil, err
}
fileNames := make([]string, len(entries))
Expand Down
24 changes: 11 additions & 13 deletions versiondb/client/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ func VerifyChangeSetCmd(defaultStores []string) *cobra.Command {
if err != nil {
return err
}
if storeInfo == nil {
// the store don't exist before target version, don't affect the commit info and app hash.
return nil
}

storeInfosLock.Lock()
defer storeInfosLock.Unlock()
Expand Down Expand Up @@ -186,28 +190,22 @@ func VerifyChangeSetCmd(defaultStores []string) *cobra.Command {
}

// verifyOneStore process a single store, can run in parallel with other stores.
// if the store don't exist before the `targetVersion`, returns nil without error.
func verifyOneStore(tree *memiavl.Tree, store, changeSetDir, saveSnapshot string, targetVersion int64, buildHashIndex bool) (*storetypes.StoreInfo, error) {
// scan directory to find the change set files
storeDir := filepath.Join(changeSetDir, store)
entries, err := os.ReadDir(storeDir)
if err != nil {
return nil, err
}
fileNames := make([]string, len(entries))
for i, entry := range entries {
fileNames[i] = filepath.Join(storeDir, entry.Name())
}

filesWithVersion, err := SortFilesByFirstVerson(fileNames)
filesWithVersion, err := scanChangeSetFiles(changeSetDir, store)
if err != nil {
return nil, err
}

if len(filesWithVersion) == 0 {
return nil, fmt.Errorf("change set directory is empty")
return nil, nil
}
// set the initial version for the store
initialVersion := filesWithVersion[0].Version
if targetVersion > 0 && initialVersion > uint64(targetVersion) {
return nil, nil
}

if err := tree.SetInitialVersion(int64(initialVersion)); err != nil {
return nil, err
}
Expand Down