Skip to content

Commit

Permalink
Problem: changeset verify command return wrong app-hash on old blocks (
Browse files Browse the repository at this point in the history
…#985)

* Problem: changeset verify command return wrong app-hash on old blocks

Solution:
- skip the stores who are added after the target version

* Update CHANGELOG.md

Signed-off-by: yihuang <huang@crypto.com>

---------

Signed-off-by: yihuang <huang@crypto.com>
  • Loading branch information
yihuang authored Apr 20, 2023
1 parent 62907e6 commit b9d5761
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
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.
- [#985](https://github.com/crypto-org-chain/cronos/pull/985) Fix versiondb verify command on older versions

*Feb 09, 2022*

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
22 changes: 10 additions & 12 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,19 +190,9 @@ 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
}
Expand All @@ -208,6 +202,10 @@ func verifyOneStore(tree *memiavl.Tree, store, changeSetDir, saveSnapshot string
}
// 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

0 comments on commit b9d5761

Please sign in to comment.