Skip to content

Commit

Permalink
fix(rollback): config cycle import
Browse files Browse the repository at this point in the history
  • Loading branch information
jdubpark committed Nov 27, 2024
1 parent e78cb90 commit 5cc6dd4
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 18 deletions.
5 changes: 3 additions & 2 deletions client/app/rollback.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package app
import (
cmtcmd "github.com/cometbft/cometbft/cmd/cometbft/commands"
cmtcfg "github.com/cometbft/cometbft/config"
"github.com/piplabs/story/client/cmd"

"github.com/piplabs/story/client/config"
"github.com/piplabs/story/lib/errors"
)

func RollbackCometAndAppState(a *App, cometCfg cmtcfg.Config, rollbackCfg cmd.RollbackConfig) (lastHeight int64, lastHash []byte, err error) {
func RollbackCometAndAppState(a *App, cometCfg cmtcfg.Config, rollbackCfg config.RollbackConfig) (lastHeight int64, lastHash []byte, err error) {
for range rollbackCfg.RollbackHeights {
lastHeight, lastHash, err = cmtcmd.RollbackState(&cometCfg, rollbackCfg.RemoveBlock)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion client/cmd/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func bindKeyConvertFlags(cmd *cobra.Command, cfg *keyConfig) {
cmd.Flags().StringVar(&cfg.PubKeyHexUncompressed, "pubkey-hex-uncompressed", "", "Uncompressed public key in hex format")
}

func bindRollbackFlags(cmd *cobra.Command, cfg *RollbackConfig) {
func bindRollbackFlags(cmd *cobra.Command, cfg *config.RollbackConfig) {
cmd.Flags().BoolVar(&cfg.RemoveBlock, "hard", false, "remove Cosmos & CometBFT blocks as well as states")
cmd.Flags().Uint64VarP(&cfg.RollbackHeights, "number", "n", 1, "number of blocks to rollback")
}
Expand Down
18 changes: 3 additions & 15 deletions client/cmd/rollback.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,15 @@ import (
"github.com/spf13/cobra"

"github.com/piplabs/story/client/app"
storycfg "github.com/piplabs/story/client/config"
cfg "github.com/piplabs/story/client/config"
libcmd "github.com/piplabs/story/lib/cmd"
"github.com/piplabs/story/lib/log"
)

type RollbackConfig struct {
RemoveBlock bool // See cosmos-sdk/server/rollback.go
RollbackHeights uint64
}

func DefaultConfig() RollbackConfig {
return RollbackConfig{
RemoveBlock: false,
RollbackHeights: 1,
}
}

// newRollbackCmd returns a new cobra command that rolls back one block of the story consensus client.
func newRollbackCmd(appCreateFunc func(context.Context, app.Config) *app.App) *cobra.Command {
rollbackCfg := DefaultConfig()
storyCfg := storycfg.DefaultConfig()
rollbackCfg := cfg.DefaultRollbackConfig()
storyCfg := cfg.DefaultConfig()
logCfg := log.DefaultConfig()

cmd := &cobra.Command{
Expand Down
13 changes: 13 additions & 0 deletions client/config/rollback.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package config

type RollbackConfig struct {
RemoveBlock bool // See cosmos-sdk/server/rollback.go
RollbackHeights uint64
}

func DefaultRollbackConfig() RollbackConfig {
return RollbackConfig{
RemoveBlock: false,
RollbackHeights: 1,
}
}

0 comments on commit 5cc6dd4

Please sign in to comment.