From dda47b5e0e8b503d98318de3d90f98210b055260 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Fri, 6 Dec 2024 15:16:59 +0100 Subject: [PATCH] chore: clean-up main (#22787) --- .github/workflows/build.yml | 4 +- .github/workflows/test.yml | 5 - math/dec_test.go | 2 +- schema/indexer/start.go | 2 +- scripts/build/build.mk | 4 - scripts/go-lint-all.bash | 5 - server/v2/cometbft/abci_test.go | 21 +- simapp/CHANGELOG.md | 2 +- simapp/app.go | 890 ------------------ simapp/app_di.go | 2 - simapp/go.mod | 4 +- simapp/simd/cmd/root.go | 137 --- simapp/simd/cmd/root_di.go | 2 - tests/integration/v2/app.go | 2 + .../v2/evidence/infraction_test.go | 21 +- 15 files changed, 20 insertions(+), 1083 deletions(-) delete mode 100644 simapp/app.go delete mode 100644 simapp/simd/cmd/root.go diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e6c6f4ee640c..d2a99a8f0523 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -50,8 +50,8 @@ jobs: ################### - name: Build run: GOARCH=${{ matrix.go-arch }} make build - - name: Build Legacy - run: GOARCH=${{ matrix.go-arch }} COSMOS_BUILD_OPTIONS=legacy make build + - name: Build v2 + run: GOARCH=${{ matrix.go-arch }} COSMOS_BUILD_OPTIONS=v2 make build - name: Build with rocksdb backend if: matrix.go-arch == 'amd64' run: GOARCH=${{ matrix.go-arch }} COSMOS_BUILD_OPTIONS="rocksdb" make build diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4990e889c330..19f27d25d952 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -526,11 +526,6 @@ jobs: run: | cd simapp go test -mod=readonly -timeout 30m -tags='norace ledger test_ledger_mock' ./... - - name: tests simapp v1 - if: env.GIT_DIFF - run: | - cd simapp - go test -mod=readonly -timeout 30m -tags='app_v1 norace ledger test_ledger_mock' ./... test-simapp-v2: runs-on: ubuntu-latest diff --git a/math/dec_test.go b/math/dec_test.go index f5e91572c0d2..0b148032eb1f 100644 --- a/math/dec_test.go +++ b/math/dec_test.go @@ -1282,7 +1282,7 @@ func TestToSdkInt(t *testing.T) { {src: "1E100000", expErr: true}, } for _, tc := range tcs { - t.Run(fmt.Sprintf(tc.src), func(t *testing.T) { + t.Run(fmt.Sprint(tc.src), func(t *testing.T) { a, err := NewDecFromString(tc.src) require.NoError(t, err) b, gotErr := a.SdkIntTrim() diff --git a/schema/indexer/start.go b/schema/indexer/start.go index f675c2916026..66fbdb52a6d3 100644 --- a/schema/indexer/start.go +++ b/schema/indexer/start.go @@ -120,7 +120,7 @@ func StartIndexing(opts IndexingOptions) (IndexingTarget, error) { targetCfg.Config, err = unmarshalIndexerCustomConfig(targetCfg.Config, init.ConfigType) if err != nil { - return IndexingTarget{}, fmt.Errorf("failed to unmarshal indexer config for target %q: %v", targetName, err) + return IndexingTarget{}, fmt.Errorf("failed to unmarshal indexer config for target %q: %v", targetName, err) //nolint:errorlint // we support go 1.12, so no error wrapping } initRes, err := init.InitFunc(InitParams{ diff --git a/scripts/build/build.mk b/scripts/build/build.mk index 4727b05e98a3..581ee1dbe06d 100644 --- a/scripts/build/build.mk +++ b/scripts/build/build.mk @@ -48,10 +48,6 @@ ifeq (secp,$(findstring secp,$(COSMOS_BUILD_OPTIONS))) build_tags += libsecp256k1_sdk endif -ifeq (legacy,$(findstring legacy,$(COSMOS_BUILD_OPTIONS))) - build_tags += app_v1 -endif - ifeq (v2,$(findstring v2,$(COSMOS_BUILD_OPTIONS))) SIMAPP = simapp/v2 APPNAME = simdv2 diff --git a/scripts/go-lint-all.bash b/scripts/go-lint-all.bash index 565aa6a41649..f643cc56aa46 100755 --- a/scripts/go-lint-all.bash +++ b/scripts/go-lint-all.bash @@ -21,11 +21,6 @@ lint_module() { fi echo "linting $(grep "^module" go.mod) [$(date -Iseconds -u)]" golangci-lint run ./... -c "${REPO_ROOT}/.golangci.yml" "$@" --build-tags=${LINT_TAGS} - - # always lint simapp with app_v1 build tag, otherwise it never gets linted - if [[ "$(grep "^module" go.mod)" == "module cosmossdk.io/simapp" ]]; then - golangci-lint run ./... -c "${REPO_ROOT}/.golangci.yml" "$@" --build-tags=app_v1 - fi } export -f lint_module diff --git a/server/v2/cometbft/abci_test.go b/server/v2/cometbft/abci_test.go index cfc649884660..17ff917c6511 100644 --- a/server/v2/cometbft/abci_test.go +++ b/server/v2/cometbft/abci_test.go @@ -15,7 +15,6 @@ import ( abci "github.com/cometbft/cometbft/abci/types" abciproto "github.com/cometbft/cometbft/api/cometbft/abci/v1" v1 "github.com/cometbft/cometbft/api/cometbft/types/v1" - "github.com/cosmos/gogoproto/proto" gogoproto "github.com/cosmos/gogoproto/proto" gogotypes "github.com/cosmos/gogoproto/types" "github.com/stretchr/testify/require" @@ -65,11 +64,11 @@ var ( func getQueryRouterBuilder[T any, PT interface { *T - proto.Message + gogoproto.Message }, U any, UT interface { *U - proto.Message + gogoproto.Message }]( t *testing.T, handler func(ctx context.Context, msg PT) (UT, error), @@ -77,7 +76,7 @@ func getQueryRouterBuilder[T any, PT interface { t.Helper() queryRouterBuilder := stf.NewMsgRouterBuilder() err := queryRouterBuilder.RegisterHandler( - proto.MessageName(PT(new(T))), + gogoproto.MessageName(PT(new(T))), func(ctx context.Context, msg transaction.Msg) (msgResp transaction.Msg, err error) { typedReq := msg.(PT) typedResp, err := handler(ctx, typedReq) @@ -107,7 +106,7 @@ func getMsgRouterBuilder[T any, PT interface { t.Helper() msgRouterBuilder := stf.NewMsgRouterBuilder() err := msgRouterBuilder.RegisterHandler( - proto.MessageName(PT(new(T))), + gogoproto.MessageName(PT(new(T))), func(ctx context.Context, msg transaction.Msg) (msgResp transaction.Msg, err error) { typedReq := msg.(PT) typedResp, err := handler(ctx, typedReq) @@ -821,18 +820,18 @@ func setUpConsensus(t *testing.T, gasLimit uint64, mempool mempool.Mempool[mock. return typedResp, nil } - queryRouterBuilder.RegisterHandler( - proto.MessageName(&testdata.SayHelloRequest{}), + _ = queryRouterBuilder.RegisterHandler( + gogoproto.MessageName(&testdata.SayHelloRequest{}), helloFooHandler, ) - queryHandler[proto.MessageName(&testdata.SayHelloRequest{})] = appmodulev2.Handler{ + queryHandler[gogoproto.MessageName(&testdata.SayHelloRequest{})] = appmodulev2.Handler{ Func: helloFooHandler, MakeMsg: func() transaction.Msg { - return reflect.New(gogoproto.MessageType(proto.MessageName(&testdata.SayHelloRequest{})).Elem()).Interface().(transaction.Msg) + return reflect.New(gogoproto.MessageType(gogoproto.MessageName(&testdata.SayHelloRequest{})).Elem()).Interface().(transaction.Msg) }, MakeMsgResp: func() transaction.Msg { - return reflect.New(gogoproto.MessageType(proto.MessageName(&testdata.SayHelloResponse{})).Elem()).Interface().(transaction.Msg) + return reflect.New(gogoproto.MessageType(gogoproto.MessageName(&testdata.SayHelloResponse{})).Elem()).Interface().(transaction.Msg) }, } @@ -895,7 +894,7 @@ func setUpConsensus(t *testing.T, gasLimit uint64, mempool mempool.Mempool[mock. cfg: Config{AppTomlConfig: DefaultAppTomlConfig()}, txCodec: mock.TxCodec{}, chainID: "test", - getProtoRegistry: sync.OnceValues(proto.MergedRegistry), + getProtoRegistry: sync.OnceValues(gogoproto.MergedRegistry), queryHandlersMap: queryHandler, addrPeerFilter: addrPeerFilter, idPeerFilter: idPeerFilter, diff --git a/simapp/CHANGELOG.md b/simapp/CHANGELOG.md index edc90c22cf89..55861fab0d3d 100644 --- a/simapp/CHANGELOG.md +++ b/simapp/CHANGELOG.md @@ -47,7 +47,7 @@ Always refer to the [UPGRADING.md](https://github.com/cosmos/cosmos-sdk/blob/mai * [#19726](https://github.com/cosmos/cosmos-sdk/pull/19726) Update APIs to match CometBFT v1. * [#21466](https://github.com/cosmos/cosmos-sdk/pull/21466) Allow chains to plug in their own public key types in `base.Account` * [#21508](https://github.com/cosmos/cosmos-sdk/pull/21508) Abstract the way we update the version of the app state in `app.go` using the interface `VersionModifier`. - + ## v0.47 to v0.50 diff --git a/simapp/app.go b/simapp/app.go deleted file mode 100644 index 7417205250c0..000000000000 --- a/simapp/app.go +++ /dev/null @@ -1,890 +0,0 @@ -//go:build app_v1 - -package simapp - -import ( - "encoding/json" - "fmt" - "io" - "maps" - "os" - "path/filepath" - - abci "github.com/cometbft/cometbft/api/cometbft/abci/v1" - cmtcrypto "github.com/cometbft/cometbft/crypto" - cmted25519 "github.com/cometbft/cometbft/crypto/ed25519" - "github.com/cosmos/gogoproto/proto" - "github.com/spf13/cast" - - autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" - reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1" - "cosmossdk.io/client/v2/autocli" - clienthelpers "cosmossdk.io/client/v2/helpers" - coreaddress "cosmossdk.io/core/address" - corestore "cosmossdk.io/core/store" - "cosmossdk.io/log" - storetypes "cosmossdk.io/store/types" - "cosmossdk.io/x/accounts" - "cosmossdk.io/x/accounts/accountstd" - baseaccount "cosmossdk.io/x/accounts/defaults/base" - lockup "cosmossdk.io/x/accounts/defaults/lockup" - "cosmossdk.io/x/accounts/defaults/multisig" - "cosmossdk.io/x/accounts/testing/account_abstraction" - "cosmossdk.io/x/accounts/testing/counter" - "cosmossdk.io/x/authz" - authzkeeper "cosmossdk.io/x/authz/keeper" - authzmodule "cosmossdk.io/x/authz/module" - "cosmossdk.io/x/bank" - bankkeeper "cosmossdk.io/x/bank/keeper" - banktypes "cosmossdk.io/x/bank/types" - "cosmossdk.io/x/circuit" - circuitkeeper "cosmossdk.io/x/circuit/keeper" - circuittypes "cosmossdk.io/x/circuit/types" - "cosmossdk.io/x/consensus" - consensusparamkeeper "cosmossdk.io/x/consensus/keeper" - consensustypes "cosmossdk.io/x/consensus/types" - distr "cosmossdk.io/x/distribution" - distrkeeper "cosmossdk.io/x/distribution/keeper" - distrtypes "cosmossdk.io/x/distribution/types" - "cosmossdk.io/x/epochs" - epochskeeper "cosmossdk.io/x/epochs/keeper" - epochstypes "cosmossdk.io/x/epochs/types" - "cosmossdk.io/x/evidence" - evidencekeeper "cosmossdk.io/x/evidence/keeper" - evidencetypes "cosmossdk.io/x/evidence/types" - "cosmossdk.io/x/feegrant" - feegrantkeeper "cosmossdk.io/x/feegrant/keeper" - feegrantmodule "cosmossdk.io/x/feegrant/module" - "cosmossdk.io/x/gov" - govkeeper "cosmossdk.io/x/gov/keeper" - govtypes "cosmossdk.io/x/gov/types" - govv1 "cosmossdk.io/x/gov/types/v1" - govv1beta1 "cosmossdk.io/x/gov/types/v1beta1" - "cosmossdk.io/x/group" - groupkeeper "cosmossdk.io/x/group/keeper" - groupmodule "cosmossdk.io/x/group/module" - "cosmossdk.io/x/mint" - mintkeeper "cosmossdk.io/x/mint/keeper" - minttypes "cosmossdk.io/x/mint/types" - "cosmossdk.io/x/nft" - nftkeeper "cosmossdk.io/x/nft/keeper" - nftmodule "cosmossdk.io/x/nft/module" - "cosmossdk.io/x/protocolpool" - poolkeeper "cosmossdk.io/x/protocolpool/keeper" - pooltypes "cosmossdk.io/x/protocolpool/types" - "cosmossdk.io/x/slashing" - slashingkeeper "cosmossdk.io/x/slashing/keeper" - slashingtypes "cosmossdk.io/x/slashing/types" - "cosmossdk.io/x/staking" - stakingkeeper "cosmossdk.io/x/staking/keeper" - stakingtypes "cosmossdk.io/x/staking/types" - txdecode "cosmossdk.io/x/tx/decode" - "cosmossdk.io/x/tx/signing" - "cosmossdk.io/x/upgrade" - upgradekeeper "cosmossdk.io/x/upgrade/keeper" - upgradetypes "cosmossdk.io/x/upgrade/types" - - "github.com/cosmos/cosmos-sdk/baseapp" - "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/client/flags" - "github.com/cosmos/cosmos-sdk/client/grpc/cmtservice" - nodeservice "github.com/cosmos/cosmos-sdk/client/grpc/node" - "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/codec/address" - "github.com/cosmos/cosmos-sdk/codec/types" - "github.com/cosmos/cosmos-sdk/runtime" - runtimeservices "github.com/cosmos/cosmos-sdk/runtime/services" - "github.com/cosmos/cosmos-sdk/server" - "github.com/cosmos/cosmos-sdk/server/api" - "github.com/cosmos/cosmos-sdk/server/config" - servertypes "github.com/cosmos/cosmos-sdk/server/types" - "github.com/cosmos/cosmos-sdk/std" - testdata_pulsar "github.com/cosmos/cosmos-sdk/testutil/testdata/testpb" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/module" - "github.com/cosmos/cosmos-sdk/types/msgservice" - sigtypes "github.com/cosmos/cosmos-sdk/types/tx/signing" - "github.com/cosmos/cosmos-sdk/version" - "github.com/cosmos/cosmos-sdk/x/auth" - "github.com/cosmos/cosmos-sdk/x/auth/ante" - "github.com/cosmos/cosmos-sdk/x/auth/ante/unorderedtx" - authcodec "github.com/cosmos/cosmos-sdk/x/auth/codec" - authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" - "github.com/cosmos/cosmos-sdk/x/auth/posthandler" - authsims "github.com/cosmos/cosmos-sdk/x/auth/simulation" - authtx "github.com/cosmos/cosmos-sdk/x/auth/tx" - txmodule "github.com/cosmos/cosmos-sdk/x/auth/tx/config" - authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - "github.com/cosmos/cosmos-sdk/x/auth/vesting" - vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types" - "github.com/cosmos/cosmos-sdk/x/genutil" - genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" -) - -const appName = "SimApp" - -var ( - // DefaultNodeHome default home directories for the application daemon - DefaultNodeHome string - - // module account permissions - maccPerms = map[string][]string{ - authtypes.FeeCollectorName: nil, - distrtypes.ModuleName: nil, - pooltypes.ModuleName: nil, - pooltypes.StreamAccount: nil, - pooltypes.ProtocolPoolDistrAccount: nil, - minttypes.ModuleName: {authtypes.Minter}, - stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking}, - stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking}, - govtypes.ModuleName: {authtypes.Burner}, - nft.ModuleName: nil, - } -) - -var ( - _ runtime.AppI = (*SimApp)(nil) - _ servertypes.Application = (*SimApp)(nil) -) - -// SimApp extends an ABCI application, but with most of its parameters exported. -// They are exported for convenience in creating helper functions, as object -// capabilities aren't needed for testing. -type SimApp struct { - *baseapp.BaseApp - logger log.Logger - legacyAmino *codec.LegacyAmino - appCodec codec.Codec - txConfig client.TxConfig - interfaceRegistry types.InterfaceRegistry - - // keys to access the substores - keys map[string]*storetypes.KVStoreKey - - // keepers - AccountsKeeper accounts.Keeper - AuthKeeper authkeeper.AccountKeeper - BankKeeper bankkeeper.BaseKeeper - StakingKeeper *stakingkeeper.Keeper - SlashingKeeper slashingkeeper.Keeper - MintKeeper *mintkeeper.Keeper - DistrKeeper distrkeeper.Keeper - GovKeeper govkeeper.Keeper - UpgradeKeeper *upgradekeeper.Keeper - AuthzKeeper authzkeeper.Keeper - EvidenceKeeper evidencekeeper.Keeper - FeeGrantKeeper feegrantkeeper.Keeper - GroupKeeper groupkeeper.Keeper - NFTKeeper nftkeeper.Keeper - ConsensusParamsKeeper consensusparamkeeper.Keeper - CircuitKeeper circuitkeeper.Keeper - PoolKeeper poolkeeper.Keeper - EpochsKeeper *epochskeeper.Keeper - - // managers - ModuleManager *module.Manager - UnorderedTxManager *unorderedtx.Manager - sm *module.SimulationManager - - // module configurator - configurator module.Configurator //nolint:staticcheck // SA1019: Configurator is deprecated but still used in runtime v1. -} - -func init() { - var err error - DefaultNodeHome, err = clienthelpers.GetNodeHomeDirectory(".simapp") - if err != nil { - panic(err) - } -} - -// NewSimApp returns a reference to an initialized SimApp. -func NewSimApp( - logger log.Logger, - db corestore.KVStoreWithBatch, - traceStore io.Writer, - loadLatest bool, - appOpts servertypes.AppOptions, - baseAppOptions ...func(*baseapp.BaseApp), -) *SimApp { - interfaceRegistry, _ := types.NewInterfaceRegistryWithOptions(types.InterfaceRegistryOptions{ - ProtoFiles: proto.HybridResolver, - SigningOptions: signing.Options{ - AddressCodec: address.NewBech32Codec(sdk.GetConfig().GetBech32AccountAddrPrefix()), - ValidatorAddressCodec: address.NewBech32Codec(sdk.GetConfig().GetBech32ValidatorAddrPrefix()), - }, - }) - appCodec := codec.NewProtoCodec(interfaceRegistry) - legacyAmino := codec.NewLegacyAmino() - signingCtx := interfaceRegistry.SigningContext() - txDecoder, err := txdecode.NewDecoder(txdecode.Options{ - SigningContext: signingCtx, - ProtoCodec: appCodec, - }) - if err != nil { - panic(err) - } - txConfig := authtx.NewTxConfig(appCodec, signingCtx.AddressCodec(), signingCtx.ValidatorAddressCodec(), authtx.DefaultSignModes) - - govModuleAddr, err := signingCtx.AddressCodec().BytesToString(authtypes.NewModuleAddress(govtypes.ModuleName)) - if err != nil { - panic(err) - } - - if err := signingCtx.Validate(); err != nil { - panic(err) - } - - std.RegisterLegacyAminoCodec(legacyAmino) - std.RegisterInterfaces(interfaceRegistry) - - // Below we could construct and set an application specific mempool and - // ABCI 1.0 PrepareProposal and ProcessProposal handlers. These defaults are - // already set in the SDK's BaseApp, this shows an example of how to override - // them. - // - // Example: - // - // bApp := baseapp.NewBaseApp(...) - // nonceMempool := mempool.NewSenderNonceMempool() - // abciPropHandler := NewDefaultProposalHandler(nonceMempool, bApp) - // - // bApp.SetMempool(nonceMempool) - // bApp.SetPrepareProposal(abciPropHandler.PrepareProposalHandler()) - // bApp.SetProcessProposal(abciPropHandler.ProcessProposalHandler()) - // - // Alternatively, you can construct BaseApp options, append those to - // baseAppOptions and pass them to NewBaseApp. - // - // Example: - // - // prepareOpt = func(app *baseapp.BaseApp) { - // abciPropHandler := baseapp.NewDefaultProposalHandler(nonceMempool, app) - // app.SetPrepareProposal(abciPropHandler.PrepareProposalHandler()) - // } - // baseAppOptions = append(baseAppOptions, prepareOpt) - - // create and set dummy vote extension handler - voteExtOp := func(bApp *baseapp.BaseApp) { - voteExtHandler := NewVoteExtensionHandler() - voteExtHandler.SetHandlers(bApp) - } - baseAppOptions = append(baseAppOptions, voteExtOp, baseapp.SetOptimisticExecution(), - baseapp.SetIncludeNestedMsgsGas([]sdk.Msg{&govv1.MsgSubmitProposal{}})) - - bApp := baseapp.NewBaseApp(appName, logger, db, txConfig.TxDecoder(), baseAppOptions...) - bApp.SetCommitMultiStoreTracer(traceStore) - bApp.SetVersion(version.Version) - bApp.SetInterfaceRegistry(interfaceRegistry) - bApp.SetTxEncoder(txConfig.TxEncoder()) - - keys := storetypes.NewKVStoreKeys( - authtypes.StoreKey, banktypes.StoreKey, stakingtypes.StoreKey, - minttypes.StoreKey, distrtypes.StoreKey, slashingtypes.StoreKey, - govtypes.StoreKey, consensustypes.StoreKey, upgradetypes.StoreKey, feegrant.StoreKey, - evidencetypes.StoreKey, circuittypes.StoreKey, - authzkeeper.StoreKey, nftkeeper.StoreKey, group.StoreKey, pooltypes.StoreKey, - accounts.StoreKey, epochstypes.StoreKey, - ) - - // register streaming services - if err := bApp.RegisterStreamingServices(appOpts, keys); err != nil { - panic(err) - } - - app := &SimApp{ - BaseApp: bApp, - logger: logger, - legacyAmino: legacyAmino, - appCodec: appCodec, - txConfig: txConfig, - interfaceRegistry: interfaceRegistry, - keys: keys, - } - cometService := runtime.NewContextAwareCometInfoService() - - // set the BaseApp's parameter store - app.ConsensusParamsKeeper = consensusparamkeeper.NewKeeper(appCodec, runtime.NewEnvironment(runtime.NewKVStoreService(keys[consensustypes.StoreKey]), logger.With(log.ModuleKey, "x/consensus")), govModuleAddr) - bApp.SetParamStore(app.ConsensusParamsKeeper.ParamsStore) - - // set the version modifier - bApp.SetVersionModifier(consensus.ProvideAppVersionModifier(app.ConsensusParamsKeeper)) - - // add keepers - accountsKeeper, err := accounts.NewKeeper( - appCodec, - runtime.NewEnvironment(runtime.NewKVStoreService(keys[accounts.StoreKey]), logger.With(log.ModuleKey, "x/accounts"), runtime.EnvWithMsgRouterService(app.MsgServiceRouter()), runtime.EnvWithQueryRouterService(app.GRPCQueryRouter())), - signingCtx.AddressCodec(), - appCodec.InterfaceRegistry(), - txDecoder, - // TESTING: do not add - accountstd.AddAccount("counter", counter.NewAccount), - accountstd.AddAccount("aa_minimal", account_abstraction.NewMinimalAbstractedAccount), - // Lockup account - accountstd.AddAccount(lockup.CONTINUOUS_LOCKING_ACCOUNT, lockup.NewContinuousLockingAccount), - accountstd.AddAccount(lockup.PERIODIC_LOCKING_ACCOUNT, lockup.NewPeriodicLockingAccount), - accountstd.AddAccount(lockup.DELAYED_LOCKING_ACCOUNT, lockup.NewDelayedLockingAccount), - accountstd.AddAccount(lockup.PERMANENT_LOCKING_ACCOUNT, lockup.NewPermanentLockingAccount), - accountstd.AddAccount("multisig", multisig.NewAccount), - // PRODUCTION: add - baseaccount.NewAccount("base", txConfig.SignModeHandler(), baseaccount.WithSecp256K1PubKey()), - ) - if err != nil { - panic(err) - } - app.AccountsKeeper = accountsKeeper - - app.AuthKeeper = authkeeper.NewAccountKeeper(runtime.NewEnvironment(runtime.NewKVStoreService(keys[authtypes.StoreKey]), logger.With(log.ModuleKey, "x/auth")), appCodec, authtypes.ProtoBaseAccount, accountsKeeper, maccPerms, signingCtx.AddressCodec(), sdk.Bech32MainPrefix, govModuleAddr) - - blockedAddrs, err := BlockedAddresses(signingCtx.AddressCodec()) - if err != nil { - panic(err) - } - app.BankKeeper = bankkeeper.NewBaseKeeper( - runtime.NewEnvironment(runtime.NewKVStoreService(keys[banktypes.StoreKey]), logger.With(log.ModuleKey, "x/bank")), - appCodec, - app.AuthKeeper, - blockedAddrs, - govModuleAddr, - ) - - // optional: enable sign mode textual by overwriting the default tx config (after setting the bank keeper) - enabledSignModes := append(authtx.DefaultSignModes, sigtypes.SignMode_SIGN_MODE_TEXTUAL) - txConfigOpts := authtx.ConfigOptions{ - EnabledSignModes: enabledSignModes, - TextualCoinMetadataQueryFn: txmodule.NewBankKeeperCoinMetadataQueryFn(app.BankKeeper), - SigningOptions: &signing.Options{ - AddressCodec: signingCtx.AddressCodec(), - ValidatorAddressCodec: signingCtx.ValidatorAddressCodec(), - }, - } - txConfig, err = authtx.NewTxConfigWithOptions( - appCodec, - txConfigOpts, - ) - if err != nil { - panic(err) - } - app.txConfig = txConfig - - app.StakingKeeper = stakingkeeper.NewKeeper( - appCodec, - runtime.NewEnvironment( - runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), - logger.With(log.ModuleKey, "x/staking"), - runtime.EnvWithMsgRouterService(app.MsgServiceRouter()), - runtime.EnvWithQueryRouterService(app.GRPCQueryRouter())), - app.AuthKeeper, - app.BankKeeper, - app.ConsensusParamsKeeper, - govModuleAddr, - signingCtx.ValidatorAddressCodec(), - authcodec.NewBech32Codec(sdk.Bech32PrefixConsAddr), - cometService, - ) - - app.MintKeeper = mintkeeper.NewKeeper(appCodec, runtime.NewEnvironment(runtime.NewKVStoreService(keys[minttypes.StoreKey]), logger.With(log.ModuleKey, "x/mint")), app.AuthKeeper, app.BankKeeper, authtypes.FeeCollectorName, govModuleAddr) - if err := app.MintKeeper.SetMintFn(mintkeeper.DefaultMintFn(minttypes.DefaultInflationCalculationFn, app.StakingKeeper, app.MintKeeper)); err != nil { - panic(err) - } - - app.PoolKeeper = poolkeeper.NewKeeper(appCodec, runtime.NewEnvironment(runtime.NewKVStoreService(keys[pooltypes.StoreKey]), logger.With(log.ModuleKey, "x/protocolpool")), app.AuthKeeper, app.BankKeeper, govModuleAddr) - - app.DistrKeeper = distrkeeper.NewKeeper(appCodec, runtime.NewEnvironment(runtime.NewKVStoreService(keys[distrtypes.StoreKey]), logger.With(log.ModuleKey, "x/distribution")), app.AuthKeeper, app.BankKeeper, app.StakingKeeper, cometService, authtypes.FeeCollectorName, govModuleAddr) - - app.SlashingKeeper = slashingkeeper.NewKeeper(runtime.NewEnvironment(runtime.NewKVStoreService(keys[slashingtypes.StoreKey]), logger.With(log.ModuleKey, "x/slashing")), - appCodec, legacyAmino, app.StakingKeeper, govModuleAddr, - ) - - app.FeeGrantKeeper = feegrantkeeper.NewKeeper(runtime.NewEnvironment(runtime.NewKVStoreService(keys[feegrant.StoreKey]), logger.With(log.ModuleKey, "x/feegrant")), appCodec, app.AuthKeeper.AddressCodec()) - - // register the staking hooks - // NOTE: stakingKeeper above is passed by reference, so that it will contain these hooks - app.StakingKeeper.SetHooks( - stakingtypes.NewMultiStakingHooks(app.DistrKeeper.Hooks(), app.SlashingKeeper.Hooks()), - ) - - app.CircuitKeeper = circuitkeeper.NewKeeper(runtime.NewEnvironment(runtime.NewKVStoreService(keys[circuittypes.StoreKey]), logger.With(log.ModuleKey, "x/circuit")), appCodec, govModuleAddr, app.AuthKeeper.AddressCodec()) - app.BaseApp.SetCircuitBreaker(&app.CircuitKeeper) - - app.AuthzKeeper = authzkeeper.NewKeeper(runtime.NewEnvironment(runtime.NewKVStoreService(keys[authzkeeper.StoreKey]), logger.With(log.ModuleKey, "x/authz"), runtime.EnvWithMsgRouterService(app.MsgServiceRouter()), runtime.EnvWithQueryRouterService(app.GRPCQueryRouter())), appCodec, signingCtx.AddressCodec()) - - groupConfig := group.DefaultConfig() - /* - Example of group params: - config.MaxExecutionPeriod = "1209600s" // example execution period in seconds - config.MaxMetadataLen = 1000 // example metadata length in bytes - config.MaxProposalTitleLen = 255 // example max title length in characters - config.MaxProposalSummaryLen = 10200 // example max summary length in characters - */ - app.GroupKeeper = groupkeeper.NewKeeper(runtime.NewEnvironment(runtime.NewKVStoreService(keys[group.StoreKey]), logger.With(log.ModuleKey, "x/group"), runtime.EnvWithMsgRouterService(app.MsgServiceRouter()), runtime.EnvWithQueryRouterService(app.GRPCQueryRouter())), appCodec, app.AuthKeeper, groupConfig) - - // get skipUpgradeHeights from the app options - skipUpgradeHeights := map[int64]bool{} - for _, h := range cast.ToIntSlice(appOpts.Get(server.FlagUnsafeSkipUpgrades)) { - skipUpgradeHeights[int64(h)] = true - } - homePath := cast.ToString(appOpts.Get(flags.FlagHome)) - // set the governance module account as the authority for conducting upgrades - app.UpgradeKeeper = upgradekeeper.NewKeeper(runtime.NewEnvironment(runtime.NewKVStoreService(keys[upgradetypes.StoreKey]), logger.With(log.ModuleKey, "x/upgrade"), runtime.EnvWithMsgRouterService(app.MsgServiceRouter()), runtime.EnvWithQueryRouterService(app.GRPCQueryRouter())), skipUpgradeHeights, appCodec, homePath, app.BaseApp, govModuleAddr, app.ConsensusParamsKeeper) - - // Register the proposal types - // Deprecated: Avoid adding new handlers, instead use the new proposal flow - // by granting the governance module the right to execute the message. - // See: https://docs.cosmos.network/main/modules/gov#proposal-messages - govRouter := govv1beta1.NewRouter() - govConfig := govkeeper.DefaultConfig() - /* - Example of setting gov params: - govConfig.MaxMetadataLen = 10000 - */ - govKeeper := govkeeper.NewKeeper(appCodec, runtime.NewEnvironment(runtime.NewKVStoreService(keys[govtypes.StoreKey]), logger.With(log.ModuleKey, "x/gov"), runtime.EnvWithMsgRouterService(app.MsgServiceRouter()), runtime.EnvWithQueryRouterService(app.GRPCQueryRouter())), app.AuthKeeper, app.BankKeeper, app.StakingKeeper, app.PoolKeeper, govConfig, govModuleAddr) - - // Set legacy router for backwards compatibility with gov v1beta1 - govKeeper.SetLegacyRouter(govRouter) - - app.GovKeeper = *govKeeper.SetHooks( - govtypes.NewMultiGovHooks( - // register the governance hooks - ), - ) - - app.NFTKeeper = nftkeeper.NewKeeper(runtime.NewEnvironment(runtime.NewKVStoreService(keys[nftkeeper.StoreKey]), logger.With(log.ModuleKey, "x/nft")), appCodec, app.AuthKeeper, app.BankKeeper) - - // create evidence keeper with router - evidenceKeeper := evidencekeeper.NewKeeper( - appCodec, - runtime.NewEnvironment(runtime.NewKVStoreService(keys[evidencetypes.StoreKey]), logger.With(log.ModuleKey, "x/evidence"), runtime.EnvWithMsgRouterService(app.MsgServiceRouter()), runtime.EnvWithQueryRouterService(app.GRPCQueryRouter())), - app.StakingKeeper, - app.SlashingKeeper, - app.ConsensusParamsKeeper, - app.AuthKeeper.AddressCodec(), - app.StakingKeeper.ConsensusAddressCodec(), - ) - // If evidence needs to be handled for the app, set routes in router here and seal - app.EvidenceKeeper = *evidenceKeeper - - app.EpochsKeeper = epochskeeper.NewKeeper( - runtime.NewEnvironment(runtime.NewKVStoreService(keys[epochstypes.StoreKey]), logger.With(log.ModuleKey, "x/epochs")), - appCodec, - ) - - app.EpochsKeeper.SetHooks( - epochstypes.NewMultiEpochHooks( - // insert epoch hooks receivers here - ), - ) - - /**** Module Options ****/ - - // NOTE: Any module instantiated in the module manager that is later modified - // must be passed by reference here. - app.ModuleManager = module.NewManager( - genutil.NewAppModule(appCodec, app.AuthKeeper, app.StakingKeeper, app, txConfig, genutiltypes.DefaultMessageValidator), - accounts.NewAppModule(appCodec, app.AccountsKeeper), - auth.NewAppModule(appCodec, app.AuthKeeper, app.AccountsKeeper, authsims.RandomGenesisAccounts, nil), - vesting.NewAppModule(app.AuthKeeper, app.BankKeeper), - bank.NewAppModule(appCodec, app.BankKeeper, app.AuthKeeper), - feegrantmodule.NewAppModule(appCodec, app.FeeGrantKeeper, app.interfaceRegistry), - gov.NewAppModule(appCodec, &app.GovKeeper, app.AuthKeeper, app.BankKeeper, app.PoolKeeper), - mint.NewAppModule(appCodec, app.MintKeeper, app.AuthKeeper), - slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AuthKeeper, app.BankKeeper, app.StakingKeeper, app.interfaceRegistry, cometService), - distr.NewAppModule(appCodec, app.DistrKeeper, app.StakingKeeper), - staking.NewAppModule(appCodec, app.StakingKeeper), - upgrade.NewAppModule(app.UpgradeKeeper), - evidence.NewAppModule(appCodec, app.EvidenceKeeper, cometService), - authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.interfaceRegistry), - groupmodule.NewAppModule(appCodec, app.GroupKeeper, app.AuthKeeper, app.BankKeeper, app.interfaceRegistry), - nftmodule.NewAppModule(appCodec, app.NFTKeeper, app.AuthKeeper, app.BankKeeper, app.interfaceRegistry), - consensus.NewAppModule(appCodec, app.ConsensusParamsKeeper), - circuit.NewAppModule(appCodec, app.CircuitKeeper), - protocolpool.NewAppModule(appCodec, app.PoolKeeper, app.AuthKeeper, app.BankKeeper), - epochs.NewAppModule(appCodec, app.EpochsKeeper), - ) - - app.ModuleManager.RegisterLegacyAminoCodec(legacyAmino) - app.ModuleManager.RegisterInterfaces(interfaceRegistry) - - // NOTE: upgrade module is required to be prioritized - app.ModuleManager.SetOrderPreBlockers( - upgradetypes.ModuleName, - ) - // During begin block slashing happens after distr.BeginBlocker so that - // there is nothing left over in the validator fee pool, so as to keep the - // CanWithdrawInvariant invariant. - // NOTE: staking module is required if HistoricalEntries param > 0 - app.ModuleManager.SetOrderBeginBlockers( - minttypes.ModuleName, - distrtypes.ModuleName, - pooltypes.ModuleName, - slashingtypes.ModuleName, - evidencetypes.ModuleName, - stakingtypes.ModuleName, - genutiltypes.ModuleName, - authz.ModuleName, - epochstypes.ModuleName, - ) - app.ModuleManager.SetOrderEndBlockers( - govtypes.ModuleName, - stakingtypes.ModuleName, - genutiltypes.ModuleName, - feegrant.ModuleName, - group.ModuleName, - pooltypes.ModuleName, - ) - - // NOTE: The genutils module must occur after staking so that pools are - // properly initialized with tokens from genesis accounts. - // NOTE: The genutils module must also occur after auth so that it can access the params from auth. - genesisModuleOrder := []string{ - consensustypes.ModuleName, - accounts.ModuleName, - authtypes.ModuleName, - banktypes.ModuleName, - distrtypes.ModuleName, - stakingtypes.ModuleName, - slashingtypes.ModuleName, - govtypes.ModuleName, - minttypes.ModuleName, - genutiltypes.ModuleName, - evidencetypes.ModuleName, - authz.ModuleName, - feegrant.ModuleName, - nft.ModuleName, - group.ModuleName, - upgradetypes.ModuleName, - vestingtypes.ModuleName, - circuittypes.ModuleName, - pooltypes.ModuleName, - epochstypes.ModuleName, - } - app.ModuleManager.SetOrderInitGenesis(genesisModuleOrder...) - app.ModuleManager.SetOrderExportGenesis(genesisModuleOrder...) - - // Uncomment if you want to set a custom migration order here. - // app.ModuleManager.SetOrderMigrations(custom order) - - app.configurator = module.NewConfigurator(app.appCodec, app.MsgServiceRouter(), app.GRPCQueryRouter()) - err = app.ModuleManager.RegisterServices(app.configurator) - if err != nil { - panic(err) - } - - // RegisterUpgradeHandlers is used for registering any on-chain upgrades. - // Make sure it's called after `app.ModuleManager` and `app.configurator` are set. - app.RegisterUpgradeHandlers() - - autocliv1.RegisterQueryServer(app.GRPCQueryRouter(), runtimeservices.NewAutoCLIQueryService(app.ModuleManager.Modules)) - - reflectionSvc, err := runtimeservices.NewReflectionService() - if err != nil { - panic(err) - } - reflectionv1.RegisterReflectionServiceServer(app.GRPCQueryRouter(), reflectionSvc) - - // add test gRPC service for testing gRPC queries in isolation - testdata_pulsar.RegisterQueryServer(app.GRPCQueryRouter(), testdata_pulsar.QueryImpl{}) - - // create the simulation manager and define the order of the modules for deterministic simulations - // - // NOTE: this is not required apps that don't use the simulator for fuzz testing - // transactions - overrideModules := map[string]module.AppModuleSimulation{ - authtypes.ModuleName: auth.NewAppModule(app.appCodec, app.AuthKeeper, app.AccountsKeeper, authsims.RandomGenesisAccounts, nil), - } - app.sm = module.NewSimulationManagerFromAppModules(app.ModuleManager.Modules, overrideModules) - - // create, start, and load the unordered tx manager - utxDataDir := filepath.Join(homePath, "data") - app.UnorderedTxManager = unorderedtx.NewManager(utxDataDir) - app.UnorderedTxManager.Start() - - if err := app.UnorderedTxManager.OnInit(); err != nil { - panic(fmt.Errorf("failed to initialize unordered tx manager: %w", err)) - } - - // register custom snapshot extensions (if any) - if manager := app.SnapshotManager(); manager != nil { - err := manager.RegisterExtensions( - unorderedtx.NewSnapshotter(app.UnorderedTxManager), - ) - if err != nil { - panic(fmt.Errorf("failed to register snapshot extension: %w", err)) - } - } - - app.sm.RegisterStoreDecoders() - - // initialize stores - app.MountKVStores(keys) - - // initialize BaseApp - app.SetInitChainer(app.InitChainer) - app.SetPreBlocker(app.PreBlocker) - app.SetBeginBlocker(app.BeginBlocker) - app.SetEndBlocker(app.EndBlocker) - app.setAnteHandler(txConfig) - - // In v0.46, the SDK introduces _postHandlers_. PostHandlers are like - // antehandlers, but are run _after_ the `runMsgs` execution. They are also - // defined as a chain, and have the same signature as antehandlers. - // - // In baseapp, postHandlers are run in the same store branch as `runMsgs`, - // meaning that both `runMsgs` and `postHandler` state will be committed if - // both are successful, and both will be reverted if any of the two fails. - // - // The SDK exposes a default postHandlers chain - // - // Please note that changing any of the anteHandler or postHandler chain is - // likely to be a state-machine breaking change, which needs a coordinated - // upgrade. - app.setPostHandler() - - // At startup, after all modules have been registered, check that all prot - // annotations are correct. - protoFiles, err := proto.MergedRegistry() - if err != nil { - panic(err) - } - err = msgservice.ValidateProtoAnnotations(protoFiles) - if err != nil { - // Once we switch to using protoreflect-based antehandlers, we might - // want to panic here instead of logging a warning. - fmt.Fprintln(os.Stderr, err.Error()) - } - - if loadLatest { - if err := app.LoadLatestVersion(); err != nil { - panic(fmt.Errorf("error loading last version: %w", err)) - } - } - - return app -} - -func (app *SimApp) setAnteHandler(txConfig client.TxConfig) { - anteHandler, err := NewAnteHandler( - HandlerOptions{ - ante.HandlerOptions{ - Environment: runtime.NewEnvironment(nil, app.logger, runtime.EnvWithMsgRouterService(app.MsgServiceRouter()), runtime.EnvWithQueryRouterService(app.GRPCQueryRouter())), // nil is set as the kvstoreservice to avoid module access - AccountAbstractionKeeper: app.AccountsKeeper, - AccountKeeper: app.AuthKeeper, - BankKeeper: app.BankKeeper, - ConsensusKeeper: app.ConsensusParamsKeeper, - SignModeHandler: txConfig.SignModeHandler(), - FeegrantKeeper: app.FeeGrantKeeper, - SigGasConsumer: ante.DefaultSigVerificationGasConsumer, - UnorderedTxManager: app.UnorderedTxManager, - }, - &app.CircuitKeeper, - }, - ) - if err != nil { - panic(err) - } - - // Set the AnteHandler for the app - app.SetAnteHandler(anteHandler) -} - -func (app *SimApp) setPostHandler() { - postHandler, err := posthandler.NewPostHandler( - posthandler.HandlerOptions{}, - ) - if err != nil { - panic(err) - } - - app.SetPostHandler(postHandler) -} - -// Close closes all necessary application resources. -// It implements servertypes.Application. -func (app *SimApp) Close() error { - if err := app.BaseApp.Close(); err != nil { - return err - } - - return app.UnorderedTxManager.Close() -} - -// Name returns the name of the App -func (app *SimApp) Name() string { return app.BaseApp.Name() } - -// PreBlocker application updates every pre block -func (app *SimApp) PreBlocker(ctx sdk.Context, _ *abci.FinalizeBlockRequest) error { - app.UnorderedTxManager.OnNewBlock(ctx.BlockTime()) - return app.ModuleManager.PreBlock(ctx) -} - -// BeginBlocker application updates every begin block -func (app *SimApp) BeginBlocker(ctx sdk.Context) (sdk.BeginBlock, error) { - return app.ModuleManager.BeginBlock(ctx) -} - -// EndBlocker application updates every end block -func (app *SimApp) EndBlocker(ctx sdk.Context) (sdk.EndBlock, error) { - return app.ModuleManager.EndBlock(ctx) -} - -func (a *SimApp) Configurator() module.Configurator { //nolint:staticcheck // SA1019: Configurator is deprecated but still used in runtime v1. - return a.configurator -} - -// InitChainer application update at chain initialization -func (app *SimApp) InitChainer(ctx sdk.Context, req *abci.InitChainRequest) (*abci.InitChainResponse, error) { - var genesisState GenesisState - err := json.Unmarshal(req.AppStateBytes, &genesisState) - if err != nil { - return nil, err - } - err = app.UpgradeKeeper.SetModuleVersionMap(ctx, app.ModuleManager.GetVersionMap()) - if err != nil { - return nil, err - } - return app.ModuleManager.InitGenesis(ctx, genesisState) -} - -// LoadHeight loads a particular height -func (app *SimApp) LoadHeight(height int64) error { - return app.LoadVersion(height) -} - -// LegacyAmino returns SimApp's amino codec. -// -// NOTE: This is solely to be used for testing purposes as it may be desirable -// for modules to register their own custom testing types. -func (app *SimApp) LegacyAmino() *codec.LegacyAmino { - return app.legacyAmino -} - -// AppCodec returns SimApp's app codec. -// -// NOTE: This is solely to be used for testing purposes as it may be desirable -// for modules to register their own custom testing types. -func (app *SimApp) AppCodec() codec.Codec { - return app.appCodec -} - -// InterfaceRegistry returns SimApp's InterfaceRegistry -func (app *SimApp) InterfaceRegistry() types.InterfaceRegistry { - return app.interfaceRegistry -} - -// TxConfig returns SimApp's TxConfig -func (app *SimApp) TxConfig() client.TxConfig { - return app.txConfig -} - -// AutoCliOpts returns the autocli options for the app. -func (app *SimApp) AutoCliOpts() autocli.AppOptions { - return autocli.AppOptions{ - Modules: app.ModuleManager.Modules, - ModuleOptions: runtimeservices.ExtractAutoCLIOptions(app.ModuleManager.Modules), - } -} - -// DefaultGenesis returns a default genesis from the registered AppModule's. -func (a *SimApp) DefaultGenesis() map[string]json.RawMessage { - return a.ModuleManager.DefaultGenesis() -} - -// GetKey returns the KVStoreKey for the provided store key. -// -// NOTE: This is solely to be used for testing purposes. -func (app *SimApp) GetKey(storeKey string) *storetypes.KVStoreKey { - return app.keys[storeKey] -} - -// GetStoreKeys returns all the stored store keys. -func (app *SimApp) GetStoreKeys() []storetypes.StoreKey { - keys := make([]storetypes.StoreKey, 0, len(app.keys)) - for _, key := range app.keys { - keys = append(keys, key) - } - - return keys -} - -// SimulationManager implements the SimulationApp interface -func (app *SimApp) SimulationManager() *module.SimulationManager { - return app.sm -} - -// RegisterAPIRoutes registers all application module routes with the provided -// API server. -func (app *SimApp) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.APIConfig) { - clientCtx := apiSvr.ClientCtx - // Register new tx routes from grpc-gateway. - authtx.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter) - - // Register new CometBFT queries routes from grpc-gateway. - cmtservice.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter) - - // Register node gRPC service for grpc-gateway. - nodeservice.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter) - - // Register grpc-gateway routes for all modules. - app.ModuleManager.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter) - - // register swagger API from root so that other applications can override easily - if err := server.RegisterSwaggerAPI(apiSvr.ClientCtx, apiSvr.Router, apiConfig.Swagger); err != nil { - panic(err) - } -} - -// RegisterTxService implements the Application.RegisterTxService method. -func (app *SimApp) RegisterTxService(clientCtx client.Context) { - authtx.RegisterTxService(app.BaseApp.GRPCQueryRouter(), clientCtx, app.BaseApp.Simulate, app.interfaceRegistry) -} - -// RegisterTendermintService implements the Application.RegisterTendermintService method. -func (app *SimApp) RegisterTendermintService(clientCtx client.Context) { - cmtApp := server.NewCometABCIWrapper(app) - cmtservice.RegisterTendermintService( - clientCtx, - app.BaseApp.GRPCQueryRouter(), - app.interfaceRegistry, - cmtApp.Query, - ) -} - -func (app *SimApp) RegisterNodeService(clientCtx client.Context, cfg config.Config) { - nodeservice.RegisterNodeService(clientCtx, app.GRPCQueryRouter(), cfg) -} - -// ValidatorKeyProvider returns a function that generates a validator key -// Supported key types are those supported by Comet: ed25519, secp256k1, bls12-381 -func (app *SimApp) ValidatorKeyProvider() runtime.KeyGenF { - return func() (cmtcrypto.PrivKey, error) { - return cmted25519.GenPrivKey(), nil - } -} - -// GetMaccPerms returns a copy of the module account permissions -// -// NOTE: This is solely to be used for testing purposes. -func GetMaccPerms() map[string][]string { - return maps.Clone(maccPerms) -} - -// BlockedAddresses returns all the app's blocked account addresses. -func BlockedAddresses(ac coreaddress.Codec) (map[string]bool, error) { - modAccAddrs := make(map[string]bool) - for acc := range GetMaccPerms() { - addr, err := ac.BytesToString(authtypes.NewModuleAddress(acc)) - if err != nil { - return nil, err - } - modAccAddrs[addr] = true - } - - // allow the following addresses to receive funds - addr, err := ac.BytesToString(authtypes.NewModuleAddress(govtypes.ModuleName)) - if err != nil { - return nil, err - } - delete(modAccAddrs, addr) - - return modAccAddrs, nil -} diff --git a/simapp/app_di.go b/simapp/app_di.go index 6e8f8d4f63ee..90de295e8b7d 100644 --- a/simapp/app_di.go +++ b/simapp/app_di.go @@ -1,5 +1,3 @@ -//go:build !app_v1 - package simapp import ( diff --git a/simapp/go.mod b/simapp/go.mod index 71e1c2d67cca..973d5e993666 100644 --- a/simapp/go.mod +++ b/simapp/go.mod @@ -32,14 +32,14 @@ require ( cosmossdk.io/x/protocolpool v0.0.0-20230925135524-a1bc045b3190 cosmossdk.io/x/slashing v0.0.0-00010101000000-000000000000 cosmossdk.io/x/staking v0.0.0-20240226161501-23359a0b6d91 - cosmossdk.io/x/tx v1.0.0-alpha.1 + cosmossdk.io/x/tx v1.0.0-alpha.1 // indirect cosmossdk.io/x/upgrade v0.0.0-20230613133644-0a778132a60f github.com/cometbft/cometbft v1.0.0-rc2.0.20241127125717-4ce33b646ac9 github.com/cometbft/cometbft/api v1.0.0-rc2 // this version is not used as it is always replaced by the latest Cosmos SDK version github.com/cosmos/cosmos-sdk v0.53.0 github.com/cosmos/gogoproto v1.7.0 - github.com/spf13/cast v1.7.0 + github.com/spf13/cast v1.7.0 // indirect github.com/spf13/cobra v1.8.1 github.com/spf13/pflag v1.0.5 github.com/spf13/viper v1.19.0 diff --git a/simapp/simd/cmd/root.go b/simapp/simd/cmd/root.go deleted file mode 100644 index 7851629e7716..000000000000 --- a/simapp/simd/cmd/root.go +++ /dev/null @@ -1,137 +0,0 @@ -//go:build app_v1 - -package cmd - -import ( - "os" - - "github.com/spf13/cobra" - - coretesting "cosmossdk.io/core/testing" - "cosmossdk.io/log" - "cosmossdk.io/simapp" - "cosmossdk.io/simapp/params" - txsigning "cosmossdk.io/x/tx/signing" - - "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/client/config" - nodeservice "github.com/cosmos/cosmos-sdk/client/grpc/node" - addresscodec "github.com/cosmos/cosmos-sdk/codec/address" - "github.com/cosmos/cosmos-sdk/server" - simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/tx/signing" - "github.com/cosmos/cosmos-sdk/x/auth/tx" - authtxconfig "github.com/cosmos/cosmos-sdk/x/auth/tx/config" - "github.com/cosmos/cosmos-sdk/x/auth/types" -) - -// NewRootCmd creates a new root command for simd. It is called once in the -// main function. -func NewRootCmd() *cobra.Command { - // we "pre"-instantiate the application for getting the injected/configured encoding configuration - // note, this is not necessary when using app wiring, as depinject can be directly used (see root_v2.go) - tempApp := simapp.NewSimApp(log.NewNopLogger(), coretesting.NewMemDB(), nil, true, simtestutil.NewAppOptionsWithFlagHome(simapp.DefaultNodeHome)) - encodingConfig := params.EncodingConfig{ - InterfaceRegistry: tempApp.InterfaceRegistry(), - Codec: tempApp.AppCodec(), - TxConfig: tempApp.TxConfig(), - Amino: tempApp.LegacyAmino(), - } - - initClientCtx := client.Context{}. - WithCodec(encodingConfig.Codec). - WithInterfaceRegistry(encodingConfig.InterfaceRegistry). - WithTxConfig(encodingConfig.TxConfig). - WithLegacyAmino(encodingConfig.Amino). - WithInput(os.Stdin). - WithAccountRetriever(types.AccountRetriever{}). - WithAddressCodec(addresscodec.NewBech32Codec(sdk.GetConfig().GetBech32AccountAddrPrefix())). - WithValidatorAddressCodec(addresscodec.NewBech32Codec(sdk.GetConfig().GetBech32ValidatorAddrPrefix())). - WithConsensusAddressCodec(addresscodec.NewBech32Codec(sdk.GetConfig().GetBech32ConsensusAddrPrefix())). - WithHomeDir(simapp.DefaultNodeHome). - WithViper(""). // uses by default the binary name as prefix - WithAddressPrefix(sdk.GetConfig().GetBech32AccountAddrPrefix()). - WithValidatorPrefix(sdk.GetConfig().GetBech32ValidatorAddrPrefix()) - - rootCmd := &cobra.Command{ - Use: "simd", - Short: "simulation app", - SilenceErrors: true, - PersistentPreRunE: func(cmd *cobra.Command, _ []string) error { - // set the default command outputs - cmd.SetOut(cmd.OutOrStdout()) - cmd.SetErr(cmd.ErrOrStderr()) - - initClientCtx = initClientCtx.WithCmdContext(cmd.Context()) - initClientCtx, err := client.ReadPersistentCommandFlags(initClientCtx, cmd.Flags()) - if err != nil { - return err - } - - customClientTemplate, customClientConfig := initClientConfig() - initClientCtx, err = config.CreateClientConfig(initClientCtx, customClientTemplate, customClientConfig) - if err != nil { - return err - } - - // This needs to go after CreateClientConfig, as that function - // sets the RPC client needed for SIGN_MODE_TEXTUAL. This sign mode - // is only available if the client is online. - if !initClientCtx.Offline { - enabledSignModes := append(tx.DefaultSignModes, signing.SignMode_SIGN_MODE_TEXTUAL) - txConfigOpts := tx.ConfigOptions{ - EnabledSignModes: enabledSignModes, - TextualCoinMetadataQueryFn: authtxconfig.NewGRPCCoinMetadataQueryFn(initClientCtx), - SigningOptions: &txsigning.Options{ - AddressCodec: initClientCtx.InterfaceRegistry.SigningContext().AddressCodec(), - ValidatorAddressCodec: initClientCtx.InterfaceRegistry.SigningContext().ValidatorAddressCodec(), - }, - } - txConfig, err := tx.NewTxConfigWithOptions( - initClientCtx.Codec, - txConfigOpts, - ) - if err != nil { - return err - } - - initClientCtx = initClientCtx.WithTxConfig(txConfig) - } - - if err := client.SetCmdClientContextHandler(initClientCtx, cmd); err != nil { - return err - } - - customAppTemplate, customAppConfig := initAppConfig() - customCMTConfig := initCometBFTConfig() - - return server.InterceptConfigsPreRunHandler(cmd, customAppTemplate, customAppConfig, customCMTConfig) - }, - } - - initRootCmd(rootCmd, tempApp.ModuleManager) - - // autocli opts - customClientTemplate, customClientConfig := initClientConfig() - var err error - initClientCtx, err = config.CreateClientConfig(initClientCtx, customClientTemplate, customClientConfig) - if err != nil { - panic(err) - } - - autoCliOpts := tempApp.AutoCliOpts() - autoCliOpts.AddressCodec = initClientCtx.AddressCodec - autoCliOpts.ValidatorAddressCodec = initClientCtx.ValidatorAddressCodec - autoCliOpts.ConsensusAddressCodec = initClientCtx.ConsensusAddressCodec - autoCliOpts.Cdc = initClientCtx.Codec - - nodeCmds := nodeservice.NewNodeCommands() - autoCliOpts.ModuleOptions[nodeCmds.Name()] = nodeCmds.AutoCLIOptions() - - if err := autoCliOpts.EnhanceRootCommand(rootCmd); err != nil { - panic(err) - } - - return rootCmd -} diff --git a/simapp/simd/cmd/root_di.go b/simapp/simd/cmd/root_di.go index ea6e70f37a99..4d3b2d5774ac 100644 --- a/simapp/simd/cmd/root_di.go +++ b/simapp/simd/cmd/root_di.go @@ -1,5 +1,3 @@ -//go:build !app_v1 - package cmd import ( diff --git a/tests/integration/v2/app.go b/tests/integration/v2/app.go index 8eba29665cf3..72a4873cba6b 100644 --- a/tests/integration/v2/app.go +++ b/tests/integration/v2/app.go @@ -445,6 +445,8 @@ func (a *App) SignCheckDeliver( // It required the context to have the integration context. // a new state is committed if the option WithAutomaticCommit is set in options. func (app *App) RunMsg(t *testing.T, ctx context.Context, handler handler, option ...Option) (resp transaction.Msg, err error) { + t.Helper() + // set options cfg := &RunMsgConfig{} for _, opt := range option { diff --git a/tests/integration/v2/evidence/infraction_test.go b/tests/integration/v2/evidence/infraction_test.go index 16cd31f4e83d..351b2f3ea9be 100644 --- a/tests/integration/v2/evidence/infraction_test.go +++ b/tests/integration/v2/evidence/infraction_test.go @@ -4,7 +4,6 @@ import ( "bytes" "context" "encoding/hex" - "fmt" "testing" "time" @@ -25,7 +24,6 @@ import ( _ "cosmossdk.io/x/evidence" // import as blank for app wiring "cosmossdk.io/x/evidence/exported" "cosmossdk.io/x/evidence/keeper" - evidencetypes "cosmossdk.io/x/evidence/types" minttypes "cosmossdk.io/x/mint/types" _ "cosmossdk.io/x/slashing" // import as blank for app wiring slashingkeeper "cosmossdk.io/x/slashing/keeper" @@ -251,6 +249,7 @@ func TestHandleDoubleSign_TooOld(t *testing.T) { require.NotNil(t, f.consensusKeeper.ParamsStore) require.NoError(t, f.consensusKeeper.ParamsStore.Set(ctx, *simtestutil.DefaultConsensusParams)) cp, err := f.consensusKeeper.ParamsStore.Get(ctx) + require.NoError(t, err) ctx = integration.SetCometInfo(ctx, nci) ctx = integration.SetHeaderInfo(ctx, header.Info{ @@ -412,21 +411,3 @@ func newPubKey(pk string) (res cryptotypes.PubKey) { return pubkey } - -func testEquivocationHandler(_ interface{}) evidencetypes.Handler { - return func(ctx context.Context, e exported.Evidence) error { - if err := e.ValidateBasic(); err != nil { - return err - } - - ee, ok := e.(*evidencetypes.Equivocation) - if !ok { - return fmt.Errorf("unexpected evidence type: %T", e) - } - if ee.Height%2 == 0 { - return fmt.Errorf("unexpected even evidence height: %d", ee.Height) - } - - return nil - } -}