Sim refactor 3: move weighted operations to modules (#4869)
* move GenesisState generators to modules * minor change on slashing genState generator * move simulation params back to modules (#4839) move simulation params back to modules (#4839) * cleanup params * various fixes * move store decoders to modules * fix * module pattern * split generators for param change * param changes * revert util pkg * banksim * compile * update Decoders params * fix * address @colin-axner comments * move weighted operations to modules * cleanup * cleanup * Update cmd_test.go * simulation manager * mino fixes * cleanup * add GenerateGenesisState to simulation manager * Apply suggestions from code review Co-Authored-By: frog power 4000 <rigel.rozanski@gmail.com> * address @rigelrozanski comments * changelog * Apply suggestions from code review Co-Authored-By: colin axner <colinaxner@berkeley.edu> * restructure modules simulation pkgs * remove cycle deps * rename funcs and add missing params * modularize simulator param changes * build * fix params keys * make format * various fixes * fix tests * minor updates to sim_test * cleanup * more cleanup * modularize genesis generators * minor cleanup * remove cdc from generators * remove cdc * add get or generate * fix non-determinism in simulation * changelog and x/simulation godoc * cleanup operations * update operations to use baseapp * updates and cleanup operations * update operations * restructure sim ops params * rename sim /operations/msg.go to /operations.go * move GenTx to a helper pkg to avoid circle deps * rm msg.ValidateBasic * changelog * random fees; delete auth's DeductFees sim operation * add chain-id for sig verification * Update x/simulation/account.go Co-Authored-By: colin axner <colinaxner@berkeley.edu> * fix bank, gov and distr errors * fix staking and slashing errors; increase prob for send enabled * increase gas x10 * make format * fix some distr and staking edge cases * fix all edge cases * golang ci * rename acc vars; default no fees to 0stake * cleanup; check for exchange rate and skip invalid ops * fixes * check for max entries * add pubkey to genaccounts * fix gov bug * update staking sim ops * fix small redelegation error * fix small self delegation on unjail * rm inf loop on random val/accs * copy array * add ok boolean to RandomValidator return values * format * build * add WeightedOperations to AppModuleSimulation * define each module proposals content as part of the module pattern * Update x/bank/simulation/operations.go Co-Authored-By: colin axner <colinaxner@berkeley.edu> * Update simapp/helpers/test_helpers.go Co-Authored-By: colin axner <colinaxner@berkeley.edu> * address @colin-axner comments * add genaccount pubkey validation * fix test * update operations and move RandomFees to x/simulation * update gov ops * address @alexanderbez comments * avoid modifications to config * reorder params * modularized sim operations working * changelog * Update types/module/simulation.go Co-Authored-By: frog power 4000 <rigel.rozanski@gmail.com> * Update x/simulation/params.go Co-Authored-By: frog power 4000 <rigel.rozanski@gmail.com> * Update x/simulation/params.go Co-Authored-By: frog power 4000 <rigel.rozanski@gmail.com> * update /types/module * Update x/distribution/simulation/genesis.go Co-Authored-By: Alexander Bezobchuk <alexanderbez@users.noreply.github.com> * remove named return values * ensure all operations are simulated * golangci * add nolint * disable whitespace and funlen linter * disable godox * add TODO on unjail * update ops weights * remove dup * update godoc * remove unused func * build fixes * move weights to the same file * scopelint * changelog * address @AdityaSripal comments * address @alexanderbez comments
This commit is contained in:
co-authored by
frog power 4000
colin axner
Alexander Bezobchuk
parent
12ff486a57
commit
722a633f54
+43
-13
@@ -2,6 +2,7 @@ package module
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"math/rand"
|
||||
"time"
|
||||
|
||||
@@ -13,14 +14,20 @@ import (
|
||||
// AppModuleSimulation defines the standard functions that every module should expose
|
||||
// for the SDK blockchain simulator
|
||||
type AppModuleSimulation interface {
|
||||
// register a func to decode the each module's defined types from their corresponding store key
|
||||
RegisterStoreDecoder(sdk.StoreDecoderRegistry)
|
||||
|
||||
// randomized genesis states
|
||||
GenerateGenesisState(input *SimulationState)
|
||||
|
||||
// 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)
|
||||
|
||||
// simulation operations (i.e msgs) with their respective weight
|
||||
WeightedOperations(simState SimulationState) []simulation.WeightedOperation
|
||||
}
|
||||
|
||||
// SimulationManager defines a simulation manager that provides the high level utility
|
||||
@@ -40,6 +47,17 @@ func NewSimulationManager(modules ...AppModuleSimulation) *SimulationManager {
|
||||
}
|
||||
}
|
||||
|
||||
// GetProposalContents returns each module's proposal content generator function
|
||||
// with their default operation weight and key.
|
||||
func (sm *SimulationManager) GetProposalContents(simState SimulationState) []simulation.WeightedProposalContent {
|
||||
var wContents []simulation.WeightedProposalContent
|
||||
for _, module := range sm.Modules {
|
||||
wContents = append(wContents, module.ProposalContents(simState)...)
|
||||
}
|
||||
|
||||
return wContents
|
||||
}
|
||||
|
||||
// RegisterStoreDecoders registers each of the modules' store decoders into a map
|
||||
func (sm *SimulationManager) RegisterStoreDecoders() {
|
||||
for _, module := range sm.Modules {
|
||||
@@ -49,9 +67,9 @@ func (sm *SimulationManager) RegisterStoreDecoders() {
|
||||
|
||||
// GenerateGenesisStates generates a randomized GenesisState for each of the
|
||||
// registered modules
|
||||
func (sm *SimulationManager) GenerateGenesisStates(input *SimulationState) {
|
||||
func (sm *SimulationManager) GenerateGenesisStates(simState *SimulationState) {
|
||||
for _, module := range sm.Modules {
|
||||
module.GenerateGenesisState(input)
|
||||
module.GenerateGenesisState(simState)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,16 +85,28 @@ func (sm *SimulationManager) GenerateParamChanges(seed int64) (paramChanges []si
|
||||
return
|
||||
}
|
||||
|
||||
// WeightedOperations returns all the modules' weighted operations of an application
|
||||
func (sm *SimulationManager) WeightedOperations(simState SimulationState) []simulation.WeightedOperation {
|
||||
var wOps []simulation.WeightedOperation
|
||||
for _, module := range sm.Modules {
|
||||
wOps = append(wOps, module.WeightedOperations(simState)...)
|
||||
}
|
||||
|
||||
return wOps
|
||||
}
|
||||
|
||||
// SimulationState is the input parameters used on each of the module's randomized
|
||||
// GenesisState generator function
|
||||
type SimulationState struct {
|
||||
AppParams simulation.AppParams
|
||||
Cdc *codec.Codec // application codec
|
||||
Rand *rand.Rand // random number
|
||||
GenState map[string]json.RawMessage // genesis state
|
||||
Accounts []simulation.Account // simulation accounts
|
||||
InitialStake int64 // initial coins per account
|
||||
NumBonded int64 // number of initially bonded acconts
|
||||
GenTimestamp time.Time // genesis timestamp
|
||||
UnbondTime time.Duration // staking unbond time stored to use it as the slashing maximum evidence duration
|
||||
Cdc *codec.Codec // application codec
|
||||
Rand *rand.Rand // random number
|
||||
GenState map[string]json.RawMessage // genesis state
|
||||
Accounts []simulation.Account // simulation accounts
|
||||
InitialStake int64 // initial coins per account
|
||||
NumBonded int64 // number of initially bonded accounts
|
||||
GenTimestamp time.Time // genesis timestamp
|
||||
UnbondTime time.Duration // staking unbond time stored to use it as the slashing maximum evidence duration
|
||||
ParamChanges []simulation.ParamChange // simulated parameter changes from modules
|
||||
Contents []simulation.WeightedProposalContent // proposal content generator functions with their default weight and app sim key
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user