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

feat: add version params to parameters #9432

Merged
merged 12 commits into from
Jul 8, 2021
8 changes: 8 additions & 0 deletions baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,13 @@ func (app *BaseApp) GetConsensusParams(ctx sdk.Context) *abci.ConsensusParams {
cp.Validator = &vp
}

if app.paramStore.Has(ctx, ParamStoreKeyVersionParams) {
var vp tmproto.VersionParams

app.paramStore.Get(ctx, ParamStoreKeyVersionParams, &vp)
cp.Version = &vp
}

return cp
}

Expand All @@ -449,6 +456,7 @@ func (app *BaseApp) StoreConsensusParams(ctx sdk.Context, cp *abci.ConsensusPara
app.paramStore.Set(ctx, ParamStoreKeyBlockParams, cp.Block)
app.paramStore.Set(ctx, ParamStoreKeyEvidenceParams, cp.Evidence)
app.paramStore.Set(ctx, ParamStoreKeyValidatorParams, cp.Validator)
app.paramStore.Set(ctx, ParamStoreKeyVersionParams, cp.Version)
tac0turtle marked this conversation as resolved.
Show resolved Hide resolved
}

// getMaximumBlockGas gets the maximum gas from the consensus params. It panics
Expand Down
12 changes: 12 additions & 0 deletions baseapp/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ var (
ParamStoreKeyBlockParams = []byte("BlockParams")
ParamStoreKeyEvidenceParams = []byte("EvidenceParams")
ParamStoreKeyValidatorParams = []byte("ValidatorParams")
ParamStoreKeyVersionParams = []byte("VersionParams")
)

// ParamStore defines the interface the parameter store used by the BaseApp must
Expand Down Expand Up @@ -84,3 +85,14 @@ func ValidateValidatorParams(i interface{}) error {

return nil
}

// ValidateVersionParams defines a stateless validation on VersionParams. This
// function is called whenever the parameters are updated or stored.
func ValidateVersionParams(i interface{}) error {
_, ok := i.(tmproto.VersionParams)
likhita-809 marked this conversation as resolved.
Show resolved Hide resolved
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}

return nil
}
2 changes: 1 addition & 1 deletion simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ func NewSimApp(
app.ParamsKeeper = initParamsKeeper(appCodec, legacyAmino, keys[paramstypes.StoreKey], tkeys[paramstypes.TStoreKey])

// set the BaseApp's parameter store
bApp.SetParamStore(app.ParamsKeeper.Subspace(baseapp.Paramspace).WithKeyTable(paramskeeper.ConsensusParamsKeyTable()))
bApp.SetParamStore(app.ParamsKeeper.Subspace(baseapp.Paramspace).WithKeyTable(paramstypes.ConsensusParamsKeyTable()))

app.CapabilityKeeper = capabilitykeeper.NewKeeper(appCodec, keys[capabilitytypes.StoreKey], memKeys[capabilitytypes.MemStoreKey])

Expand Down
23 changes: 23 additions & 0 deletions x/params/keeper/migrations.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package keeper

import (
"github.com/cosmos/cosmos-sdk/baseapp"
sdk "github.com/cosmos/cosmos-sdk/types"
v044 "github.com/cosmos/cosmos-sdk/x/params/legacy/v044"
)

// Migrator is a struct for handling in-place store migrations.
type Migrator struct {
keeper Keeper
}

// NewMigrator returns a new Migrator.
func NewMigrator(keeper Keeper) Migrator {
return Migrator{keeper: keeper}
}

// Migrate1to2 migrates from version 1 to 2.
func (m Migrator) Migrate1to2(ctx sdk.Context) error {
subspace, _ := m.keeper.GetSubspace(baseapp.Paramspace)
return v044.MigrateStore(ctx, m.keeper.key, subspace)
}
20 changes: 20 additions & 0 deletions x/params/legacy/v044/store.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package v043
tac0turtle marked this conversation as resolved.
Show resolved Hide resolved

amaury1093 marked this conversation as resolved.
Show resolved Hide resolved
import (
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"

"github.com/cosmos/cosmos-sdk/baseapp"
sdk "github.com/cosmos/cosmos-sdk/types"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
)

func migrateParamsStore(ctx sdk.Context, paramstore paramtypes.Subspace) {
paramstore.WithKeyTable(paramtypes.ConsensusParamsKeyTable())
tac0turtle marked this conversation as resolved.
Show resolved Hide resolved
paramstore.Set(ctx, baseapp.ParamStoreKeyVersionParams, tmproto.VersionParams{})
}

func MigrateStore(ctx sdk.Context, storeKey sdk.StoreKey, paramstore paramtypes.Subspace) error {
tac0turtle marked this conversation as resolved.
Show resolved Hide resolved
migrateParamsStore(ctx, paramstore)
return nil

}
4 changes: 4 additions & 0 deletions x/params/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ func (am AppModule) LegacyQuerierHandler(legacyQuerierCdc *codec.LegacyAmino) sd
// module-specific gRPC queries.
func (am AppModule) RegisterServices(cfg module.Configurator) {
proposal.RegisterQueryServer(cfg.QueryServer(), am.keeper)

m := keeper.NewMigrator(am.keeper)
cfg.RegisterMigration(types.ModuleName, 1, m.Migrate1to2)

tac0turtle marked this conversation as resolved.
Show resolved Hide resolved
}

// ProposalContents returns all the params content functions used to
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
package keeper
package types

import (
abci "github.com/tendermint/tendermint/abci/types"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/x/params/types"
)

// ConsensusParamsKeyTable returns an x/params module keyTable to be used in
// the BaseApp's ParamStore. The KeyTable registers the types along with the
// standard validation functions. Applications can choose to adopt this KeyTable
// or provider their own when the existing validation functions do not suite their
// needs.
func ConsensusParamsKeyTable() types.KeyTable {
return types.NewKeyTable(
types.NewParamSetPair(
func ConsensusParamsKeyTable() KeyTable {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add an API breaking changelog entry for this guy?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, on it

return NewKeyTable(
NewParamSetPair(
baseapp.ParamStoreKeyBlockParams, abci.BlockParams{}, baseapp.ValidateBlockParams,
),
types.NewParamSetPair(
NewParamSetPair(
baseapp.ParamStoreKeyEvidenceParams, tmproto.EvidenceParams{}, baseapp.ValidateEvidenceParams,
),
types.NewParamSetPair(
NewParamSetPair(
baseapp.ParamStoreKeyValidatorParams, tmproto.ValidatorParams{}, baseapp.ValidateValidatorParams,
),
NewParamSetPair(
baseapp.ParamStoreKeyVersionParams, tmproto.VersionParams{}, baseapp.ValidateVersionParams,
),
)
}