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

Sim refactor 3: move weighted operations to modules #4869

Merged
merged 157 commits into from
Dec 5, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
157 commits
Select commit Hold shift + click to select a range
771e305
move GenesisState generators to modules
fedekunze Jul 30, 2019
77d8bd9
minor change on slashing genState generator
fedekunze Aug 2, 2019
52c18e0
move simulation params back to modules (#4839)
fedekunze Aug 5, 2019
bea474f
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk into fe…
fedekunze Aug 5, 2019
237b65a
cleanup params
fedekunze Aug 5, 2019
8bb9880
various fixes
fedekunze Aug 5, 2019
84fa364
move store decoders to modules
fedekunze Jul 30, 2019
687125a
fix
fedekunze Aug 5, 2019
eeb0469
module pattern
fedekunze Aug 5, 2019
5fa13a3
split generators for param change
fedekunze Aug 6, 2019
5efe2bd
param changes
fedekunze Aug 6, 2019
3e15e2a
revert util pkg
fedekunze Aug 6, 2019
521c4dd
banksim
fedekunze Aug 6, 2019
5c41dd2
compile
fedekunze Aug 7, 2019
865a5e4
update Decoders params
fedekunze Aug 7, 2019
45a0e3c
fix
fedekunze Aug 7, 2019
da6de9f
address @colin-axner comments
fedekunze Aug 8, 2019
b59f37c
merge master
fedekunze Aug 8, 2019
f25f970
move weighted operations to modules
fedekunze Jul 30, 2019
66d459a
cleanup
fedekunze Aug 8, 2019
867ba5a
merge master
fedekunze Aug 8, 2019
4f59730
cleanup
fedekunze Aug 8, 2019
bd71a17
Update cmd_test.go
fedekunze Aug 8, 2019
3628d90
merge master
fedekunze Aug 9, 2019
564b484
Merge branch 'fedekunze/move-sim-decoders' of https://github.com/cosm…
fedekunze Aug 9, 2019
fc1e72a
simulation manager
fedekunze Aug 9, 2019
cca3a19
mino fixes
fedekunze Aug 9, 2019
c48a035
cleanup
fedekunze Aug 9, 2019
8c02035
merge sim refactor part 1
fedekunze Aug 9, 2019
5fe9b91
add GenerateGenesisState to simulation manager
fedekunze Aug 9, 2019
225bea3
Apply suggestions from code review
fedekunze Aug 9, 2019
9f3525b
address @rigelrozanski comments
fedekunze Aug 9, 2019
c13ecb6
changelog
fedekunze Aug 9, 2019
4959068
Apply suggestions from code review
fedekunze Aug 10, 2019
4a4db84
update tests
fedekunze Aug 12, 2019
0338964
Merge branch 'fedekunze/move-sim-decoders' of https://github.com/cosm…
fedekunze Aug 12, 2019
84555d9
Merge branch 'fedekunze/move-sim-decoders' of https://github.com/cosm…
fedekunze Aug 12, 2019
258e3e6
restructure modules simulation pkgs
fedekunze Aug 12, 2019
785ac1d
merge sim decoders PR
fedekunze Aug 12, 2019
c627c68
remove cycle deps
fedekunze Aug 12, 2019
427b235
rename funcs and add missing params
fedekunze Aug 12, 2019
7793e11
modularize simulator param changes
fedekunze Aug 13, 2019
d81ba90
build
fedekunze Aug 13, 2019
3899350
fix params keys
fedekunze Aug 13, 2019
c0cd833
make format
fedekunze Aug 13, 2019
e574743
merge master
fedekunze Aug 13, 2019
694e699
merge master
fedekunze Aug 14, 2019
b3ad025
various fixes
fedekunze Aug 14, 2019
538e6e1
fix tests
fedekunze Aug 14, 2019
2ac27a2
minor updates to sim_test
fedekunze Aug 14, 2019
702a257
merge master
fedekunze Aug 16, 2019
d6c669b
cleanup
fedekunze Aug 16, 2019
85ced57
more cleanup
fedekunze Aug 16, 2019
ea76486
modularize genesis generators
fedekunze Aug 16, 2019
9db1881
minor cleanup
fedekunze Aug 16, 2019
cb3f361
remove cdc from generators
fedekunze Aug 20, 2019
d1b96f0
remove cdc
fedekunze Aug 20, 2019
329d32b
merge master
fedekunze Aug 20, 2019
887f2e7
add get or generate
fedekunze Aug 20, 2019
b51949c
fix non-determinism in simulation
fedekunze Aug 20, 2019
ee7c66d
changelog and x/simulation godoc
fedekunze Aug 20, 2019
6bd9554
changes from master
fedekunze Aug 20, 2019
86a6819
merge simulation part 2
fedekunze Aug 20, 2019
4928867
cleanup operations
fedekunze Aug 20, 2019
f22313a
update operations to use baseapp
fedekunze Aug 22, 2019
8f1240c
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk into fe…
fedekunze Aug 26, 2019
5a31d65
updates and cleanup operations
fedekunze Aug 26, 2019
89cf7b9
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk into fe…
fedekunze Aug 27, 2019
5f606ea
update operations
fedekunze Aug 27, 2019
d450ebb
restructure sim ops params
fedekunze Aug 27, 2019
abb288f
merge master
fedekunze Aug 27, 2019
51bf12b
merge master
fedekunze Aug 28, 2019
fe3f6f3
rename sim /operations/msg.go to /operations.go
fedekunze Aug 28, 2019
f3a398b
move GenTx to a helper pkg to avoid circle deps
fedekunze Aug 28, 2019
666a301
rm msg.ValidateBasic
fedekunze Aug 28, 2019
1bb0adc
changelog
fedekunze Aug 28, 2019
b300de0
random fees; delete auth's DeductFees sim operation
fedekunze Aug 29, 2019
bcf6796
add chain-id for sig verification
fedekunze Aug 29, 2019
bb47279
Update x/simulation/account.go
fedekunze Aug 29, 2019
b52a122
fix bank, gov and distr errors
fedekunze Aug 29, 2019
08af7df
Merge branch 'fedekunze/4935-sim-ops-baseapp' of https://github.com/c…
fedekunze Aug 29, 2019
a0a4105
fix staking and slashing errors; increase prob for send enabled
fedekunze Aug 29, 2019
0d33e53
increase gas x10
fedekunze Aug 29, 2019
d2d8e06
make format
fedekunze Aug 29, 2019
882b529
fix some distr and staking edge cases
fedekunze Aug 29, 2019
86798bd
fix all edge cases
fedekunze Aug 30, 2019
8a5a8f7
golang ci
fedekunze Aug 30, 2019
d2433c8
rename acc vars; default no fees to 0stake
fedekunze Aug 30, 2019
0172569
cleanup; check for exchange rate and skip invalid ops
fedekunze Aug 30, 2019
2a2c369
fixes
fedekunze Aug 30, 2019
50f6959
check for max entries
fedekunze Aug 30, 2019
309348a
add pubkey to genaccounts
fedekunze Aug 30, 2019
4e2d3b3
fix gov bug
fedekunze Sep 2, 2019
e662201
update staking sim ops
fedekunze Sep 2, 2019
f1c3e12
fix small redelegation error
fedekunze Sep 2, 2019
3298d5d
fix small self delegation on unjail
fedekunze Sep 2, 2019
8501356
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk into fe…
fedekunze Sep 2, 2019
e615ee1
rm inf loop on random val/accs
fedekunze Sep 2, 2019
9e81756
copy array
fedekunze Sep 2, 2019
490bc77
add ok boolean to RandomValidator return values
fedekunze Sep 2, 2019
2139e75
format
fedekunze Sep 2, 2019
94dcc8c
merge #4946
fedekunze Sep 3, 2019
e64f774
build
fedekunze Sep 3, 2019
0b10ad0
add WeightedOperations to AppModuleSimulation
fedekunze Sep 3, 2019
370a664
define each module proposals content as part of the module pattern
fedekunze Sep 4, 2019
7da6f34
Update x/bank/simulation/operations.go
fedekunze Sep 4, 2019
bd7ed37
Update simapp/helpers/test_helpers.go
fedekunze Sep 4, 2019
59620ed
address @colin-axner comments
fedekunze Sep 4, 2019
b2b4a63
add genaccount pubkey validation
fedekunze Sep 4, 2019
c739839
fix test
fedekunze Sep 4, 2019
8d5a90e
update operations and move RandomFees to x/simulation
fedekunze Sep 5, 2019
52875e5
update gov ops
fedekunze Sep 5, 2019
ae94071
merge master
fedekunze Sep 5, 2019
c49543f
address @alexanderbez comments
fedekunze Sep 6, 2019
86503a9
avoid modifications to config
fedekunze Sep 6, 2019
496fa15
reorder params
fedekunze Sep 6, 2019
0b9b1f4
modularized sim operations working
fedekunze Sep 9, 2019
7aad9cb
merge master
fedekunze Sep 9, 2019
f00fbab
merge sims baseapp PR
fedekunze Sep 9, 2019
337a25c
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk into fe…
fedekunze Sep 9, 2019
efcab1d
changelog
fedekunze Sep 9, 2019
70e8bfa
Merge branch 'fedekunze/4935-sim-ops-baseapp' of https://github.com/c…
fedekunze Sep 9, 2019
7543f45
Update types/module/simulation.go
fedekunze Sep 11, 2019
01da23d
Update x/simulation/params.go
fedekunze Sep 11, 2019
cc719ba
Update x/simulation/params.go
fedekunze Sep 11, 2019
ce53f80
update /types/module
fedekunze Sep 11, 2019
d4df4bf
Update x/distribution/simulation/genesis.go
fedekunze Sep 11, 2019
4f9961a
merge master
fedekunze Sep 24, 2019
8396254
Merge branch 'fedekunze/4935-sim-ops-baseapp' of https://github.com/c…
fedekunze Sep 24, 2019
a188a77
remove named return values
fedekunze Sep 24, 2019
ea3594b
ensure all operations are simulated
fedekunze Sep 25, 2019
f39fc77
Merge branch 'master' into fedekunze/4935-sim-ops-baseapp
fedekunze Sep 25, 2019
c79bc9a
golangci
fedekunze Sep 25, 2019
5491db8
Merge branch 'fedekunze/4935-sim-ops-baseapp' of https://github.com/c…
fedekunze Sep 25, 2019
c9faeeb
add nolint
fedekunze Sep 25, 2019
b310b12
disable whitespace and funlen linter
fedekunze Sep 25, 2019
446179d
disable godox
fedekunze Sep 25, 2019
42eebc3
add TODO on unjail
fedekunze Sep 25, 2019
272e08a
update ops weights
fedekunze Sep 25, 2019
5a3712d
address @alexanderbez comments
fedekunze Sep 30, 2019
c45382b
remove dup
fedekunze Sep 30, 2019
efd2edb
update godoc
fedekunze Sep 30, 2019
daa8206
Merge branch 'master' into fedekunze/4935-sim-ops-baseapp
fedekunze Sep 30, 2019
55f4eb2
merge sim baseapp branch
fedekunze Sep 30, 2019
e34af9d
remove unused func
fedekunze Oct 1, 2019
3b9b870
merge master
fedekunze Nov 22, 2019
c16e512
build fixes
fedekunze Nov 22, 2019
a933a05
move weights to the same file
fedekunze Nov 26, 2019
58357f2
scopelint
fedekunze Nov 26, 2019
9e84b66
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk into fe…
fedekunze Dec 2, 2019
bfb0a94
changelog
fedekunze Dec 2, 2019
15c015b
address @AdityaSripal comments
fedekunze Dec 3, 2019
a9696c0
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk into fe…
fedekunze Dec 3, 2019
6ba787d
Merge branch 'master' into fedekunze/move-sim-operations
alexanderbez Dec 4, 2019
9ba2ec5
Merge branch 'master' into fedekunze/move-sim-operations
fedekunze Dec 4, 2019
cb524e0
address @alexanderbez comments
fedekunze Dec 4, 2019
40a38fa
Merge branch 'fedekunze/move-sim-operations' of https://github.com/co…
fedekunze Dec 4, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
simulation manager
  • Loading branch information
fedekunze committed Aug 9, 2019
commit fc1e72a310fd24c1f828414e7ed3c27c5610bd71
7 changes: 6 additions & 1 deletion simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ type SimApp struct {

// the module manager
mm *module.Manager

// simulation manager
sm *module.SimulationManager
}

// NewSimApp returns a reference to an initialized SimApp.
Expand Down Expand Up @@ -199,7 +202,9 @@ func NewSimApp(

app.mm.RegisterInvariants(&app.crisisKeeper)
app.mm.RegisterRoutes(app.Router(), app.QueryRouter())
app.mm.RegisterStoreDecoders()

app.sm = module.NewSimulationManager(app.mm.Modules)
app.sm.RegisterStoreDecoders()

// initialize stores
app.MountKVStores(keys)
Expand Down
102 changes: 65 additions & 37 deletions types/module/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Package module contains application module patterns and associated "manager" fun
The module pattern has been broken down by:
- independent module functionality (AppModuleBasic)
- inter-dependent module genesis functionality (AppModuleGenesis)
- inter-dependent module simulation functionality (AppModuleSimulation)
- inter-dependent module full functionality (AppModule)

inter-dependent module functionality is module functionality which somehow
Expand Down Expand Up @@ -41,6 +42,7 @@ import (
)

//__________________________________________________________________________________________

// AppModuleBasic is the standard form for basic non-dependant elements of an application module.
type AppModuleBasic interface {
Name() string
Expand All @@ -56,9 +58,10 @@ type AppModuleBasic interface {
GetQueryCmd(*codec.Codec) *cobra.Command
}

// collections of AppModuleBasic
// BasicManager is a collection of AppModuleBasic
type BasicManager map[string]AppModuleBasic

// NewBasicManager creates a new BasicManager object
func NewBasicManager(modules ...AppModuleBasic) BasicManager {
moduleMap := make(map[string]AppModuleBasic)
for _, module := range modules {
Expand All @@ -67,14 +70,14 @@ func NewBasicManager(modules ...AppModuleBasic) BasicManager {
return moduleMap
}

// RegisterCodecs registers all module codecs
// RegisterCodec registers all module codecs
func (bm BasicManager) RegisterCodec(cdc *codec.Codec) {
for _, b := range bm {
b.RegisterCodec(cdc)
}
}

// Provided default genesis information for all modules
// DefaultGenesis provided default genesis information for all modules
func (bm BasicManager) DefaultGenesis() map[string]json.RawMessage {
genesis := make(map[string]json.RawMessage)
for _, b := range bm {
Expand All @@ -83,7 +86,7 @@ func (bm BasicManager) DefaultGenesis() map[string]json.RawMessage {
return genesis
}

// Provided default genesis information for all modules
// ValidateGenesis provided default genesis information for all modules
func (bm BasicManager) ValidateGenesis(genesis map[string]json.RawMessage) error {
for _, b := range bm {
if err := b.ValidateGenesis(genesis[b.Name()]); err != nil {
Expand All @@ -93,14 +96,14 @@ func (bm BasicManager) ValidateGenesis(genesis map[string]json.RawMessage) error
return nil
}

// RegisterRestRoutes registers all module rest routes
// RegisterRESTRoutes registers all module rest routes
func (bm BasicManager) RegisterRESTRoutes(ctx context.CLIContext, rtr *mux.Router) {
for _, b := range bm {
b.RegisterRESTRoutes(ctx, rtr)
}
}

// add all tx commands to the rootTxCmd
// AddTxCommands adds all tx commands to the rootTxCmd
func (bm BasicManager) AddTxCommands(rootTxCmd *cobra.Command, cdc *codec.Codec) {
for _, b := range bm {
if cmd := b.GetTxCmd(cdc); cmd != nil {
Expand All @@ -109,7 +112,7 @@ func (bm BasicManager) AddTxCommands(rootTxCmd *cobra.Command, cdc *codec.Codec)
}
}

// add all query commands to the rootQueryCmd
// AddQueryCommands adds all query commands to the rootQueryCmd
func (bm BasicManager) AddQueryCommands(rootQueryCmd *cobra.Command, cdc *codec.Codec) {
for _, b := range bm {
if cmd := b.GetQueryCmd(cdc); cmd != nil {
Expand All @@ -119,20 +122,28 @@ func (bm BasicManager) AddQueryCommands(rootQueryCmd *cobra.Command, cdc *codec.
}

//_________________________________________________________

// AppModuleGenesis is the standard form for an application module genesis functions
type AppModuleGenesis interface {
AppModuleBasic
InitGenesis(sdk.Context, json.RawMessage) []abci.ValidatorUpdate
ExportGenesis(sdk.Context) json.RawMessage
}

// 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)
}

// AppModule is the standard form for an application module
type AppModule interface {
AppModuleGenesis
AppModuleSimulation

// registers
RegisterInvariants(sdk.InvariantRegistry)
RegisterStoreDecoder(sdk.StoreDecoderRegistry)

// routes
Route() string
Expand All @@ -146,7 +157,8 @@ type AppModule interface {
}

//___________________________
// app module

// GenesisOnlyAppModule is an AppModule that only has import/export functionality
type GenesisOnlyAppModule struct {
AppModuleGenesis
}
Expand All @@ -158,49 +170,48 @@ func NewGenesisOnlyAppModule(amg AppModuleGenesis) AppModule {
}
}

// register invariants
// RegisterInvariants register no invariants
func (GenesisOnlyAppModule) RegisterInvariants(_ sdk.InvariantRegistry) {}

// RegisterStoreDecoder empty store decoder registry
func (GenesisOnlyAppModule) RegisterStoreDecoder(_ sdk.StoreDecoderRegistry) {}

// module message route ngame
// Route empty module message route
func (GenesisOnlyAppModule) Route() string { return "" }

// module handler
// NewHandler empty module handler
func (GenesisOnlyAppModule) NewHandler() sdk.Handler { return nil }

// module querier route ngame
// QuerierRoute empty module querier route
func (GenesisOnlyAppModule) QuerierRoute() string { return "" }

// module querier
// NewQuerierHandler empty module querier
func (gam GenesisOnlyAppModule) NewQuerierHandler() sdk.Querier { return nil }

// module begin-block
// BeginBlock empty module begin-block
func (gam GenesisOnlyAppModule) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) {}

// module end-block
// EndBlock empty module end-block
func (GenesisOnlyAppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate {
return []abci.ValidatorUpdate{}
}

//____________________________________________________________________________
// module manager provides the high level utility for managing and executing

// Manager defines a module manager that provides the high level utility for managing and executing
// operations for a group of modules
type Manager struct {
Modules map[string]AppModule
StoreDecoders sdk.StoreDecoderRegistry
OrderInitGenesis []string
OrderExportGenesis []string
OrderBeginBlockers []string
OrderEndBlockers []string
}

// NewModuleManager creates a new Manager object
// NewManager creates a new Manager object
func NewManager(modules ...AppModule) *Manager {

moduleMap := make(map[string]AppModule)
decoders := make(sdk.StoreDecoderRegistry)
var modulesStr []string
for _, module := range modules {
moduleMap[module.Name()] = module
Expand All @@ -209,49 +220,41 @@ func NewManager(modules ...AppModule) *Manager {

return &Manager{
Modules: moduleMap,
StoreDecoders: decoders,
OrderInitGenesis: modulesStr,
OrderExportGenesis: modulesStr,
OrderBeginBlockers: modulesStr,
OrderEndBlockers: modulesStr,
}
}

// set the order of init genesis calls
// SetOrderInitGenesis sets the order of init genesis calls
func (m *Manager) SetOrderInitGenesis(moduleNames ...string) {
m.OrderInitGenesis = moduleNames
}

// set the order of export genesis calls
// SetOrderExportGenesis sets the order of export genesis calls
func (m *Manager) SetOrderExportGenesis(moduleNames ...string) {
m.OrderExportGenesis = moduleNames
}

// set the order of set begin-blocker calls
// SetOrderBeginBlockers sets the order of set begin-blocker calls
func (m *Manager) SetOrderBeginBlockers(moduleNames ...string) {
m.OrderBeginBlockers = moduleNames
}

// set the order of set end-blocker calls
// SetOrderEndBlockers sets the order of set end-blocker calls
func (m *Manager) SetOrderEndBlockers(moduleNames ...string) {
m.OrderEndBlockers = moduleNames
}

// register all module routes and module querier routes
// RegisterInvariants registers all module routes and module querier routes
func (m *Manager) RegisterInvariants(ir sdk.InvariantRegistry) {
for _, module := range m.Modules {
module.RegisterInvariants(ir)
}
}

// RegisterStoreDecoders registers the each type decoder with the respective key
func (m *Manager) RegisterStoreDecoders() {
for _, module := range m.Modules {
module.RegisterStoreDecoder(m.StoreDecoders)
}
}

// register all module routes and module querier routes
// RegisterRoutes registers all module routes and module querier routes
func (m *Manager) RegisterRoutes(router sdk.Router, queryRouter sdk.QueryRouter) {
for _, module := range m.Modules {
if module.Route() != "" {
Expand All @@ -263,7 +266,7 @@ func (m *Manager) RegisterRoutes(router sdk.Router, queryRouter sdk.QueryRouter)
}
}

// perform init genesis functionality for modules
// InitGenesis performs init genesis functionality for modules
func (m *Manager) InitGenesis(ctx sdk.Context, genesisData map[string]json.RawMessage) abci.ResponseInitChain {
var validatorUpdates []abci.ValidatorUpdate
for _, moduleName := range m.OrderInitGenesis {
Expand All @@ -286,7 +289,7 @@ func (m *Manager) InitGenesis(ctx sdk.Context, genesisData map[string]json.RawMe
}
}

// perform export genesis functionality for modules
// ExportGenesis performs export genesis functionality for modules
func (m *Manager) ExportGenesis(ctx sdk.Context) map[string]json.RawMessage {
genesisData := make(map[string]json.RawMessage)
for _, moduleName := range m.OrderExportGenesis {
Expand Down Expand Up @@ -337,4 +340,29 @@ func (m *Manager) EndBlock(ctx sdk.Context, req abci.RequestEndBlock) abci.Respo
}
}

// DONTCOVER
//____________________________________________________________________________

// SimulationManager defines a simulation manager that provides the high level utility
// for managing and executing simulation functionalities for a group of modules
type SimulationManager struct {
Modules map[string]AppModule
StoreDecoders sdk.StoreDecoderRegistry
}

// NewSimulationManager creates a new SimulationManager object
func NewSimulationManager(moduleMap map[string]AppModule) *SimulationManager {

decoders := make(sdk.StoreDecoderRegistry)

return &SimulationManager{
Modules: moduleMap,
StoreDecoders: decoders,
}
}

// RegisterStoreDecoders registers each of the modules' store decoders into a map
func (sm *SimulationManager) RegisterStoreDecoders() {
for _, module := range sm.Modules {
module.RegisterStoreDecoder(sm.StoreDecoders)
}
}
Loading