From 5cc6dd4b111a48a7099d37da9bfe6493d0da9d20 Mon Sep 17 00:00:00 2001 From: Jongwon Park Date: Tue, 26 Nov 2024 18:28:40 -0600 Subject: [PATCH] fix(rollback): config cycle import --- client/app/rollback.go | 5 +++-- client/cmd/flags.go | 2 +- client/cmd/rollback.go | 18 +++--------------- client/config/rollback.go | 13 +++++++++++++ 4 files changed, 20 insertions(+), 18 deletions(-) create mode 100644 client/config/rollback.go diff --git a/client/app/rollback.go b/client/app/rollback.go index fe0a30f1..cb967ecf 100644 --- a/client/app/rollback.go +++ b/client/app/rollback.go @@ -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 { diff --git a/client/cmd/flags.go b/client/cmd/flags.go index d678274f..9be5a7ed 100644 --- a/client/cmd/flags.go +++ b/client/cmd/flags.go @@ -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") } diff --git a/client/cmd/rollback.go b/client/cmd/rollback.go index 8733c1ab..319264f7 100644 --- a/client/cmd/rollback.go +++ b/client/cmd/rollback.go @@ -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{ diff --git a/client/config/rollback.go b/client/config/rollback.go new file mode 100644 index 00000000..c02a7da4 --- /dev/null +++ b/client/config/rollback.go @@ -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, + } +}