mukan-sdk/baseapp/params_legacy.go
Mukan Erkin Törük 20afb5db80
Some checks failed
Build SimApp / build (amd64) (push) Waiting to run
Build SimApp / build (arm64) (push) Waiting to run
CodeQL / Analyze (push) Waiting to run
Build & Push / build (push) Waiting to run
Run Gosec / Gosec (push) Waiting to run
Lint / golangci-lint (push) Waiting to run
Checks dependencies and mocks generation / Check go mod tidy (push) Waiting to run
Checks dependencies and mocks generation / Check up to date mocks (push) Waiting to run
System Tests / setup (push) Waiting to run
System Tests / test-system (push) Blocked by required conditions
System Tests / test-system-legacy (push) Blocked by required conditions
Tests / Code Coverage / split-test-files (push) Waiting to run
Tests / Code Coverage / tests (00) (push) Blocked by required conditions
Tests / Code Coverage / tests (01) (push) Blocked by required conditions
Tests / Code Coverage / tests (02) (push) Blocked by required conditions
Tests / Code Coverage / tests (03) (push) Blocked by required conditions
Tests / Code Coverage / test-integration (push) Waiting to run
Tests / Code Coverage / test-e2e (push) Waiting to run
Tests / Code Coverage / repo-analysis (push) Blocked by required conditions
Tests / Code Coverage / test-sim-nondeterminism (push) Waiting to run
Tests / Code Coverage / test-clientv2 (push) Waiting to run
Tests / Code Coverage / test-core (push) Waiting to run
Tests / Code Coverage / test-depinject (push) Waiting to run
Tests / Code Coverage / test-errors (push) Waiting to run
Tests / Code Coverage / test-math (push) Waiting to run
Tests / Code Coverage / test-schema (push) Waiting to run
Tests / Code Coverage / test-collections (push) Waiting to run
Tests / Code Coverage / test-cosmovisor (push) Waiting to run
Tests / Code Coverage / test-confix (push) Waiting to run
Tests / Code Coverage / test-store (push) Waiting to run
Tests / Code Coverage / test-log (push) Waiting to run
Tests / Code Coverage / test-x-tx (push) Waiting to run
Tests / Code Coverage / test-x-nft (push) Waiting to run
Tests / Code Coverage / test-x-circuit (push) Waiting to run
Tests / Code Coverage / test-x-feegrant (push) Waiting to run
Tests / Code Coverage / test-x-evidence (push) Waiting to run
Tests / Code Coverage / test-x-upgrade (push) Waiting to run
Tests / Code Coverage / test-tools-benchmark (push) Waiting to run
Build & Push SDK Proto Builder / build (push) Has been cancelled
initial: sovereign Mukan Network fork
2026-05-11 03:18:24 +03:00

150 lines
3.8 KiB
Go

/*
Deprecated.
Legacy types are defined below to aid in the migration of CometBFT consensus
parameters from use of the now deprecated x/params modules to a new dedicated
x/consensus module.
Application developers should ensure that they implement their upgrade handler
correctly such that app.ConsensusParamsKeeper.Set() is called with the values
returned by GetConsensusParams().
Example:
baseAppLegacySS := app.ParamsKeeper.Subspace(baseapp.Paramspace).WithKeyTable(paramstypes.ConsensusParamsKeyTable())
app.UpgradeKeeper.SetUpgradeHandler(
UpgradeName,
func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
if cp := baseapp.GetConsensusParams(ctx, baseAppLegacySS); cp != nil {
app.ConsensusParamsKeeper.Set(ctx, cp)
} else {
ctx.Logger().Info("warning: consensus parameters are undefined; skipping migration", "upgrade", UpgradeName)
}
return app.ModuleManager.RunMigrations(ctx, app.Configurator(), fromVM)
},
)
Developers can also bypass the use of the legacy Params subspace and set the
values to app.ConsensusParamsKeeper.Set() explicitly.
Note, for new chains this is not necessary as CometBFT's consensus parameters
will automatically be set for you in InitChain.
*/
package baseapp
import (
"errors"
"fmt"
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)
const Paramspace = "baseapp"
var (
ParamStoreKeyBlockParams = []byte("BlockParams")
ParamStoreKeyEvidenceParams = []byte("EvidenceParams")
ParamStoreKeyValidatorParams = []byte("ValidatorParams")
)
type LegacyParamStore interface {
Get(ctx sdk.Context, key []byte, ptr any)
Has(ctx sdk.Context, key []byte) bool
}
func ValidateBlockParams(i any) error {
v, ok := i.(cmtproto.BlockParams)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
if v.MaxBytes <= 0 {
return fmt.Errorf("block maximum bytes must be positive: %d", v.MaxBytes)
}
if v.MaxGas < -1 {
return fmt.Errorf("block maximum gas must be greater than or equal to -1: %d", v.MaxGas)
}
return nil
}
func ValidateEvidenceParams(i any) error {
v, ok := i.(cmtproto.EvidenceParams)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
if v.MaxAgeNumBlocks <= 0 {
return fmt.Errorf("evidence maximum age in blocks must be positive: %d", v.MaxAgeNumBlocks)
}
if v.MaxAgeDuration <= 0 {
return fmt.Errorf("evidence maximum age time duration must be positive: %v", v.MaxAgeDuration)
}
if v.MaxBytes < 0 {
return fmt.Errorf("maximum evidence bytes must be non-negative: %v", v.MaxBytes)
}
return nil
}
func ValidateValidatorParams(i any) error {
v, ok := i.(cmtproto.ValidatorParams)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
if len(v.PubKeyTypes) == 0 {
return errors.New("validator allowed pubkey types must not be empty")
}
return nil
}
func GetConsensusParams(ctx sdk.Context, paramStore LegacyParamStore) *cmtproto.ConsensusParams {
if paramStore == nil {
return nil
}
cp := new(cmtproto.ConsensusParams)
if paramStore.Has(ctx, ParamStoreKeyBlockParams) {
var bp cmtproto.BlockParams
paramStore.Get(ctx, ParamStoreKeyBlockParams, &bp)
cp.Block = &bp
}
if paramStore.Has(ctx, ParamStoreKeyEvidenceParams) {
var ep cmtproto.EvidenceParams
paramStore.Get(ctx, ParamStoreKeyEvidenceParams, &ep)
cp.Evidence = &ep
}
if paramStore.Has(ctx, ParamStoreKeyValidatorParams) {
var vp cmtproto.ValidatorParams
paramStore.Get(ctx, ParamStoreKeyValidatorParams, &vp)
cp.Validator = &vp
}
return cp
}
func MigrateParams(ctx sdk.Context, lps LegacyParamStore, ps ParamStore) error {
if cp := GetConsensusParams(ctx, lps); cp != nil {
if err := ps.Set(ctx, *cp); err != nil {
return err
}
} else {
ctx.Logger().Info("warning: consensus parameters are undefined; skipping migration")
}
return nil
}