Skip to content

Commit

Permalink
fix!: initialize ConsensusParams Version field
Browse files Browse the repository at this point in the history
  • Loading branch information
MSalopek committed Sep 12, 2024
1 parent fbd214a commit 81303da
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions app/upgrades/v20/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)

Check failure on line 60 in app/upgrades/v20/upgrades.go

View workflow job for this annotation

GitHub Actions / Analyze

SA4001: *&x will be simplified to x. It will not copy x. (staticcheck)

Check failure on line 60 in app/upgrades/v20/upgrades.go

View workflow job for this annotation

GitHub Actions / golangci-lint

SA4001: *&x will be simplified to x. It will not copy x. (staticcheck)

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)
Expand Down Expand Up @@ -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)

Check failure on line 110 in app/upgrades/v20/upgrades.go

View workflow job for this annotation

GitHub Actions / Analyze

Error return value of `consensusKeeper.ParamsStore.Set` is not checked (errcheck)

Check failure on line 110 in app/upgrades/v20/upgrades.go

View workflow job for this annotation

GitHub Actions / golangci-lint

Error return value of `consensusKeeper.ParamsStore.Set` is not checked (errcheck)
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,
Expand Down

0 comments on commit 81303da

Please sign in to comment.