Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix!: initialize ConsensusParams Version field #3333

Merged
merged 3 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Migrate consensus params - initialize Version field
([\#3333](https://github.com/cosmos/gaia/pull/3333))
24 changes: 24 additions & 0 deletions app/upgrades/v20/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ 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"

Expand All @@ -15,6 +17,7 @@ import (
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"
Expand Down Expand Up @@ -54,6 +57,13 @@ func CreateUpgradeHandler(
return vm, errorsmod.Wrapf(err, "running module migrations")
}

ctx.Logger().Info("Initializing ConsensusParam Version...")
err = InitializeConsensusParamVersion(ctx, keepers.ConsensusParamsKeeper)
if err != nil {
MSalopek marked this conversation as resolved.
Show resolved Hide resolved
// 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)

Expand Down Expand Up @@ -87,6 +97,20 @@ 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 {
MSalopek marked this conversation as resolved.
Show resolved Hide resolved
params, err := consensusKeeper.ParamsStore.Get(ctx)
if err != nil {
return err
}
params.Version = &cmtproto.VersionParams{}
return consensusKeeper.ParamsStore.Set(ctx, params)
}

// 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,
Expand Down
Loading