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 #985

Merged
merged 12 commits into from
Apr 20, 2023
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
- [#924](/~https://github.com/crypto-org-chain/cronos/pull/924) memiavl support `Export` API.
- [#934](/~https://github.com/crypto-org-chain/cronos/pull/934) Add pebbledb backend.
- [#950](/~https://github.com/crypto-org-chain/cronos/pull/950) Implement memiavl and integrate with state machine.
- [#]() Fix versiondb verify command on older versions
yihuang marked this conversation as resolved.
Show resolved Hide resolved
yihuang marked this conversation as resolved.
Show resolved Hide resolved

*Feb 09, 2022*

Expand Down
13 changes: 13 additions & 0 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,11 +190,16 @@ 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 {
if os.IsNotExist(err) {
// assume the change set files are taken from older versions, don't include all stores.
return nil, nil
}
return nil, err
}
fileNames := make([]string, len(entries))
Expand All @@ -208,6 +217,10 @@ func verifyOneStore(tree *memiavl.Tree, store, changeSetDir, saveSnapshot string
}
// set the initial version for the store
initialVersion := filesWithVersion[0].Version
if initialVersion > uint64(targetVersion) {
Fixed Show fixed Hide fixed
Fixed Show fixed Hide fixed
yihuang marked this conversation as resolved.
Show resolved Hide resolved
return nil, nil
}

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