From 7496aa3d2745b95042d2f3d145a713d7a67819ed Mon Sep 17 00:00:00 2001 From: likhita-809 <78951027+likhita-809@users.noreply.github.com> Date: Wed, 10 Aug 2022 18:04:45 +0530 Subject: [PATCH] feat: Remove `RandomizedParams` from the `AppModuleSimulation` interface (#12846) * remove RandomizedParams from AppModuleSimulation interface * add changelog * add upgrading doc * nit fix Co-authored-by: Marko --- CHANGELOG.md | 1 + UPGRADING.md | 4 ++++ simapp/utils.go | 1 - types/module/simulation.go | 15 --------------- x/auth/module.go | 6 ------ x/authz/module/module.go | 6 ------ x/bank/module.go | 10 ---------- x/capability/module.go | 6 ------ x/distribution/module.go | 10 ---------- x/evidence/module.go | 6 ------ x/feegrant/module/module.go | 6 ------ x/gov/module.go | 8 -------- x/group/module/module.go | 6 ------ x/mint/module.go | 10 ---------- x/nft/module/module.go | 6 ------ x/params/module.go | 6 ------ x/slashing/module.go | 6 ------ x/staking/module.go | 6 ------ 18 files changed, 5 insertions(+), 114 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d6dc151f972e..6b1179bbee5f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -45,6 +45,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Improvements +* [#12846](https://github.com/cosmos/cosmos-sdk/pull/12846) Remove `RandomizedParams` from the `AppModuleSimulation` interface which is no longer needed. * (events) [#12850](https://github.com/cosmos/cosmos-sdk/pull/12850) Add a new `fee_payer` attribute to the `tx` event that is emitted from the `DeductFeeDecorator` AnteHandler decorator. * (ci) [#12854](https://github.com/cosmos/cosmos-sdk/pull/12854) Use ghcr.io to host the proto builder image. Update proto builder image to go 1.19 * (x/bank) [#12706](https://github.com/cosmos/cosmos-sdk/pull/12706) Added the `chain-id` flag to the `AddTxFlagsToCmd` API. There is no longer a need to explicitly register this flag on commands whens `AddTxFlagsToCmd` is already called. diff --git a/UPGRADING.md b/UPGRADING.md index 35d548ce00c5..d171edac70a9 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -4,6 +4,10 @@ This guide provides instructions for upgrading to specific versions of Cosmos SD ## [Unreleased] +### Simulation + +Remove `RandomizedParams` from `AppModuleSimulation` interface. Previously, it used to generate random parameter changes during simulations, however, it does so through ParamChangeProposal which is now legacy. Since all modules were migrated, we can now safely remove this from `AppModuleSimulation` interface. + ### AppModule Interface Remove `Querier`, `Route` and `LegacyQuerier` from the app module interface. This removes and fully deprecates all legacy queriers. All modules no longer support the REST API previously known as the LCD, and the `sdk.Msg#Route` method won't be used anymore. diff --git a/simapp/utils.go b/simapp/utils.go index 4ab543464121..b18ff77dbeb9 100644 --- a/simapp/utils.go +++ b/simapp/utils.go @@ -67,7 +67,6 @@ func SimulationOperations(app App, cdc codec.JSONCodec, config simtypes.Config) } } - simState.ParamChanges = app.SimulationManager().GenerateParamChanges(config.Seed) simState.Contents = app.SimulationManager().GetProposalContents(simState) return app.SimulationManager().WeightedOperations(simState) } diff --git a/types/module/simulation.go b/types/module/simulation.go index 8cba9093452e..28f9b3b1cce8 100644 --- a/types/module/simulation.go +++ b/types/module/simulation.go @@ -21,9 +21,6 @@ type AppModuleSimulation interface { // content functions used to simulate governance proposals ProposalContents(simState SimulationState) []simulation.WeightedProposalContent - // randomized module parameters for param change proposals - RandomizedParams(r *rand.Rand) []simulation.ParamChange - // register a func to decode the each module's defined types from their corresponding store key RegisterStoreDecoder(sdk.StoreDecoderRegistry) @@ -106,18 +103,6 @@ func (sm *SimulationManager) GenerateGenesisStates(simState *SimulationState) { } } -// GenerateParamChanges generates randomized contents for creating params change -// proposal transactions -func (sm *SimulationManager) GenerateParamChanges(seed int64) (paramChanges []simulation.ParamChange) { - r := rand.New(rand.NewSource(seed)) - - for _, module := range sm.Modules { - paramChanges = append(paramChanges, module.RandomizedParams(r)...) - } - - return -} - // WeightedOperations returns all the modules' weighted operations of an application func (sm *SimulationManager) WeightedOperations(simState SimulationState) []simulation.WeightedOperation { wOps := make([]simulation.WeightedOperation, 0, len(sm.Modules)) diff --git a/x/auth/module.go b/x/auth/module.go index 2505e44bbc6a..8f8165a916d7 100644 --- a/x/auth/module.go +++ b/x/auth/module.go @@ -4,7 +4,6 @@ import ( "context" "encoding/json" "fmt" - "math/rand" modulev1 "cosmossdk.io/api/cosmos/auth/module/v1" "cosmossdk.io/core/appmodule" @@ -168,11 +167,6 @@ func (AppModule) ProposalContents(simState module.SimulationState) []simtypes.We return nil } -// RandomizedParams creates randomized auth param changes for the simulator. -func (AppModule) RandomizedParams(r *rand.Rand) []simtypes.ParamChange { - return []simtypes.ParamChange{} -} - // RegisterStoreDecoder registers a decoder for auth module's types func (am AppModule) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) { sdr[types.StoreKey] = simulation.NewDecodeStore(am.accountKeeper) diff --git a/x/authz/module/module.go b/x/authz/module/module.go index bced6e7a891d..9890fed910d2 100644 --- a/x/authz/module/module.go +++ b/x/authz/module/module.go @@ -3,7 +3,6 @@ package authz import ( "context" "encoding/json" - "math/rand" gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/spf13/cobra" @@ -209,11 +208,6 @@ func (am AppModule) ProposalContents(simState module.SimulationState) []simtypes return nil } -// RandomizedParams creates randomized authz param changes for the simulator. -func (AppModule) RandomizedParams(r *rand.Rand) []simtypes.ParamChange { - return nil -} - // RegisterStoreDecoder registers a decoder for authz module's types func (am AppModule) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) { sdr[keeper.StoreKey] = simulation.NewDecodeStore(am.cdc) diff --git a/x/bank/module.go b/x/bank/module.go index 0ca4e015ebb7..ab2167980ae3 100644 --- a/x/bank/module.go +++ b/x/bank/module.go @@ -4,7 +4,6 @@ import ( "context" "encoding/json" "fmt" - "math/rand" "time" modulev1 "cosmossdk.io/api/cosmos/bank/module/v1" @@ -183,15 +182,6 @@ func (AppModule) ProposalContents(_ module.SimulationState) []simtypes.WeightedP return nil } -// RandomizedParams creates randomized distribution param changes for the simulator. - -// TODO: Returns an empty slice which will make parameter changes a no-op during -// simulations. Once all modules are migrated, remove RandomizedParams from -// the simulation interface. -func (AppModule) RandomizedParams(_ *rand.Rand) []simtypes.ParamChange { - return []simtypes.ParamChange{} -} - // RegisterStoreDecoder registers a decoder for supply module's types func (am AppModule) RegisterStoreDecoder(_ sdk.StoreDecoderRegistry) {} diff --git a/x/capability/module.go b/x/capability/module.go index 23ecad8e7cd3..f37be6984a78 100644 --- a/x/capability/module.go +++ b/x/capability/module.go @@ -3,7 +3,6 @@ package capability import ( "encoding/json" "fmt" - "math/rand" "time" "cosmossdk.io/core/appmodule" @@ -159,11 +158,6 @@ func (am AppModule) ProposalContents(simState module.SimulationState) []simtypes return nil } -// RandomizedParams creates randomized capability param changes for the simulator. -func (AppModule) RandomizedParams(r *rand.Rand) []simtypes.ParamChange { - return nil -} - // RegisterStoreDecoder registers a decoder for capability module's types func (am AppModule) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) { sdr[types.StoreKey] = simulation.NewDecodeStore(am.cdc) diff --git a/x/distribution/module.go b/x/distribution/module.go index 068f50fcee9f..fdda3e932b81 100644 --- a/x/distribution/module.go +++ b/x/distribution/module.go @@ -4,7 +4,6 @@ import ( "context" "encoding/json" "fmt" - "math/rand" modulev1 "cosmossdk.io/api/cosmos/distribution/module/v1" "cosmossdk.io/core/appmodule" @@ -184,15 +183,6 @@ func (am AppModule) ProposalContents(simState module.SimulationState) []simtypes return simulation.ProposalContents(am.keeper) } -// RandomizedParams creates randomized distribution param changes for the simulator. - -// TODO: Returns an empty slice which will make parameter changes a no-op during -// simulations. Once all modules are migrated, remove RandomizedParams from -// the simulation interface. -func (AppModule) RandomizedParams(_ *rand.Rand) []simtypes.ParamChange { - return []simtypes.ParamChange{} -} - // RegisterStoreDecoder registers a decoder for distribution module's types func (am AppModule) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) { sdr[types.StoreKey] = simulation.NewDecodeStore(am.cdc) diff --git a/x/evidence/module.go b/x/evidence/module.go index 03c9135a5000..083a29217072 100644 --- a/x/evidence/module.go +++ b/x/evidence/module.go @@ -4,7 +4,6 @@ import ( "context" "encoding/json" "fmt" - "math/rand" "cosmossdk.io/core/appmodule" gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime" @@ -174,11 +173,6 @@ func (am AppModule) ProposalContents(simState module.SimulationState) []simtypes return nil } -// RandomizedParams creates randomized evidence param changes for the simulator. -func (AppModule) RandomizedParams(r *rand.Rand) []simtypes.ParamChange { - return nil -} - // RegisterStoreDecoder registers a decoder for evidence module's types func (am AppModule) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) { sdr[types.StoreKey] = simulation.NewDecodeStore(am.keeper) diff --git a/x/feegrant/module/module.go b/x/feegrant/module/module.go index 402dc449e520..766173e1e9f2 100644 --- a/x/feegrant/module/module.go +++ b/x/feegrant/module/module.go @@ -3,7 +3,6 @@ package module import ( "context" "encoding/json" - "math/rand" "cosmossdk.io/core/appmodule" gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime" @@ -215,11 +214,6 @@ func (AppModule) ProposalContents(simState module.SimulationState) []simtypes.We return nil } -// RandomizedParams creates randomized feegrant param changes for the simulator. -func (AppModule) RandomizedParams(r *rand.Rand) []simtypes.ParamChange { - return nil -} - // RegisterStoreDecoder registers a decoder for feegrant module's types func (am AppModule) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) { sdr[feegrant.StoreKey] = simulation.NewDecodeStore(am.cdc) diff --git a/x/gov/module.go b/x/gov/module.go index 3aa73ccfb0d3..d71c75ffec00 100644 --- a/x/gov/module.go +++ b/x/gov/module.go @@ -6,7 +6,6 @@ import ( "context" "encoding/json" "fmt" - "math/rand" "sort" gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime" @@ -334,13 +333,6 @@ func (AppModule) ProposalContents(simState module.SimulationState) []simtypes.We return simulation.ProposalContents() } -// TODO: Returns an empty slice which will make parameter changes a no-op during -// simulations. Once all modules are migrated, remove RandomizedParams from -// the simulation interface. -func (AppModule) RandomizedParams(_ *rand.Rand) []simtypes.ParamChange { - return []simtypes.ParamChange{} -} - // RegisterStoreDecoder registers a decoder for gov module's types func (am AppModule) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) { sdr[types.StoreKey] = simulation.NewDecodeStore(am.cdc) diff --git a/x/group/module/module.go b/x/group/module/module.go index c0ad9a540cf4..1b0bfb0c6ca0 100644 --- a/x/group/module/module.go +++ b/x/group/module/module.go @@ -4,7 +4,6 @@ import ( "context" "encoding/json" "fmt" - "math/rand" "cosmossdk.io/core/appmodule" gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime" @@ -206,11 +205,6 @@ func (am AppModule) ProposalContents(simState module.SimulationState) []simtypes return nil } -// RandomizedParams creates randomized group param changes for the simulator. -func (AppModule) RandomizedParams(r *rand.Rand) []simtypes.ParamChange { - return nil -} - // RegisterStoreDecoder registers a decoder for group module's types func (am AppModule) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) { sdr[group.StoreKey] = simulation.NewDecodeStore(am.cdc) diff --git a/x/mint/module.go b/x/mint/module.go index 6ee35876e854..ef013161427a 100644 --- a/x/mint/module.go +++ b/x/mint/module.go @@ -4,7 +4,6 @@ import ( "context" "encoding/json" "fmt" - "math/rand" modulev1 "cosmossdk.io/api/cosmos/mint/module/v1" "cosmossdk.io/core/appmodule" @@ -187,15 +186,6 @@ func (AppModule) ProposalContents(simState module.SimulationState) []simtypes.We return nil } -// RandomizedParams creates randomized mint param changes for the simulator. -// -// TODO: Returns an empty slice which will make parameter changes a no-op during -// simulations. Once all modules are migrated, remove RandomizedParams from -// the simulation interface. -func (AppModule) RandomizedParams(r *rand.Rand) []simtypes.ParamChange { - return []simtypes.ParamChange{} -} - // RegisterStoreDecoder registers a decoder for mint module's types. func (am AppModule) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) { sdr[types.StoreKey] = simulation.NewDecodeStore(am.cdc) diff --git a/x/nft/module/module.go b/x/nft/module/module.go index b8054addf0d8..c03b535ed227 100644 --- a/x/nft/module/module.go +++ b/x/nft/module/module.go @@ -3,7 +3,6 @@ package module import ( "context" "encoding/json" - "math/rand" gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/spf13/cobra" @@ -159,11 +158,6 @@ func (am AppModule) ProposalContents(simState module.SimulationState) []simtypes return nil } -// RandomizedParams creates randomized nft param changes for the simulator. -func (AppModule) RandomizedParams(r *rand.Rand) []simtypes.ParamChange { - return nil -} - // RegisterStoreDecoder registers a decoder for nft module's types func (am AppModule) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) { sdr[keeper.StoreKey] = simulation.NewDecodeStore(am.cdc) diff --git a/x/params/module.go b/x/params/module.go index 82ccd75c48a1..fb32960ab404 100644 --- a/x/params/module.go +++ b/x/params/module.go @@ -3,7 +3,6 @@ package params import ( "context" "encoding/json" - "math/rand" govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" @@ -114,11 +113,6 @@ func (am AppModule) ProposalContents(simState module.SimulationState) []simtypes return nil } -// RandomizedParams creates randomized distribution param changes for the simulator. -func (AppModule) RandomizedParams(r *rand.Rand) []simtypes.ParamChange { - return nil -} - // RegisterStoreDecoder doesn't register any type. func (AppModule) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) {} diff --git a/x/slashing/module.go b/x/slashing/module.go index e0e5de62e324..a01a8b37deb6 100644 --- a/x/slashing/module.go +++ b/x/slashing/module.go @@ -4,7 +4,6 @@ import ( "context" "encoding/json" "fmt" - "math/rand" modulev1 "cosmossdk.io/api/cosmos/slashing/module/v1" "cosmossdk.io/core/appmodule" @@ -179,11 +178,6 @@ func (AppModule) ProposalContents(simState module.SimulationState) []simtypes.We return nil } -// RandomizedParams creates randomized slashing param changes for the simulator. -func (AppModule) RandomizedParams(r *rand.Rand) []simtypes.ParamChange { - return []simtypes.ParamChange{} -} - // RegisterStoreDecoder registers a decoder for slashing module's types func (am AppModule) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) { sdr[types.StoreKey] = simulation.NewDecodeStore(am.cdc) diff --git a/x/staking/module.go b/x/staking/module.go index 6a2f74072478..fd77ea806a5e 100644 --- a/x/staking/module.go +++ b/x/staking/module.go @@ -4,7 +4,6 @@ import ( "context" "encoding/json" "fmt" - "math/rand" "sort" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" @@ -288,11 +287,6 @@ func (AppModule) ProposalContents(simState module.SimulationState) []simtypes.We return nil } -// RandomizedParams creates randomized staking param changes for the simulator. -func (AppModule) RandomizedParams(r *rand.Rand) []simtypes.ParamChange { - return []simtypes.ParamChange{} -} - // RegisterStoreDecoder registers a decoder for staking module's types func (am AppModule) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) { sdr[types.StoreKey] = simulation.NewDecodeStore(am.cdc)