Skip to content

Commit b9d5761

Browse files
author
yihuang
authored
Problem: changeset verify command return wrong app-hash on old blocks (#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>
1 parent 62907e6 commit b9d5761

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
- [#924](https://github.com/crypto-org-chain/cronos/pull/924) memiavl support `Export` API.
2929
- [#934](https://github.com/crypto-org-chain/cronos/pull/934) Add pebbledb backend.
3030
- [#950](https://github.com/crypto-org-chain/cronos/pull/950) Implement memiavl and integrate with state machine.
31+
- [#985](https://github.com/crypto-org-chain/cronos/pull/985) Fix versiondb verify command on older versions
3132

3233
*Feb 09, 2022*
3334

versiondb/client/convert_to_sst.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ func convertSingleStore(store string, changeSetDir, sstDir string, sstFileSize u
9090
if err != nil {
9191
return err
9292
}
93+
if len(csFiles) == 0 {
94+
return nil
95+
}
9396

9497
prefix := []byte(fmt.Sprintf(tsrocksdb.StorePrefixTpl, store))
9598
isEmpty := true
@@ -179,6 +182,10 @@ func scanChangeSetFiles(changeSetDir, store string) ([]FileWithVersion, error) {
179182
storeDir := filepath.Join(changeSetDir, store)
180183
entries, err := os.ReadDir(storeDir)
181184
if err != nil {
185+
// assume the change set files are taken from older versions, don't include all stores.
186+
if os.IsNotExist(err) {
187+
return nil, nil
188+
}
182189
return nil, err
183190
}
184191
fileNames := make([]string, len(entries))

versiondb/client/verify.go

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ func VerifyChangeSetCmd(defaultStores []string) *cobra.Command {
105105
if err != nil {
106106
return err
107107
}
108+
if storeInfo == nil {
109+
// the store don't exist before target version, don't affect the commit info and app hash.
110+
return nil
111+
}
108112

109113
storeInfosLock.Lock()
110114
defer storeInfosLock.Unlock()
@@ -186,19 +190,9 @@ func VerifyChangeSetCmd(defaultStores []string) *cobra.Command {
186190
}
187191

188192
// verifyOneStore process a single store, can run in parallel with other stores.
193+
// if the store don't exist before the `targetVersion`, returns nil without error.
189194
func verifyOneStore(tree *memiavl.Tree, store, changeSetDir, saveSnapshot string, targetVersion int64, buildHashIndex bool) (*storetypes.StoreInfo, error) {
190-
// scan directory to find the change set files
191-
storeDir := filepath.Join(changeSetDir, store)
192-
entries, err := os.ReadDir(storeDir)
193-
if err != nil {
194-
return nil, err
195-
}
196-
fileNames := make([]string, len(entries))
197-
for i, entry := range entries {
198-
fileNames[i] = filepath.Join(storeDir, entry.Name())
199-
}
200-
201-
filesWithVersion, err := SortFilesByFirstVerson(fileNames)
195+
filesWithVersion, err := scanChangeSetFiles(changeSetDir, store)
202196
if err != nil {
203197
return nil, err
204198
}
@@ -208,6 +202,10 @@ func verifyOneStore(tree *memiavl.Tree, store, changeSetDir, saveSnapshot string
208202
}
209203
// set the initial version for the store
210204
initialVersion := filesWithVersion[0].Version
205+
if targetVersion > 0 && initialVersion > uint64(targetVersion) {
206+
return nil, nil
207+
}
208+
211209
if err := tree.SetInitialVersion(int64(initialVersion)); err != nil {
212210
return nil, err
213211
}

0 commit comments

Comments
 (0)