11package server
22
33import (
4+ "errors"
45 "fmt"
56
6- cmtcmd "github.com/cometbft/cometbft/cmd/cometbft/commands"
77 "github.com/spf13/cobra"
88
99 "github.com/cosmos/cosmos-sdk/client/flags"
@@ -12,8 +12,10 @@ import (
1212
1313// NewRollbackCmd creates a command to rollback CometBFT and multistore state by one height.
1414func NewRollbackCmd (appCreator types.AppCreator , defaultNodeHome string ) * cobra.Command {
15- var removeBlock bool
16-
15+ var (
16+ removeBlock bool
17+ height int64
18+ )
1719 cmd := & cobra.Command {
1820 Use : "rollback" ,
1921 Short : "rollback Cosmos SDK and CometBFT state by one height" ,
@@ -35,22 +37,26 @@ application.
3537 }
3638 app := appCreator (ctx .Logger , db , nil , ctx .Viper )
3739 // rollback CometBFT state
38- height , hash , err := cmtcmd .RollbackState (ctx .Config , removeBlock )
39- if err != nil {
40- return fmt .Errorf ("failed to rollback CometBFT state: %w" , err )
41- }
40+ // height, hash, err := cmtcmd.RollbackState(ctx.Config, removeBlock)
41+ // if err != nil {
42+ // return fmt.Errorf("failed to rollback CometBFT state: %w", err)
43+ // }
4244 // rollback the multistore
45+ if height == 0 {
46+ return errors .New ("cannot rollback to height 0" )
47+ }
4348
4449 if err := app .CommitMultiStore ().RollbackToVersion (height ); err != nil {
4550 return fmt .Errorf ("failed to rollback to version: %w" , err )
4651 }
4752
48- fmt .Printf ("Rolled back state to height %d and hash %X " , height , hash )
53+ fmt .Printf ("Rolled back state to height %d" , height )
4954 return nil
5055 },
5156 }
5257
5358 cmd .Flags ().String (flags .FlagHome , defaultNodeHome , "The application home directory" )
5459 cmd .Flags ().BoolVar (& removeBlock , "hard" , false , "remove last block as well as state" )
60+ cmd .Flags ().Int64Var (& height , "height" , 0 , "height to rollback to" )
5561 return cmd
5662}
0 commit comments