Skip to content

Commit

Permalink
feat(sims): Integration with app v2 (#23013)
Browse files Browse the repository at this point in the history
Co-authored-by: Alex | Interchain Labs <[email protected]>
(cherry picked from commit cf721a6)

# Conflicts:
#	CHANGELOG.md
#	runtime/v2/app.go
#	scripts/build/simulations.mk
#	server/v2/appmanager/appmanager.go
#	server/v2/appmanager/stf.go
#	server/v2/stf/stf.go
#	server/v2/streaming/examples/file/file.go
#	simapp/v2/go.mod
#	store/v2/db/db.go
  • Loading branch information
alpe authored and mergify[bot] committed Jan 9, 2025
1 parent 6b943b2 commit b2d4581
Show file tree
Hide file tree
Showing 26 changed files with 2,406 additions and 29 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ Ref: https://keepachangelog.com/en/1.0.0/

Every module contains its own CHANGELOG.md. Please refer to the module you are interested in.

<<<<<<< HEAD
=======
### Features
* (sims) [#23013](https://github.com/cosmos/cosmos-sdk/pull/23013) Integration with app v2
* (baseapp) [#20291](https://github.com/cosmos/cosmos-sdk/pull/20291) Simulate nested messages.
* (client/keys) [#21829](https://github.com/cosmos/cosmos-sdk/pull/21829) Add support for importing hex key using standard input.
* (x/auth/ante) [#23128](https://github.com/cosmos/cosmos-sdk/pull/23128) Allow custom verifyIsOnCurve when validate tx for public key like ethsecp256k1.

>>>>>>> cf721a654 (feat(sims): Integration with app v2 (#23013))
### Improvements

* (codec) [#22988](https://github.com/cosmos/cosmos-sdk/pull/22988) Improve edge case handling for recursion limits.
Expand Down
113 changes: 113 additions & 0 deletions runtime/v2/app.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
package runtime

import (
"encoding/json"

runtimev2 "cosmossdk.io/api/cosmos/app/runtime/v2"
appmodulev2 "cosmossdk.io/core/appmodule/v2"
"cosmossdk.io/core/registry"
"cosmossdk.io/core/transaction"
"cosmossdk.io/log"
"cosmossdk.io/schema/decoding"
"cosmossdk.io/server/v2/appmanager"

Check failure on line 12 in runtime/v2/app.go

View workflow job for this annotation

GitHub Actions / split-test-files

no required module provides package cosmossdk.io/server/v2/appmanager; to add it:

Check failure on line 12 in runtime/v2/app.go

View workflow job for this annotation

GitHub Actions / dependency-review

no required module provides package cosmossdk.io/server/v2/appmanager; to add it:
"cosmossdk.io/server/v2/stf"

Check failure on line 13 in runtime/v2/app.go

View workflow job for this annotation

GitHub Actions / split-test-files

no required module provides package cosmossdk.io/server/v2/stf; to add it:

Check failure on line 13 in runtime/v2/app.go

View workflow job for this annotation

GitHub Actions / dependency-review

no required module provides package cosmossdk.io/server/v2/stf; to add it:
)

// App is a wrapper around AppManager and ModuleManager that can be used in hybrid
// app.go/app config scenarios or directly as a servertypes.Application instance.
// To get an instance of *App, *AppBuilder must be requested as a dependency
// in a container which declares the runtime module and the AppBuilder.Build()
// method must be called.
//
// App can be used to create a hybrid app.go setup where some configuration is
// done declaratively with an app config and the rest of it is done the old way.
// See simapp/v2/app.go for an example of this setup.
type App[T transaction.Tx] struct {
appmanager.AppManager[T]

// app configuration
logger log.Logger
config *runtimev2.Module

// state
stf *stf.STF[T]
msgRouterBuilder *stf.MsgRouterBuilder
queryRouterBuilder *stf.MsgRouterBuilder
db Store
storeLoader StoreLoader

// modules
interfaceRegistrar registry.InterfaceRegistrar
amino registry.AminoRegistrar
moduleManager *MM[T]
queryHandlers map[string]appmodulev2.Handler // queryHandlers defines the query handlers
}

// Name returns the app name.
func (a *App[T]) Name() string {
return a.config.AppName
}

// Logger returns the app logger.
func (a *App[T]) Logger() log.Logger {
return a.logger
}

// ModuleManager returns the module manager.
func (a *App[T]) ModuleManager() *MM[T] {
return a.moduleManager
}

// DefaultGenesis returns a default genesis from the registered modules.
func (a *App[T]) DefaultGenesis() map[string]json.RawMessage {
return a.moduleManager.DefaultGenesis()
}

// SetStoreLoader sets the store loader.
func (a *App[T]) SetStoreLoader(loader StoreLoader) {
a.storeLoader = loader
}

// LoadLatest loads the latest version.
func (a *App[T]) LoadLatest() error {
return a.storeLoader(a.db)
}

// LoadHeight loads a particular height
func (a *App[T]) LoadHeight(height uint64) error {
return a.db.LoadVersion(height)
}

// LoadLatestHeight loads the latest height.
func (a *App[T]) LoadLatestHeight() (uint64, error) {
return a.db.GetLatestVersion()
}

// QueryHandlers returns the query handlers.
func (a *App[T]) QueryHandlers() map[string]appmodulev2.Handler {
return a.queryHandlers
}

// SchemaDecoderResolver returns the module schema resolver.
func (a *App[T]) SchemaDecoderResolver() decoding.DecoderResolver {
moduleSet := map[string]any{}
for moduleName, module := range a.moduleManager.Modules() {
moduleSet[moduleName] = module
}

for _, overrideKey := range a.config.OverrideStoreKeys {
moduleSet[overrideKey.KvStoreKey] = moduleSet[overrideKey.ModuleName]
}

return decoding.ModuleSetDecoderResolver(moduleSet)
}

// Close is called in start cmd to gracefully cleanup resources.
func (a *App[T]) Close() error {
return nil
}

// GetApp return self
func (a *App[T]) GetApp() *App[T] {
return a
}
13 changes: 13 additions & 0 deletions scripts/build/simulations.mk
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,24 @@ test-sim-multi-seed-long:
@cd ${CURRENT_DIR}/simapp && go test -failfast -mod=readonly -timeout=2h -tags='sims' -run TestFullAppSimulation \
-NumBlocks=150 -Period=50

<<<<<<< HEAD
test-sim-multi-seed-short:
@echo "Running short multi-seed application simulation. This may take awhile!"
@cd ${CURRENT_DIR}/simapp && go test -failfast -mod=readonly -timeout 30m -tags='sims' -run TestFullAppSimulation \
-NumBlocks=50 -Period=10 -FauxMerkle=true

=======
test-sim-multi-seed-short: test-v2-sim
# @echo "Running short multi-seed application simulation. This may take awhile!"
# @cd ${CURRENT_DIR}/simapp && go test -failfast -mod=readonly -timeout 30m -tags='sims' -run TestFullAppSimulation \
# -NumBlocks=50 -Period=10 -FauxMerkle=true

.Phony: test-v2-sim
test-v2-sim:
@echo "Running short multi-seed application simulation. This may take awhile!"
@cd ${CURRENT_DIR}/simapp/v2 && go test -failfast -mod=readonly -timeout 30m -tags='sims' -run TestSimsAppV2 \
# -NumBlocks=50 -Period=10 -FauxMerkle=true
>>>>>>> cf721a654 (feat(sims): Integration with app v2 (#23013))

test-sim-benchmark-invariants:
@echo "Running simulation invariant benchmarks..."
Expand Down
Loading

0 comments on commit b2d4581

Please sign in to comment.