From 6cfe2dc1bb370ab8a5bd572505afba19c7b4c584 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 28 Nov 2024 15:52:53 +0100 Subject: [PATCH] feat(server/v2,upgrade): add skip upgrade flag (#22682) --- server/v2/flags.go | 5 +++-- server/v2/server.go | 1 + x/upgrade/depinject.go | 13 +++++++++++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/server/v2/flags.go b/server/v2/flags.go index 46925cc526e5..f065556b50ef 100644 --- a/server/v2/flags.go +++ b/server/v2/flags.go @@ -10,8 +10,9 @@ func prefix(f string) string { } var ( - FlagMinGasPrices = prefix("minimum-gas-prices") - FlagCPUProfiling = prefix("cpu-profile") + FlagMinGasPrices = prefix("minimum-gas-prices") + FlagCPUProfiling = prefix("cpu-profile") + FlagUnsafeSkipUpgrades = prefix("unsafe-skip-upgrades") ) const ( diff --git a/server/v2/server.go b/server/v2/server.go index 191c42d0651d..5dd8a73d76ad 100644 --- a/server/v2/server.go +++ b/server/v2/server.go @@ -184,6 +184,7 @@ func (s *Server[T]) StartCmdFlags() *pflag.FlagSet { flags := pflag.NewFlagSet(s.Name(), pflag.ExitOnError) flags.String(FlagMinGasPrices, "", "Minimum gas prices to accept for transactions; Any fee in a tx must meet this minimum (e.g. 0.01photino;0.0001stake)") flags.String(FlagCPUProfiling, "", "Enable CPU profiling and write to the specified file") + flags.IntSlice(FlagUnsafeSkipUpgrades, []int{}, "Skip a set of upgrade heights to continue the old binary") return flags } diff --git a/x/upgrade/depinject.go b/x/upgrade/depinject.go index 01b93356fdf0..d12c0ea9a3b3 100644 --- a/x/upgrade/depinject.go +++ b/x/upgrade/depinject.go @@ -19,6 +19,10 @@ import ( authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" ) +// flagUnsafeSkipUpgradesV2 is a custom flag that allows the user to skip upgrades +// It is used in a v2 chain. +const flagUnsafeSkipUpgradesV2 = "server.unsafe-skip-upgrades" + var _ depinject.OnePerModuleType = AppModule{} // IsOnePerModuleType implements the depinject.OnePerModuleType interface. @@ -36,6 +40,7 @@ func ProvideConfig(key depinject.OwnModuleKey) coreserver.ModuleConfigMap { Module: depinject.ModuleKey(key).Name(), Config: coreserver.ConfigMap{ server.FlagUnsafeSkipUpgrades: []int{}, + flagUnsafeSkipUpgradesV2: []int{}, flags.FlagHome: "", }, } @@ -66,10 +71,14 @@ func ProvideModule(in ModuleInputs) ModuleOutputs { skipUpgradeHeights = make(map[int64]bool) ) - skipUpgrades, ok := in.ConfigMap[server.FlagUnsafeSkipUpgrades] + skipUpgrades, ok := in.ConfigMap[flagUnsafeSkipUpgradesV2] // check v2 if !ok || skipUpgrades == nil { - skipUpgrades = []int{} + skipUpgrades, ok = in.ConfigMap[server.FlagUnsafeSkipUpgrades] // check v1 + if !ok || skipUpgrades == nil { + skipUpgrades = []int{} + } } + heights := cast.ToIntSlice(skipUpgrades) // safe to use cast here as we've handled nil case for _, h := range heights { skipUpgradeHeights[int64(h)] = true