Skip to content

Commit

Permalink
disable cometbft rollback
Browse files Browse the repository at this point in the history
  • Loading branch information
gupadhyaya committed Nov 20, 2024
1 parent c4d9a49 commit f698a77
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions server/rollback.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package server

import (
"errors"
"fmt"

cmtcmd "github.com/cometbft/cometbft/cmd/cometbft/commands"
"github.com/spf13/cobra"

"github.com/cosmos/cosmos-sdk/client/flags"
Expand All @@ -12,8 +12,10 @@ import (

// NewRollbackCmd creates a command to rollback CometBFT and multistore state by one height.
func NewRollbackCmd(appCreator types.AppCreator, defaultNodeHome string) *cobra.Command {
var removeBlock bool

var (
removeBlock bool
height int64
)
cmd := &cobra.Command{
Use: "rollback",
Short: "rollback Cosmos SDK and CometBFT state by one height",
Expand All @@ -35,22 +37,26 @@ application.
}
app := appCreator(ctx.Logger, db, nil, ctx.Viper)
// rollback CometBFT state
height, hash, err := cmtcmd.RollbackState(ctx.Config, removeBlock)
if err != nil {
return fmt.Errorf("failed to rollback CometBFT state: %w", err)
}
// height, hash, err := cmtcmd.RollbackState(ctx.Config, removeBlock)
// if err != nil {
// return fmt.Errorf("failed to rollback CometBFT state: %w", err)
// }
// rollback the multistore
if height == 0 {
return errors.New("cannot rollback to height 0")
}

if err := app.CommitMultiStore().RollbackToVersion(height); err != nil {
return fmt.Errorf("failed to rollback to version: %w", err)
}

fmt.Printf("Rolled back state to height %d and hash %X", height, hash)
fmt.Printf("Rolled back state to height %d", height)
return nil
},
}

cmd.Flags().String(flags.FlagHome, defaultNodeHome, "The application home directory")
cmd.Flags().BoolVar(&removeBlock, "hard", false, "remove last block as well as state")
cmd.Flags().Int64Var(&height, "height", 0, "height to rollback to")
return cmd
}

0 comments on commit f698a77

Please sign in to comment.