Skip to content

Commit

Permalink
feat(server/v2,upgrade): add skip upgrade flag (#22682)
Browse files Browse the repository at this point in the history
  • Loading branch information
julienrbrt authored Nov 28, 2024
1 parent 9caec06 commit 6cfe2dc
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
5 changes: 3 additions & 2 deletions server/v2/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
1 change: 1 addition & 0 deletions server/v2/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
13 changes: 11 additions & 2 deletions x/upgrade/depinject.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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: "",
},
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 6cfe2dc

Please sign in to comment.