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 @@ -421,6 +421,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 @@ -444,6 +451,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
}
3 changes: 3 additions & 0 deletions x/params/keeper/consensus_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,8 @@ func ConsensusParamsKeyTable() types.KeyTable {
types.NewParamSetPair(
baseapp.ParamStoreKeyValidatorParams, tmproto.ValidatorParams{}, baseapp.ValidateValidatorParams,
),
types.NewParamSetPair(
baseapp.ParamStoreKeyVersionParams, tmproto.VersionParams{}, baseapp.ValidateVersionParams,
),
)
}