From 81303da9d10907d1f0c3caa34d1cf50719b40f72 Mon Sep 17 00:00:00 2001 From: MSalopek Date: Thu, 12 Sep 2024 20:28:29 +0200 Subject: [PATCH 1/3] fix!: initialize ConsensusParams Version field --- app/upgrades/v20/upgrades.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/app/upgrades/v20/upgrades.go b/app/upgrades/v20/upgrades.go index 15e43b63a05..68101a2cbbf 100644 --- a/app/upgrades/v20/upgrades.go +++ b/app/upgrades/v20/upgrades.go @@ -11,10 +11,12 @@ import ( errorsmod "cosmossdk.io/errors" upgradetypes "cosmossdk.io/x/upgrade/types" + cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" codec "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + consensusparamkeeper "github.com/cosmos/cosmos-sdk/x/consensus/keeper" govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" govtypesv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" @@ -54,8 +56,15 @@ func CreateUpgradeHandler( return vm, errorsmod.Wrapf(err, "running module migrations") } + ctx.Logger().Info("Initializing ConsensusParam Version...") + err = InitializeConsensusParamVersion(ctx, *&keepers.ConsensusParamsKeeper) + ctx.Logger().Info("Initializing MaxProviderConsensusValidators parameter...") InitializeMaxProviderConsensusParam(ctx, keepers.ProviderKeeper) + if err != nil { + // don't hard fail here, as this is not critical for the upgrade to succeed + ctx.Logger().Error("Error initializing ConsensusParam Version:", "message", err.Error()) + } ctx.Logger().Info("Setting MaxValidators parameter...") err = SetMaxValidators(ctx, *keepers.StakingKeeper) @@ -87,6 +96,21 @@ func CreateUpgradeHandler( } } +// InitializeConsensusParamVersion initializes the consumer params that were missed in a consensus keeper migration. +// Some fields were set to nil values instead of zero values, which causes a panic during Txs to modify the params. +// Context: +// - https://github.com/cosmos/cosmos-sdk/issues/21483 +// - https://github.com/cosmos/cosmos-sdk/pull/21484/ +func InitializeConsensusParamVersion(ctx sdk.Context, consensusKeeper consensusparamkeeper.Keeper) error { + params, err := consensusKeeper.ParamsStore.Get(ctx) + if err != nil { + return err + } + params.Version = &cmtproto.VersionParams{} + consensusKeeper.ParamsStore.Set(ctx, params) + return nil +} + // InitializeMaxProviderConsensusParam initializes the MaxProviderConsensusValidators parameter. // It is set to 180, which is the current number of validators participating in consensus on the Cosmos Hub. // This parameter will be used to govern the number of validators participating in consensus on the Cosmos Hub, From 28d46926c65eb4309a8b941574257a53b5c52841 Mon Sep 17 00:00:00 2001 From: MSalopek Date: Thu, 12 Sep 2024 20:29:37 +0200 Subject: [PATCH 2/3] Update upgrades.go --- app/upgrades/v20/upgrades.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/upgrades/v20/upgrades.go b/app/upgrades/v20/upgrades.go index 68101a2cbbf..16ac1c72967 100644 --- a/app/upgrades/v20/upgrades.go +++ b/app/upgrades/v20/upgrades.go @@ -100,7 +100,7 @@ func CreateUpgradeHandler( // Some fields were set to nil values instead of zero values, which causes a panic during Txs to modify the params. // Context: // - https://github.com/cosmos/cosmos-sdk/issues/21483 -// - https://github.com/cosmos/cosmos-sdk/pull/21484/ +// - https://github.com/cosmos/cosmos-sdk/pull/21484 func InitializeConsensusParamVersion(ctx sdk.Context, consensusKeeper consensusparamkeeper.Keeper) error { params, err := consensusKeeper.ParamsStore.Get(ctx) if err != nil { From a658478a210c82e05e18e233e4c027c3dbdd8291 Mon Sep 17 00:00:00 2001 From: MSalopek Date: Fri, 13 Sep 2024 14:36:36 +0200 Subject: [PATCH 3/3] fix: mv err; add changelogs --- .../bug-fixes/3333-migrate-consensus-params.md | 2 ++ app/upgrades/v20/upgrades.go | 14 +++++++------- 2 files changed, 9 insertions(+), 7 deletions(-) create mode 100644 .changelog/unreleased/bug-fixes/3333-migrate-consensus-params.md diff --git a/.changelog/unreleased/bug-fixes/3333-migrate-consensus-params.md b/.changelog/unreleased/bug-fixes/3333-migrate-consensus-params.md new file mode 100644 index 00000000000..14130a94e78 --- /dev/null +++ b/.changelog/unreleased/bug-fixes/3333-migrate-consensus-params.md @@ -0,0 +1,2 @@ +- Migrate consensus params - initialize Version field + ([\#3333](https://github.com/cosmos/gaia/pull/3333)) diff --git a/app/upgrades/v20/upgrades.go b/app/upgrades/v20/upgrades.go index 16ac1c72967..6969cd00cbe 100644 --- a/app/upgrades/v20/upgrades.go +++ b/app/upgrades/v20/upgrades.go @@ -5,13 +5,14 @@ import ( "encoding/json" "fmt" + cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" + providerkeeper "github.com/cosmos/interchain-security/v6/x/ccv/provider/keeper" providertypes "github.com/cosmos/interchain-security/v6/x/ccv/provider/types" errorsmod "cosmossdk.io/errors" upgradetypes "cosmossdk.io/x/upgrade/types" - cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" codec "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" @@ -57,15 +58,15 @@ func CreateUpgradeHandler( } ctx.Logger().Info("Initializing ConsensusParam Version...") - err = InitializeConsensusParamVersion(ctx, *&keepers.ConsensusParamsKeeper) - - ctx.Logger().Info("Initializing MaxProviderConsensusValidators parameter...") - InitializeMaxProviderConsensusParam(ctx, keepers.ProviderKeeper) + err = InitializeConsensusParamVersion(ctx, keepers.ConsensusParamsKeeper) if err != nil { // don't hard fail here, as this is not critical for the upgrade to succeed ctx.Logger().Error("Error initializing ConsensusParam Version:", "message", err.Error()) } + ctx.Logger().Info("Initializing MaxProviderConsensusValidators parameter...") + InitializeMaxProviderConsensusParam(ctx, keepers.ProviderKeeper) + ctx.Logger().Info("Setting MaxValidators parameter...") err = SetMaxValidators(ctx, *keepers.StakingKeeper) if err != nil { @@ -107,8 +108,7 @@ func InitializeConsensusParamVersion(ctx sdk.Context, consensusKeeper consensusp return err } params.Version = &cmtproto.VersionParams{} - consensusKeeper.ParamsStore.Set(ctx, params) - return nil + return consensusKeeper.ParamsStore.Set(ctx, params) } // InitializeMaxProviderConsensusParam initializes the MaxProviderConsensusValidators parameter.