Skip to content

Commit

Permalink
Fix Seid Rollback state mismatch
Browse files Browse the repository at this point in the history
  • Loading branch information
yzang2019 committed Dec 4, 2024
1 parent 73e5eda commit 1941305
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
4 changes: 2 additions & 2 deletions server/rollback.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ when Tendermint has persisted an incorrect app hash and is thus unable to make
progress. Rollback overwrites a state at height n with the state at height n - 1.
The application also roll back to height n - 1. No blocks are removed, so upon
restarting Tendermint the transactions in block n will be re-executed against the
application.
application. If you wanna rollback multiple blocks, please add --hard option.
`,
RunE: func(cmd *cobra.Command, args []string) error {
ctx := GetServerContextFromCmd(cmd)
Expand Down Expand Up @@ -54,7 +54,7 @@ application.

// rollback the app state
lastCommit = app.CommitMultiStore().LastCommitID()
fmt.Printf("App state height %d and hash %X\n", lastCommit.GetVersion(), lastCommit.GetHash())
fmt.Printf("CMS app state height %d and hash %X\n", lastCommit.GetVersion(), lastCommit.GetHash())
fmt.Printf("Attempting to rollback app state to height=%d\n", tmHeight)
if err := app.CommitMultiStore().RollbackToVersion(tmHeight); err != nil {
return fmt.Errorf("failed to rollback to version: %w", err)
Expand Down
12 changes: 11 additions & 1 deletion storev2/rootmulti/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,17 @@ func (rs *Store) RollbackToVersion(target int64) error {
if target > math.MaxUint32 {
return fmt.Errorf("rollback height target %d exceeds max uint32", target)
}
return rs.scStore.Rollback(target)
err := rs.scStore.Rollback(target)
if err != nil {
return err
}
// to keep the root hash compatible with cosmos-sdk 0.46
if rs.scStore.Version() != 0 {
fmt.Printf("Rolled back CMS to version %d\n", rs.scStore.Version())
rs.lastCommitInfo = convertCommitInfo(rs.scStore.LastCommitInfo())
rs.lastCommitInfo = amendCommitInfo(rs.lastCommitInfo, rs.storesParams)
}
return nil
}

// getStoreByName performs a lookup of a StoreKey given a store name typically
Expand Down

0 comments on commit 1941305

Please sign in to comment.