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
Changes from 2 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
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 @@
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 @@
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 / golangci-lint

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 / Analyze

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 {
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("Setting MaxValidators parameter...")
err = SetMaxValidators(ctx, *keepers.StakingKeeper)
Expand Down Expand Up @@ -87,6 +96,21 @@
}
}

// 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{}
consensusKeeper.ParamsStore.Set(ctx, params)

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)

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)
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
Loading