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
…crypto-org-chain#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 committed Apr 21, 2023
1 parent 53cc988 commit 2b2b384
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
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

0 comments on commit 2b2b384

Please sign in to comment.