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

refactor(simapp): un-wire crisis #18380

Merged
merged 2 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
4 changes: 3 additions & 1 deletion server/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,9 @@ func AddCommands(rootCmd *cobra.Command, appCreator types.AppCreator, addStartFl
)

startCmd := StartCmd(appCreator)
addStartFlags(startCmd)
if addStartFlags != nil {
addStartFlags(startCmd)
}

rootCmd.AddCommand(
startCmd,
Expand Down
19 changes: 2 additions & 17 deletions simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,6 @@ import (
"github.com/cosmos/cosmos-sdk/x/consensus"
consensusparamkeeper "github.com/cosmos/cosmos-sdk/x/consensus/keeper"
consensusparamtypes "github.com/cosmos/cosmos-sdk/x/consensus/types"
"github.com/cosmos/cosmos-sdk/x/crisis"
crisiskeeper "github.com/cosmos/cosmos-sdk/x/crisis/keeper"
crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types"
"github.com/cosmos/cosmos-sdk/x/genutil"
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
)
Expand Down Expand Up @@ -157,7 +154,6 @@ type SimApp struct {
MintKeeper mintkeeper.Keeper
DistrKeeper distrkeeper.Keeper
GovKeeper govkeeper.Keeper
CrisisKeeper *crisiskeeper.Keeper
UpgradeKeeper *upgradekeeper.Keeper
AuthzKeeper authzkeeper.Keeper
EvidenceKeeper evidencekeeper.Keeper
Expand Down Expand Up @@ -255,7 +251,7 @@ func NewSimApp(
bApp.SetTxEncoder(txConfig.TxEncoder())

keys := storetypes.NewKVStoreKeys(
authtypes.StoreKey, banktypes.StoreKey, stakingtypes.StoreKey, crisistypes.StoreKey,
authtypes.StoreKey, banktypes.StoreKey, stakingtypes.StoreKey,
minttypes.StoreKey, distrtypes.StoreKey, slashingtypes.StoreKey,
govtypes.StoreKey, consensusparamtypes.StoreKey, upgradetypes.StoreKey, feegrant.StoreKey,
evidencetypes.StoreKey, circuittypes.StoreKey,
Expand Down Expand Up @@ -337,10 +333,6 @@ func NewSimApp(
appCodec, legacyAmino, runtime.NewKVStoreService(keys[slashingtypes.StoreKey]), app.StakingKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

invCheckPeriod := cast.ToUint(appOpts.Get(server.FlagInvCheckPeriod))
app.CrisisKeeper = crisiskeeper.NewKeeper(appCodec, runtime.NewKVStoreService(keys[crisistypes.StoreKey]), invCheckPeriod,
app.BankKeeper, authtypes.FeeCollectorName, authtypes.NewModuleAddress(govtypes.ModuleName).String(), app.AuthKeeper.AddressCodec())

app.FeeGrantKeeper = feegrantkeeper.NewKeeper(appCodec, runtime.NewKVStoreService(keys[feegrant.StoreKey]), app.AuthKeeper)

// register the staking hooks
Expand Down Expand Up @@ -405,10 +397,6 @@ func NewSimApp(

/**** Module Options ****/

// NOTE: we may consider parsing `appOpts` inside module constructors. For the moment
// we prefer to be more strict in what arguments the modules expect.
skipGenesisInvariants := cast.ToBool(appOpts.Get(crisis.FlagSkipGenesisInvariants))

// NOTE: Any module instantiated in the module manager that is later modified
// must be passed by reference here.
app.ModuleManager = module.NewManager(
Expand All @@ -420,7 +408,6 @@ func NewSimApp(
auth.NewAppModule(appCodec, app.AuthKeeper, authsims.RandomGenesisAccounts),
vesting.NewAppModule(app.AuthKeeper, app.BankKeeper),
bank.NewAppModule(appCodec, app.BankKeeper, app.AuthKeeper),
crisis.NewAppModule(app.CrisisKeeper, skipGenesisInvariants),
feegrantmodule.NewAppModule(appCodec, app.AuthKeeper, app.BankKeeper, app.FeeGrantKeeper, app.interfaceRegistry),
gov.NewAppModule(appCodec, &app.GovKeeper, app.AuthKeeper, app.BankKeeper, app.PoolKeeper),
mint.NewAppModule(appCodec, app.MintKeeper, app.AuthKeeper, nil),
Expand Down Expand Up @@ -470,7 +457,6 @@ func NewSimApp(
authz.ModuleName,
)
app.ModuleManager.SetOrderEndBlockers(
crisistypes.ModuleName,
govtypes.ModuleName,
stakingtypes.ModuleName,
genutiltypes.ModuleName,
Expand All @@ -485,7 +471,7 @@ func NewSimApp(
genesisModuleOrder := []string{
accounts.ModuleName, authtypes.ModuleName, banktypes.ModuleName,
distrtypes.ModuleName, stakingtypes.ModuleName, slashingtypes.ModuleName, govtypes.ModuleName,
minttypes.ModuleName, crisistypes.ModuleName, genutiltypes.ModuleName, evidencetypes.ModuleName, authz.ModuleName,
minttypes.ModuleName, genutiltypes.ModuleName, evidencetypes.ModuleName, authz.ModuleName,
feegrant.ModuleName, nft.ModuleName, group.ModuleName, upgradetypes.ModuleName,
vestingtypes.ModuleName, consensusparamtypes.ModuleName, circuittypes.ModuleName, pooltypes.ModuleName,
}
Expand All @@ -495,7 +481,6 @@ func NewSimApp(
// Uncomment if you want to set a custom migration order here.
// app.ModuleManager.SetOrderMigrations(custom order)

app.ModuleManager.RegisterInvariants(app.CrisisKeeper)
app.configurator = module.NewConfigurator(app.appCodec, app.MsgServiceRouter(), app.GRPCQueryRouter())
err = app.ModuleManager.RegisterServices(app.configurator)
if err != nil {
Expand Down
9 changes: 0 additions & 9 deletions simapp/app_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
bankmodulev1 "cosmossdk.io/api/cosmos/bank/module/v1"
circuitmodulev1 "cosmossdk.io/api/cosmos/circuit/module/v1"
consensusmodulev1 "cosmossdk.io/api/cosmos/consensus/module/v1"
crisismodulev1 "cosmossdk.io/api/cosmos/crisis/module/v1"
distrmodulev1 "cosmossdk.io/api/cosmos/distribution/module/v1"
evidencemodulev1 "cosmossdk.io/api/cosmos/evidence/module/v1"
feegrantmodulev1 "cosmossdk.io/api/cosmos/feegrant/module/v1"
Expand Down Expand Up @@ -67,8 +66,6 @@ import (
vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
_ "github.com/cosmos/cosmos-sdk/x/consensus" // import for side-effects
consensustypes "github.com/cosmos/cosmos-sdk/x/consensus/types"
_ "github.com/cosmos/cosmos-sdk/x/crisis" // import for side-effects
crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types"
"github.com/cosmos/cosmos-sdk/x/genutil"
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
)
Expand Down Expand Up @@ -123,7 +120,6 @@ var (
authz.ModuleName,
},
EndBlockers: []string{
crisistypes.ModuleName,
govtypes.ModuleName,
stakingtypes.ModuleName,
feegrant.ModuleName,
Expand All @@ -147,7 +143,6 @@ var (
slashingtypes.ModuleName,
govtypes.ModuleName,
minttypes.ModuleName,
crisistypes.ModuleName,
genutiltypes.ModuleName,
evidencetypes.ModuleName,
authz.ModuleName,
Expand Down Expand Up @@ -245,10 +240,6 @@ var (
Name: govtypes.ModuleName,
Config: appconfig.WrapAny(&govmodulev1.Module{}),
},
{
Name: crisistypes.ModuleName,
Config: appconfig.WrapAny(&crisismodulev1.Module{}),
},
{
Name: consensustypes.ModuleName,
Config: appconfig.WrapAny(&consensusmodulev1.Module{}),
Expand Down
3 changes: 0 additions & 3 deletions simapp/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import (
"github.com/cosmos/cosmos-sdk/types/msgservice"
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/auth/vesting"
"github.com/cosmos/cosmos-sdk/x/crisis"
"github.com/cosmos/cosmos-sdk/x/genutil"
)

Expand Down Expand Up @@ -211,7 +210,6 @@ func TestRunMigrations(t *testing.T) {
"vesting": vesting.AppModule{}.ConsensusVersion(),
"feegrant": feegrantmodule.AppModule{}.ConsensusVersion(),
"evidence": evidence.AppModule{}.ConsensusVersion(),
"crisis": crisis.AppModule{}.ConsensusVersion(),
"genutil": genutil.AppModule{}.ConsensusVersion(),
},
)
Expand Down Expand Up @@ -259,7 +257,6 @@ func TestInitGenesisOnMigration(t *testing.T) {
"vesting": vesting.AppModule{}.ConsensusVersion(),
"feegrant": feegrantmodule.AppModule{}.ConsensusVersion(),
"evidence": evidence.AppModule{}.ConsensusVersion(),
"crisis": crisis.AppModule{}.ConsensusVersion(),
"genutil": genutil.AppModule{}.ConsensusVersion(),
},
)
Expand Down
5 changes: 0 additions & 5 deletions simapp/app_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ import (
authsims "github.com/cosmos/cosmos-sdk/x/auth/simulation"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
consensuskeeper "github.com/cosmos/cosmos-sdk/x/consensus/keeper"
crisiskeeper "github.com/cosmos/cosmos-sdk/x/crisis/keeper"
)

// DefaultNodeHome default home directories for the application daemon
Expand Down Expand Up @@ -73,7 +72,6 @@ type SimApp struct {
MintKeeper mintkeeper.Keeper
DistrKeeper distrkeeper.Keeper
GovKeeper *govkeeper.Keeper
CrisisKeeper *crisiskeeper.Keeper
UpgradeKeeper *upgradekeeper.Keeper
AuthzKeeper authzkeeper.Keeper
EvidenceKeeper evidencekeeper.Keeper
Expand Down Expand Up @@ -175,7 +173,6 @@ func NewSimApp(
&app.MintKeeper,
&app.DistrKeeper,
&app.GovKeeper,
&app.CrisisKeeper,
&app.UpgradeKeeper,
&app.AuthzKeeper,
&app.EvidenceKeeper,
Expand Down Expand Up @@ -231,8 +228,6 @@ func NewSimApp(

/**** Module Options ****/

app.ModuleManager.RegisterInvariants(app.CrisisKeeper)

// RegisterUpgradeHandlers is used for registering any on-chain upgrades.
app.RegisterUpgradeHandlers()

Expand Down
3 changes: 0 additions & 3 deletions simapp/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,6 @@ func (app *SimApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []
allowedAddrsMap[addr] = true
}

/* Just to be safe, assert the invariants on current state. */
app.CrisisKeeper.AssertInvariants(ctx)

/* Handle fee distribution state. */

// withdraw all validator commission
Expand Down
75 changes: 0 additions & 75 deletions simapp/sim_bench_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package simapp

import (
"fmt"
"os"
"testing"

cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
flag "github.com/spf13/pflag"
"github.com/spf13/viper"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -89,76 +87,3 @@ func BenchmarkFullAppSimulation(b *testing.B) {
simtestutil.PrintStats(db)
}
}

func BenchmarkInvariants(b *testing.B) {
b.ReportAllocs()

config := simcli.NewConfigFromFlags()
config.ChainID = SimAppChainID

db, dir, logger, skip, err := simtestutil.SetupSimulation(config, "leveldb-app-invariant-bench", "Simulation", simcli.FlagVerboseValue, simcli.FlagEnabledValue)
if err != nil {
b.Fatalf("simulation setup failed: %s", err.Error())
}

if skip {
b.Skip("skipping benchmark application simulation")
}

config.AllInvariants = false

defer func() {
require.NoError(b, db.Close())
require.NoError(b, os.RemoveAll(dir))
}()

appOptions := make(simtestutil.AppOptionsMap, 0)
appOptions[flags.FlagHome] = DefaultNodeHome
appOptions[server.FlagInvCheckPeriod] = simcli.FlagPeriodValue

app := NewSimApp(logger, db, nil, true, appOptions, interBlockCacheOpt(), baseapp.SetChainID(SimAppChainID))

// run randomized simulation
_, simParams, simErr := simulation.SimulateFromSeed(
b,
os.Stdout,
app.BaseApp,
simtestutil.AppStateFn(app.AppCodec(), app.SimulationManager(), app.DefaultGenesis()),
simtypes.RandomAccounts, // Replace with own random account function if using keys other than secp256k1
simtestutil.SimulationOperations(app, app.AppCodec(), config),
BlockedAddresses(),
config,
app.AppCodec(),
)

// export state and simParams before the simulation error is checked
if err = simtestutil.CheckExportSimulation(app, config, simParams); err != nil {
b.Fatal(err)
}

if simErr != nil {
b.Fatal(simErr)
}

if config.Commit {
simtestutil.PrintStats(db)
}

ctx := app.NewContextLegacy(true, cmtproto.Header{Height: app.LastBlockHeight() + 1})

// 3. Benchmark each invariant separately
//
// NOTE: We use the crisis keeper as it has all the invariants registered with
// their respective metadata which makes it useful for testing/benchmarking.
for _, cr := range app.CrisisKeeper.Routes() {
cr := cr
b.Run(fmt.Sprintf("%s/%s", cr.ModuleName, cr.Route), func(b *testing.B) {
if res, stop := cr.Invar(ctx); stop {
b.Fatalf(
"broken invariant at block %d of %d\n%s",
ctx.BlockHeight()-1, config.NumBlocks, res,
)
}
})
}
}
7 changes: 1 addition & 6 deletions simapp/simd/cmd/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
"github.com/cosmos/cosmos-sdk/x/crisis"
genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli"
)

Expand All @@ -51,7 +50,7 @@ func initRootCmd(
snapshot.Cmd(newApp),
)

server.AddCommands(rootCmd, newApp, addModuleInitFlags)
server.AddCommands(rootCmd, newApp, func(startCmd *cobra.Command) {})

// add keybase, auxiliary RPC, query, genesis, and tx child commands
rootCmd.AddCommand(
Expand All @@ -63,10 +62,6 @@ func initRootCmd(
)
}

func addModuleInitFlags(startCmd *cobra.Command) {
crisis.AddModuleInitFlags(startCmd)
}

// genesisCommand builds genesis-related `simd genesis` command. Users may provide application specific commands as a parameter
func genesisCommand(txConfig client.TxConfig, basicManager module.BasicManager, appExport servertypes.AppExporter, cmds ...*cobra.Command) *cobra.Command {
cmd := genutilcli.Commands(txConfig, basicManager, appExport)
Expand Down
Loading