From c6890b387651d161d23212eb75a8db2dd37821a8 Mon Sep 17 00:00:00 2001 From: Leon <156270887+leonz789@users.noreply.github.com> Date: Thu, 25 Apr 2024 17:32:19 +0800 Subject: [PATCH 1/2] fix(testsuite/sims): set all signatures (#20151) Co-authored-by: qinglin89 <316032931@qq.com> --- testutil/sims/tx_helpers.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/testutil/sims/tx_helpers.go b/testutil/sims/tx_helpers.go index 7120b4d672f..24e0ad0365d 100644 --- a/testutil/sims/tx_helpers.go +++ b/testutil/sims/tx_helpers.go @@ -79,10 +79,10 @@ func GenSignedMockTx(r *rand.Rand, txConfig client.TxConfig, msgs []sdk.Msg, fee panic(err) } sigs[i].Data.(*signing.SingleSignatureData).Signature = sig - err = tx.SetSignatures(sigs...) - if err != nil { - panic(err) - } + } + err = tx.SetSignatures(sigs...) + if err != nil { + panic(err) } return tx.GetTx(), nil From b15732a594add9408ced9fe1b66a25f0d207c984 Mon Sep 17 00:00:00 2001 From: Marko Date: Thu, 25 Apr 2024 17:26:43 +0200 Subject: [PATCH 2/2] refactor: migrate to query Consensus Params (#19600) Co-authored-by: Julien Robert Co-authored-by: Facundo Co-authored-by: Facundo Medica <14063057+facundomedica@users.noreply.github.com> Co-authored-by: Matt Kocubinski Co-authored-by: Hieu Vu <72878483+hieuvubk@users.noreply.github.com> --- baseapp/abci_test.go | 2 +- baseapp/abci_utils.go | 6 +-- go.mod | 2 - orm/go.mod | 11 ++++- orm/go.sum | 18 ++++++- orm/model/ormdb/module.go | 4 +- simapp/ante.go | 10 ++-- simapp/app.go | 9 ++-- simapp/app_di.go | 1 + simapp/sim_test.go | 1 + store/db/db_test.go | 9 ---- store/db/rocksdb_test.go | 20 ++++++++ .../auth/keeper/msg_server_test.go | 4 +- .../bank/keeper/deterministic_test.go | 7 ++- .../distribution/keeper/msg_server_test.go | 13 ++++- .../evidence/keeper/infraction_test.go | 12 +++-- tests/integration/example/example_test.go | 5 ++ tests/integration/gov/keeper/keeper_test.go | 5 +- .../slashing/keeper/keeper_test.go | 20 +++++--- .../integration/staking/keeper/common_test.go | 16 ++++-- .../staking/keeper/deterministic_test.go | 6 ++- tests/sims/feegrant/operations_test.go | 2 +- testutil/integration/router.go | 19 ++++++- testutil/sims/app_helpers.go | 4 ++ types/context.go | 2 + x/accounts/defaults/lockup/lockup_test.go | 2 + x/accounts/defaults/lockup/utils_test.go | 1 + x/auth/CHANGELOG.md | 1 + x/auth/ante/ante.go | 6 ++- x/auth/ante/ante_test.go | 1 + x/auth/ante/setup.go | 24 ++++++--- x/auth/ante/setup_test.go | 10 ++-- .../ante/testutil/expected_keepers_mocks.go | 39 +++++++++++++++ x/auth/ante/testutil_test.go | 38 ++++++++++---- x/auth/tx/config/depinject.go | 3 ++ x/evidence/keeper/infraction.go | 15 +++--- x/gov/go.mod | 1 + x/gov/go.sum | 2 - x/gov/keeper/common_test.go | 11 ++++- x/gov/testutil/expected_keepers_mocks.go | 5 +- x/staking/keeper/keeper_test.go | 22 ++++++++- x/staking/keeper/msg_server.go | 15 +++--- x/staking/testutil/expected_keepers_mocks.go | 39 +++++++++++++++ x/upgrade/keeper/abci.go | 10 ++-- x/upgrade/keeper/abci_test.go | 49 ++++++++----------- 45 files changed, 375 insertions(+), 127 deletions(-) create mode 100644 store/db/rocksdb_test.go diff --git a/baseapp/abci_test.go b/baseapp/abci_test.go index 4a369309435..9430a479371 100644 --- a/baseapp/abci_test.go +++ b/baseapp/abci_test.go @@ -1812,7 +1812,7 @@ func TestABCI_PrepareProposal_VoteExtensions(t *testing.T) { return nil, err } - cp := ctx.ConsensusParams() + cp := ctx.ConsensusParams() // nolint:staticcheck // ignore linting error extsEnabled := cp.Abci != nil && req.Height >= cp.Abci.VoteExtensionsEnableHeight && cp.Abci.VoteExtensionsEnableHeight != 0 if extsEnabled { req.Txs = append(req.Txs, []byte("some-tx-that-does-something-from-votes")) diff --git a/baseapp/abci_utils.go b/baseapp/abci_utils.go index e4ae40f7127..dd554ce3ad0 100644 --- a/baseapp/abci_utils.go +++ b/baseapp/abci_utils.go @@ -46,7 +46,7 @@ func ValidateVoteExtensions( extCommit abci.ExtendedCommitInfo, ) error { // Get values from context - cp := ctx.ConsensusParams() + cp := ctx.ConsensusParams() // nolint:staticcheck // ignore linting error currentHeight := ctx.HeaderInfo().Height chainID := ctx.HeaderInfo().ChainID commitInfo := ctx.CometInfo().LastCommit @@ -249,7 +249,7 @@ func (h *DefaultProposalHandler) SetTxSelector(ts TxSelector) { func (h *DefaultProposalHandler) PrepareProposalHandler() sdk.PrepareProposalHandler { return func(ctx sdk.Context, req *abci.RequestPrepareProposal) (*abci.ResponsePrepareProposal, error) { var maxBlockGas uint64 - if b := ctx.ConsensusParams().Block; b != nil { + if b := ctx.ConsensusParams().Block; b != nil { // nolint:staticcheck // ignore linting error maxBlockGas = uint64(b.MaxGas) } @@ -375,7 +375,7 @@ func (h *DefaultProposalHandler) ProcessProposalHandler() sdk.ProcessProposalHan var totalTxGas uint64 var maxBlockGas int64 - if b := ctx.ConsensusParams().Block; b != nil { + if b := ctx.ConsensusParams().Block; b != nil { // nolint:staticcheck // ignore linting error maxBlockGas = b.MaxGas } diff --git a/go.mod b/go.mod index 647134d6214..86a4713f090 100644 --- a/go.mod +++ b/go.mod @@ -187,8 +187,6 @@ replace ( cosmossdk.io/x/staking => ./x/staking ) -replace github.com/cosmos/iavl => github.com/cosmos/iavl v1.0.1 // TODO remove - // Below are the long-lived replace of the Cosmos SDK replace ( // use cosmos fork of keyring diff --git a/orm/go.mod b/orm/go.mod index c2cfea5a28a..22cea9f3568 100644 --- a/orm/go.mod +++ b/orm/go.mod @@ -4,7 +4,7 @@ go 1.21 require ( cosmossdk.io/api v0.7.4 - cosmossdk.io/core v0.11.0 + cosmossdk.io/core v0.12.1-0.20231114100755-569e3ff6a0d7 cosmossdk.io/depinject v1.0.0-alpha.4 cosmossdk.io/errors v1.0.1 github.com/cosmos/cosmos-db v1.0.2 @@ -22,6 +22,7 @@ require ( ) require ( + cosmossdk.io/log v1.3.1 // indirect github.com/DataDog/zstd v1.5.5 // indirect github.com/beorn7/perks v1.0.1 // indirect github.com/bmatcuk/doublestar/v4 v4.6.1 // indirect @@ -47,6 +48,8 @@ require ( github.com/kr/pretty v0.3.1 // indirect github.com/kr/text v0.2.0 // indirect github.com/linxGnu/grocksdb v1.8.14 // indirect + github.com/mattn/go-colorable v0.1.13 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect github.com/onsi/gomega v1.20.0 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect @@ -55,6 +58,7 @@ require ( github.com/prometheus/common v0.53.0 // indirect github.com/prometheus/procfs v0.12.0 // indirect github.com/rogpeppe/go-internal v1.12.0 // indirect + github.com/rs/zerolog v1.32.0 // indirect github.com/spf13/cast v1.6.0 // indirect github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d // indirect golang.org/x/net v0.24.0 // indirect @@ -67,4 +71,7 @@ require ( sigs.k8s.io/yaml v1.4.0 // indirect ) -replace cosmossdk.io/depinject => ../depinject +replace ( + cosmossdk.io/core => ../core + cosmossdk.io/depinject => ../depinject +) diff --git a/orm/go.sum b/orm/go.sum index fc9db78cebb..ab8f24eed47 100644 --- a/orm/go.sum +++ b/orm/go.sum @@ -1,9 +1,9 @@ cosmossdk.io/api v0.7.4 h1:sPo8wKwCty1lht8kgL3J7YL1voJywP3YWuA5JKkBz30= cosmossdk.io/api v0.7.4/go.mod h1:IcxpYS5fMemZGqyYtErK7OqvdM0C8kdW3dq8Q/XIG38= -cosmossdk.io/core v0.11.0 h1:vtIafqUi+1ZNAE/oxLOQQ7Oek2n4S48SWLG8h/+wdbo= -cosmossdk.io/core v0.11.0/go.mod h1:LaTtayWBSoacF5xNzoF8tmLhehqlA9z1SWiPuNC6X1w= cosmossdk.io/errors v1.0.1 h1:bzu+Kcr0kS/1DuPBtUFdWjzLqyUuCiyHjyJB6srBV/0= cosmossdk.io/errors v1.0.1/go.mod h1:MeelVSZThMi4bEakzhhhE/CKqVv3nOJDA25bIqRDu/U= +cosmossdk.io/log v1.3.1 h1:UZx8nWIkfbbNEWusZqzAx3ZGvu54TZacWib3EzUYmGI= +cosmossdk.io/log v1.3.1/go.mod h1:2/dIomt8mKdk6vl3OWJcPk2be3pGOS8OQaLUM/3/tCM= github.com/DataDog/zstd v1.5.5 h1:oWf5W7GtOLgp6bciQYDmhHHjdhYkALu6S/5Ni9ZgSvQ= github.com/DataDog/zstd v1.5.5/go.mod h1:g4AWEaM3yOg3HYfnJ3YIawPnVdXJh9QME85blwSAmyw= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= @@ -29,6 +29,7 @@ github.com/cockroachdb/redact v1.1.5 h1:u1PMllDkdFfPWaNGMyLD1+so+aq3uUItthCFqzwP github.com/cockroachdb/redact v1.1.5/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZZ2lK+dpvRg= github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 h1:zuQyyAKVxetITBuuhv3BI9cMrmStnpT18zmgmTxunpo= github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06/go.mod h1:7nc4anLGjupUW/PeY5qiNYsdNXj7zopG+eqsS7To5IQ= +github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= github.com/cosmos/cosmos-db v1.0.2 h1:hwMjozuY1OlJs/uh6vddqnk9j7VamLv+0DBlbEXbAKs= github.com/cosmos/cosmos-db v1.0.2/go.mod h1:Z8IXcFJ9PqKK6BIsVOB3QXtkKoqUOp1vRvPT39kOXEA= github.com/cosmos/cosmos-proto v1.0.0-beta.5 h1:eNcayDLpip+zVLRLYafhzLvQlSmyab+RC5W7ZfmxJLA= @@ -57,6 +58,7 @@ github.com/getsentry/sentry-go v0.27.0/go.mod h1:lc76E2QywIyW8WuBnwl8Lc4bkmQH4+w github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA= github.com/go-errors/errors v1.4.2/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og= github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= +github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/gofrs/uuid v4.4.0+incompatible h1:3qXRTX8/NbyulANqlc0lchS1gqAVxRgsuW1YrTJupqA= github.com/gofrs/uuid v4.4.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= @@ -100,6 +102,12 @@ github.com/lib/pq v1.10.7 h1:p7ZhMD+KsSRozJr34udlUrhboJwWAgCg34+/ZZNvZZw= github.com/lib/pq v1.10.7/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= github.com/linxGnu/grocksdb v1.8.14 h1:HTgyYalNwBSG/1qCQUIott44wU5b2Y9Kr3z7SK5OfGQ= github.com/linxGnu/grocksdb v1.8.14/go.mod h1:QYiYypR2d4v63Wj1adOOfzglnoII0gLj3PNh4fZkcFA= +github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= +github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= +github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= +github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= +github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE= github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU= @@ -135,6 +143,9 @@ github.com/regen-network/gocuke v1.1.1/go.mod h1:Nl9EbhLmTzdLqb52fr/Fvf8LcoVuTjj github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8= github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4= +github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= +github.com/rs/zerolog v1.32.0 h1:keLypqrlIjaFsbmJOBdB/qvyF8KEtCWHwobLp5l/mQ0= +github.com/rs/zerolog v1.32.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss= github.com/spf13/cast v1.6.0 h1:GEiTHELF+vaR5dhz3VqZfFSzZjYbgeKDpBxQVS4GYJ0= github.com/spf13/cast v1.6.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= @@ -192,7 +203,10 @@ golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o= golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= diff --git a/orm/model/ormdb/module.go b/orm/model/ormdb/module.go index 605e641729a..35d264196a3 100644 --- a/orm/model/ormdb/module.go +++ b/orm/model/ormdb/module.go @@ -39,7 +39,7 @@ type ModuleDB interface { // func NewAppModule(keeper keeper.Keeper) AppModule { // return AppModule{HasGenesis: keeper.GenesisHandler()} // } - GenesisHandler() appmodule.HasGenesis // TODO should be appmodule.HasGenesisAuto with core v1 + GenesisHandler() appmodule.HasGenesisAuto private() } @@ -212,7 +212,7 @@ func (m moduleDB) GetTable(message proto.Message) ormtable.Table { return m.tablesByName[message.ProtoReflect().Descriptor().FullName()] } -func (m moduleDB) GenesisHandler() appmodule.HasGenesis { // TODO should be appmodule.HasGenesisAuto with core v1 +func (m moduleDB) GenesisHandler() appmodule.HasGenesisAuto { return appModuleGenesisWrapper{m} } diff --git a/simapp/ante.go b/simapp/ante.go index 939d1436247..359494d91ff 100644 --- a/simapp/ante.go +++ b/simapp/ante.go @@ -33,13 +33,17 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) { return nil, errors.New("sign mode handler is required for ante builder") } + if options.Environment.RouterService == nil { + return nil, errors.New("router service is required for ante builder") + } + anteDecorators := []sdk.AnteDecorator{ - ante.NewSetUpContextDecorator(), // outermost AnteDecorator. SetUpContext must be called first + ante.NewSetUpContextDecorator(options.Environment), // outermost AnteDecorator. SetUpContext must be called first circuitante.NewCircuitBreakerDecorator(options.CircuitKeeper), ante.NewExtensionOptionsDecorator(options.ExtensionOptionChecker), - ante.NewValidateBasicDecorator(options.AccountKeeper.GetEnvironment()), + ante.NewValidateBasicDecorator(options.Environment), ante.NewTxTimeoutHeightDecorator(), - ante.NewUnorderedTxDecorator(unorderedtx.DefaultMaxUnOrderedTTL, options.TxManager, options.AccountKeeper.GetEnvironment()), + ante.NewUnorderedTxDecorator(unorderedtx.DefaultMaxUnOrderedTTL, options.TxManager, options.Environment), ante.NewValidateMemoDecorator(options.AccountKeeper), ante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper), ante.NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper, options.TxFeeChecker), diff --git a/simapp/app.go b/simapp/app.go index 9bf64c813bd..fcb756cb7ba 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -144,6 +144,7 @@ var ( // capabilities aren't needed for testing. type SimApp struct { *baseapp.BaseApp + logger log.Logger legacyAmino *codec.LegacyAmino appCodec codec.Codec txConfig client.TxConfig @@ -273,6 +274,7 @@ func NewSimApp( app := &SimApp{ BaseApp: bApp, + logger: logger, legacyAmino: legacyAmino, appCodec: appCodec, txConfig: txConfig, @@ -336,7 +338,7 @@ func NewSimApp( app.txConfig = txConfig app.StakingKeeper = stakingkeeper.NewKeeper( - appCodec, runtime.NewEnvironment(runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), logger.With(log.ModuleKey, "x/staking")), app.AuthKeeper, app.BankKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(), signingCtx.ValidatorAddressCodec(), authcodec.NewBech32Codec(sdk.Bech32PrefixConsAddr), + appCodec, runtime.NewEnvironment(runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), logger.With(log.ModuleKey, "x/staking"), runtime.EnvWithRouterService(app.GRPCQueryRouter(), app.MsgServiceRouter())), app.AuthKeeper, app.BankKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(), signingCtx.ValidatorAddressCodec(), authcodec.NewBech32Codec(sdk.Bech32PrefixConsAddr), ) app.MintKeeper = mintkeeper.NewKeeper(appCodec, runtime.NewEnvironment(runtime.NewKVStoreService(keys[minttypes.StoreKey]), logger.With(log.ModuleKey, "x/mint")), app.StakingKeeper, app.AuthKeeper, app.BankKeeper, authtypes.FeeCollectorName, authtypes.NewModuleAddress(govtypes.ModuleName).String()) @@ -378,7 +380,7 @@ func NewSimApp( } 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")), skipUpgradeHeights, appCodec, homePath, app.BaseApp, authtypes.NewModuleAddress(govtypes.ModuleName).String()) + app.UpgradeKeeper = upgradekeeper.NewKeeper(runtime.NewEnvironment(runtime.NewKVStoreService(keys[upgradetypes.StoreKey]), logger.With(log.ModuleKey, "x/upgrade"), runtime.EnvWithRouterService(app.GRPCQueryRouter(), app.MsgServiceRouter())), skipUpgradeHeights, appCodec, homePath, app.BaseApp, authtypes.NewModuleAddress(govtypes.ModuleName).String()) // Register the proposal types // Deprecated: Avoid adding new handlers, instead use the new proposal flow @@ -405,7 +407,7 @@ func NewSimApp( // create evidence keeper with router evidenceKeeper := evidencekeeper.NewKeeper( - appCodec, runtime.NewEnvironment(runtime.NewKVStoreService(keys[evidencetypes.StoreKey]), logger.With(log.ModuleKey, "x/evidence")), app.StakingKeeper, app.SlashingKeeper, app.AuthKeeper.AddressCodec(), + appCodec, runtime.NewEnvironment(runtime.NewKVStoreService(keys[evidencetypes.StoreKey]), logger.With(log.ModuleKey, "x/evidence"), runtime.EnvWithRouterService(app.GRPCQueryRouter(), app.MsgServiceRouter())), app.StakingKeeper, app.SlashingKeeper, app.AuthKeeper.AddressCodec(), ) // If evidence needs to be handled for the app, set routes in router here and seal app.EvidenceKeeper = *evidenceKeeper @@ -596,6 +598,7 @@ func (app *SimApp) setAnteHandler(txConfig client.TxConfig) { anteHandler, err := NewAnteHandler( HandlerOptions{ ante.HandlerOptions{ + Environment: runtime.NewEnvironment(nil, app.logger, runtime.EnvWithRouterService(app.GRPCQueryRouter(), app.MsgServiceRouter())), // nil is set as the kvstoreservice to avoid module access AccountAbstractionKeeper: app.AccountsKeeper, AccountKeeper: app.AuthKeeper, BankKeeper: app.BankKeeper, diff --git a/simapp/app_di.go b/simapp/app_di.go index 997565a4b1d..15869bf755e 100644 --- a/simapp/app_di.go +++ b/simapp/app_di.go @@ -317,6 +317,7 @@ func (app *SimApp) setCustomAnteHandler() { SignModeHandler: app.txConfig.SignModeHandler(), FeegrantKeeper: app.FeeGrantKeeper, SigGasConsumer: ante.DefaultSigVerificationGasConsumer, + Environment: app.AuthKeeper.Environment, }, &app.CircuitBreakerKeeper, app.UnorderedTxManager, diff --git a/simapp/sim_test.go b/simapp/sim_test.go index c26545e579f..781a649d629 100644 --- a/simapp/sim_test.go +++ b/simapp/sim_test.go @@ -261,6 +261,7 @@ func TestAppSimulationAfterImport(t *testing.T) { } func setupSimulationApp(t *testing.T, msg string) (simtypes.Config, dbm.DB, simtestutil.AppOptionsMap, *SimApp) { + t.Helper() config := simcli.NewConfigFromFlags() config.ChainID = SimAppChainID diff --git a/store/db/db_test.go b/store/db/db_test.go index 39ef0403d74..cad62a42644 100644 --- a/store/db/db_test.go +++ b/store/db/db_test.go @@ -106,15 +106,6 @@ func TestPebbleDBSuite(t *testing.T) { }) } -func TestRocksDBSuite(t *testing.T) { - db, err := NewRocksDB("test", t.TempDir()) - require.NoError(t, err) - - suite.Run(t, &DBTestSuite{ - db: db, - }) -} - func TestGoLevelDBSuite(t *testing.T) { db, err := NewGoLevelDB("test", t.TempDir(), nil) require.NoError(t, err) diff --git a/store/db/rocksdb_test.go b/store/db/rocksdb_test.go new file mode 100644 index 00000000000..75147a56855 --- /dev/null +++ b/store/db/rocksdb_test.go @@ -0,0 +1,20 @@ +//go:build rocksdb +// +build rocksdb + +package db + +import ( + "testing" + + "github.com/stretchr/testify/require" + "github.com/stretchr/testify/suite" +) + +func TestRocksDBSuite(t *testing.T) { + db, err := NewRocksDB("test", t.TempDir()) + require.NoError(t, err) + + suite.Run(t, &DBTestSuite{ + db: db, + }) +} diff --git a/tests/integration/auth/keeper/msg_server_test.go b/tests/integration/auth/keeper/msg_server_test.go index ff2f4c89cbe..1078d85040a 100644 --- a/tests/integration/auth/keeper/msg_server_test.go +++ b/tests/integration/auth/keeper/msg_server_test.go @@ -75,9 +75,7 @@ func initFixture(t *testing.T) *fixture { newCtx := sdk.NewContext(cms, true, logger) router := baseapp.NewMsgServiceRouter() - router.SetInterfaceRegistry(cdc.InterfaceRegistry()) queryRouter := baseapp.NewGRPCQueryRouter() - queryRouter.SetInterfaceRegistry(cdc.InterfaceRegistry()) handler := directHandler{} account := baseaccount.NewAccount("base", signing.NewHandlerMap(handler)) @@ -128,7 +126,7 @@ func initFixture(t *testing.T) *fixture { accounts.ModuleName: accountsModule, authtypes.ModuleName: authModule, banktypes.ModuleName: bankModule, - }) + }, router, queryRouter) authtypes.RegisterInterfaces(cdc.InterfaceRegistry()) banktypes.RegisterInterfaces(cdc.InterfaceRegistry()) diff --git a/tests/integration/bank/keeper/deterministic_test.go b/tests/integration/bank/keeper/deterministic_test.go index 2f126d5ab38..7bbec8fe11a 100644 --- a/tests/integration/bank/keeper/deterministic_test.go +++ b/tests/integration/bank/keeper/deterministic_test.go @@ -24,6 +24,7 @@ import ( minttypes "cosmossdk.io/x/mint/types" _ "cosmossdk.io/x/staking" + "github.com/cosmos/cosmos-sdk/baseapp" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/runtime" @@ -99,7 +100,6 @@ func initDeterministicFixture(t *testing.T) *deterministicFixture { accountKeeper.GetAuthority(): false, } bankKeeper := keeper.NewBaseKeeper( - runtime.NewEnvironment(runtime.NewKVStoreService(keys[banktypes.StoreKey]), log.NewNopLogger()), cdc, accountKeeper, @@ -116,7 +116,10 @@ func initDeterministicFixture(t *testing.T) *deterministicFixture { map[string]appmodule.AppModule{ authtypes.ModuleName: authModule, banktypes.ModuleName: bankModule, - }) + }, + baseapp.NewMsgServiceRouter(), + baseapp.NewGRPCQueryRouter(), + ) sdkCtx := sdk.UnwrapSDKContext(integrationApp.Context()) diff --git a/tests/integration/distribution/keeper/msg_server_test.go b/tests/integration/distribution/keeper/msg_server_test.go index cd2d89333f0..281ade5b9c4 100644 --- a/tests/integration/distribution/keeper/msg_server_test.go +++ b/tests/integration/distribution/keeper/msg_server_test.go @@ -33,6 +33,7 @@ import ( stakingtestutil "cosmossdk.io/x/staking/testutil" stakingtypes "cosmossdk.io/x/staking/types" + "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" @@ -40,6 +41,7 @@ import ( "github.com/cosmos/cosmos-sdk/testutil/integration" sdk "github.com/cosmos/cosmos-sdk/types" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" + consensustypes "github.com/cosmos/cosmos-sdk/x/consensus/types" ) var ( @@ -68,6 +70,7 @@ func initFixture(t *testing.T) *fixture { t.Helper() keys := storetypes.NewKVStoreKeys( authtypes.StoreKey, banktypes.StoreKey, distrtypes.StoreKey, pooltypes.StoreKey, stakingtypes.StoreKey, + consensustypes.StoreKey, ) encodingCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, auth.AppModule{}, bank.AppModule{}) cdc := encodingCfg.Codec @@ -113,7 +116,10 @@ func initFixture(t *testing.T) *fixture { authority.String(), ) - stakingKeeper := stakingkeeper.NewKeeper(cdc, runtime.NewEnvironment(runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), log.NewNopLogger()), accountKeeper, bankKeeper, authority.String(), addresscodec.NewBech32Codec(sdk.Bech32PrefixValAddr), addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr)) + msgRouter := baseapp.NewMsgServiceRouter() + grpcRouter := baseapp.NewGRPCQueryRouter() + + stakingKeeper := stakingkeeper.NewKeeper(cdc, runtime.NewEnvironment(runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), log.NewNopLogger(), runtime.EnvWithRouterService(grpcRouter, msgRouter)), accountKeeper, bankKeeper, authority.String(), addresscodec.NewBech32Codec(sdk.Bech32PrefixValAddr), addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr)) require.NoError(t, stakingKeeper.Params.Set(newCtx, stakingtypes.DefaultParams())) poolKeeper := poolkeeper.NewKeeper(cdc, runtime.NewEnvironment(runtime.NewKVStoreService(keys[pooltypes.StoreKey]), log.NewNopLogger()), accountKeeper, bankKeeper, stakingKeeper, authority.String()) @@ -156,7 +162,10 @@ func initFixture(t *testing.T) *fixture { stakingtypes.ModuleName: stakingModule, distrtypes.ModuleName: distrModule, pooltypes.ModuleName: poolModule, - }) + }, + msgRouter, + grpcRouter, + ) sdkCtx := sdk.UnwrapSDKContext(integrationApp.Context()) diff --git a/tests/integration/evidence/keeper/infraction_test.go b/tests/integration/evidence/keeper/infraction_test.go index 62b3a6362d7..4e40b006faf 100644 --- a/tests/integration/evidence/keeper/infraction_test.go +++ b/tests/integration/evidence/keeper/infraction_test.go @@ -41,6 +41,7 @@ import ( stakingtestutil "cosmossdk.io/x/staking/testutil" stakingtypes "cosmossdk.io/x/staking/types" + "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" @@ -92,6 +93,8 @@ func initFixture(tb testing.TB) *fixture { ) encodingCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, auth.AppModule{}, evidence.AppModule{}) cdc := encodingCfg.Codec + msgRouter := baseapp.NewMsgServiceRouter() + grpcQueryRouter := baseapp.NewGRPCQueryRouter() logger := log.NewTestLogger(tb) cms := integration.CreateMultiStore(keys, logger) @@ -133,13 +136,13 @@ func initFixture(tb testing.TB) *fixture { authority.String(), ) - stakingKeeper := stakingkeeper.NewKeeper(cdc, runtime.NewEnvironment(runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), log.NewNopLogger()), accountKeeper, bankKeeper, authority.String(), addresscodec.NewBech32Codec(sdk.Bech32PrefixValAddr), addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr)) + stakingKeeper := stakingkeeper.NewKeeper(cdc, runtime.NewEnvironment(runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), log.NewNopLogger(), runtime.EnvWithRouterService(grpcQueryRouter, msgRouter)), accountKeeper, bankKeeper, authority.String(), addresscodec.NewBech32Codec(sdk.Bech32PrefixValAddr), addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr)) slashingKeeper := slashingkeeper.NewKeeper(runtime.NewEnvironment(runtime.NewKVStoreService(keys[slashingtypes.StoreKey]), log.NewNopLogger()), cdc, codec.NewLegacyAmino(), stakingKeeper, authority.String()) stakingKeeper.SetHooks(stakingtypes.NewMultiStakingHooks(slashingKeeper.Hooks())) - evidenceKeeper := keeper.NewKeeper(cdc, runtime.NewEnvironment(runtime.NewKVStoreService(keys[evidencetypes.StoreKey]), log.NewNopLogger()), stakingKeeper, slashingKeeper, addresscodec.NewBech32Codec(sdk.Bech32PrefixAccAddr)) + evidenceKeeper := keeper.NewKeeper(cdc, runtime.NewEnvironment(runtime.NewKVStoreService(keys[evidencetypes.StoreKey]), log.NewNopLogger(), runtime.EnvWithRouterService(grpcQueryRouter, msgRouter)), stakingKeeper, slashingKeeper, addresscodec.NewBech32Codec(sdk.Bech32PrefixAccAddr)) router := evidencetypes.NewRouter() router = router.AddRoute(evidencetypes.RouteEquivocation, testEquivocationHandler(evidenceKeeper)) evidenceKeeper.SetRouter(router) @@ -159,7 +162,10 @@ func initFixture(tb testing.TB) *fixture { stakingtypes.ModuleName: stakingModule, slashingtypes.ModuleName: slashingModule, evidencetypes.ModuleName: evidenceModule, - }) + }, + msgRouter, + grpcQueryRouter, + ) sdkCtx := sdk.UnwrapSDKContext(integrationApp.Context()) diff --git a/tests/integration/example/example_test.go b/tests/integration/example/example_test.go index bc87760e114..06325060365 100644 --- a/tests/integration/example/example_test.go +++ b/tests/integration/example/example_test.go @@ -20,6 +20,7 @@ import ( mintkeeper "cosmossdk.io/x/mint/keeper" minttypes "cosmossdk.io/x/mint/types" + "github.com/cosmos/cosmos-sdk/baseapp" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/runtime" @@ -80,6 +81,8 @@ func Example() { authtypes.ModuleName: authModule, minttypes.ModuleName: mintModule, }, + baseapp.NewMsgServiceRouter(), + baseapp.NewGRPCQueryRouter(), ) // register the message and query servers @@ -170,6 +173,8 @@ func Example_oneModule() { map[string]appmodule.AppModule{ authtypes.ModuleName: authModule, }, + baseapp.NewMsgServiceRouter(), + baseapp.NewGRPCQueryRouter(), ) // register the message and query servers diff --git a/tests/integration/gov/keeper/keeper_test.go b/tests/integration/gov/keeper/keeper_test.go index 55d3b2154c3..c29953cf139 100644 --- a/tests/integration/gov/keeper/keeper_test.go +++ b/tests/integration/gov/keeper/keeper_test.go @@ -145,7 +145,10 @@ func initFixture(tb testing.TB) *fixture { banktypes.ModuleName: bankModule, stakingtypes.ModuleName: stakingModule, types.ModuleName: govModule, - }) + }, + baseapp.NewMsgServiceRouter(), + baseapp.NewGRPCQueryRouter(), + ) sdkCtx := sdk.UnwrapSDKContext(integrationApp.Context()) diff --git a/tests/integration/slashing/keeper/keeper_test.go b/tests/integration/slashing/keeper/keeper_test.go index a9c325ab348..294dbbccb8e 100644 --- a/tests/integration/slashing/keeper/keeper_test.go +++ b/tests/integration/slashing/keeper/keeper_test.go @@ -30,6 +30,7 @@ import ( stakingtestutil "cosmossdk.io/x/staking/testutil" stakingtypes "cosmossdk.io/x/staking/types" + "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" @@ -38,6 +39,7 @@ import ( simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" + consensustypes "github.com/cosmos/cosmos-sdk/x/consensus/types" ) type fixture struct { @@ -57,7 +59,7 @@ type fixture struct { func initFixture(tb testing.TB) *fixture { tb.Helper() keys := storetypes.NewKVStoreKeys( - authtypes.StoreKey, banktypes.StoreKey, slashingtypes.StoreKey, stakingtypes.StoreKey, + authtypes.StoreKey, banktypes.StoreKey, slashingtypes.StoreKey, stakingtypes.StoreKey, consensustypes.StoreKey, ) encodingCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, auth.AppModule{}) cdc := encodingCfg.Codec @@ -75,12 +77,15 @@ func initFixture(tb testing.TB) *fixture { stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking}, } + msgRouter := baseapp.NewMsgServiceRouter() + queryRouter := baseapp.NewGRPCQueryRouter() + // gomock initializations ctrl := gomock.NewController(&testing.T{}) acctsModKeeper := authtestutil.NewMockAccountsModKeeper(ctrl) accountKeeper := authkeeper.NewAccountKeeper( - runtime.NewEnvironment(runtime.NewKVStoreService(keys[authtypes.StoreKey]), log.NewNopLogger()), + runtime.NewEnvironment(runtime.NewKVStoreService(keys[authtypes.StoreKey]), log.NewNopLogger(), runtime.EnvWithRouterService(queryRouter, msgRouter)), cdc, authtypes.ProtoBaseAccount, acctsModKeeper, @@ -94,16 +99,16 @@ func initFixture(tb testing.TB) *fixture { accountKeeper.GetAuthority(): false, } bankKeeper := bankkeeper.NewBaseKeeper( - runtime.NewEnvironment(runtime.NewKVStoreService(keys[banktypes.StoreKey]), log.NewNopLogger()), + runtime.NewEnvironment(runtime.NewKVStoreService(keys[banktypes.StoreKey]), log.NewNopLogger(), runtime.EnvWithRouterService(queryRouter, msgRouter)), cdc, accountKeeper, blockedAddresses, authority.String(), ) - stakingKeeper := stakingkeeper.NewKeeper(cdc, runtime.NewEnvironment(runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), log.NewNopLogger()), accountKeeper, bankKeeper, authority.String(), addresscodec.NewBech32Codec(sdk.Bech32PrefixValAddr), addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr)) + stakingKeeper := stakingkeeper.NewKeeper(cdc, runtime.NewEnvironment(runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), log.NewNopLogger(), runtime.EnvWithRouterService(queryRouter, msgRouter)), accountKeeper, bankKeeper, authority.String(), addresscodec.NewBech32Codec(sdk.Bech32PrefixValAddr), addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr)) - slashingKeeper := slashingkeeper.NewKeeper(runtime.NewEnvironment(runtime.NewKVStoreService(keys[slashingtypes.StoreKey]), log.NewNopLogger()), cdc, &codec.LegacyAmino{}, stakingKeeper, authority.String()) + slashingKeeper := slashingkeeper.NewKeeper(runtime.NewEnvironment(runtime.NewKVStoreService(keys[slashingtypes.StoreKey]), log.NewNopLogger(), runtime.EnvWithRouterService(queryRouter, msgRouter)), cdc, &codec.LegacyAmino{}, stakingKeeper, authority.String()) bankModule := bank.NewAppModule(cdc, bankKeeper, accountKeeper) stakingModule := staking.NewAppModule(cdc, stakingKeeper, accountKeeper, bankKeeper) @@ -116,7 +121,10 @@ func initFixture(tb testing.TB) *fixture { banktypes.ModuleName: bankModule, stakingtypes.ModuleName: stakingModule, slashingtypes.ModuleName: slashingModule, - }) + }, + msgRouter, + queryRouter, + ) sdkCtx := sdk.UnwrapSDKContext(integrationApp.Context()) diff --git a/tests/integration/staking/keeper/common_test.go b/tests/integration/staking/keeper/common_test.go index 35b9f630096..1ff2b47a13b 100644 --- a/tests/integration/staking/keeper/common_test.go +++ b/tests/integration/staking/keeper/common_test.go @@ -26,6 +26,7 @@ import ( "cosmossdk.io/x/staking/testutil" "cosmossdk.io/x/staking/types" + "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" @@ -34,6 +35,7 @@ import ( simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" + consensustypes "github.com/cosmos/cosmos-sdk/x/consensus/types" ) var PKs = simtestutil.CreateTestPubKeys(500) @@ -104,11 +106,14 @@ func createValidators(t *testing.T, f *fixture, powers []int64) ([]sdk.AccAddres func initFixture(tb testing.TB) *fixture { tb.Helper() keys := storetypes.NewKVStoreKeys( - authtypes.StoreKey, banktypes.StoreKey, types.StoreKey, + authtypes.StoreKey, banktypes.StoreKey, types.StoreKey, consensustypes.StoreKey, ) encodingCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, auth.AppModule{}, staking.AppModule{}) cdc := encodingCfg.Codec + msgRouter := baseapp.NewMsgServiceRouter() + queryRouter := baseapp.NewGRPCQueryRouter() + logger := log.NewTestLogger(tb) cms := integration.CreateMultiStore(keys, logger) @@ -129,7 +134,7 @@ func initFixture(tb testing.TB) *fixture { acctsModKeeper := authtestutil.NewMockAccountsModKeeper(ctrl) accountKeeper := authkeeper.NewAccountKeeper( - runtime.NewEnvironment(runtime.NewKVStoreService(keys[authtypes.StoreKey]), log.NewNopLogger()), + runtime.NewEnvironment(runtime.NewKVStoreService(keys[authtypes.StoreKey]), log.NewNopLogger(), runtime.EnvWithRouterService(queryRouter, msgRouter)), cdc, authtypes.ProtoBaseAccount, acctsModKeeper, @@ -150,7 +155,7 @@ func initFixture(tb testing.TB) *fixture { authority.String(), ) - stakingKeeper := stakingkeeper.NewKeeper(cdc, runtime.NewEnvironment(runtime.NewKVStoreService(keys[types.StoreKey]), log.NewNopLogger()), accountKeeper, bankKeeper, authority.String(), addresscodec.NewBech32Codec(sdk.Bech32PrefixValAddr), addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr)) + stakingKeeper := stakingkeeper.NewKeeper(cdc, runtime.NewEnvironment(runtime.NewKVStoreService(keys[types.StoreKey]), log.NewNopLogger(), runtime.EnvWithRouterService(queryRouter, msgRouter)), accountKeeper, bankKeeper, authority.String(), addresscodec.NewBech32Codec(sdk.Bech32PrefixValAddr), addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr)) authModule := auth.NewAppModule(cdc, accountKeeper, acctsModKeeper, authsims.RandomGenesisAccounts) bankModule := bank.NewAppModule(cdc, bankKeeper, accountKeeper) @@ -163,7 +168,10 @@ func initFixture(tb testing.TB) *fixture { authtypes.ModuleName: authModule, banktypes.ModuleName: bankModule, types.ModuleName: stakingModule, - }) + }, + msgRouter, + queryRouter, + ) sdkCtx := sdk.UnwrapSDKContext(integrationApp.Context()) diff --git a/tests/integration/staking/keeper/deterministic_test.go b/tests/integration/staking/keeper/deterministic_test.go index 12182e992d6..b8fe56f48ee 100644 --- a/tests/integration/staking/keeper/deterministic_test.go +++ b/tests/integration/staking/keeper/deterministic_test.go @@ -27,6 +27,7 @@ import ( stakingkeeper "cosmossdk.io/x/staking/keeper" stakingtypes "cosmossdk.io/x/staking/types" + "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" @@ -127,7 +128,10 @@ func initDeterministicFixture(t *testing.T) *deterministicFixture { authtypes.ModuleName: authModule, banktypes.ModuleName: bankModule, stakingtypes.ModuleName: stakingModule, - }) + }, + baseapp.NewMsgServiceRouter(), + baseapp.NewGRPCQueryRouter(), + ) ctx := integrationApp.Context() diff --git a/tests/sims/feegrant/operations_test.go b/tests/sims/feegrant/operations_test.go index 21ef34e3aa5..9da29e67b53 100644 --- a/tests/sims/feegrant/operations_test.go +++ b/tests/sims/feegrant/operations_test.go @@ -199,7 +199,7 @@ func (suite *SimTestSuite) TestSimulateMsgRevokeAllowance() { require.NoError(err) // execute operation - op := simulation.SimulateMsgRevokeAllowance(codec.NewProtoCodec(suite.interfaceRegistry), suite.txConfig, suite.accountKeeper, suite.bankKeeper, suite.feegrantKeeper, codecaddress.NewBech32Codec("cosmos")) + op := simulation.SimulateMsgRevokeAllowance(codec.NewProtoCodec(suite.interfaceRegistry), suite.txConfig, suite.accountKeeper, suite.bankKeeper, suite.feegrantKeeper) operationMsg, futureOperations, err := op(r, app.BaseApp, ctx, accounts, "") require.NoError(err) diff --git a/testutil/integration/router.go b/testutil/integration/router.go index 9bf25657cff..94262363726 100644 --- a/testutil/integration/router.go +++ b/testutil/integration/router.go @@ -50,6 +50,8 @@ func NewIntegrationApp( addressCodec address.Codec, validatorCodec address.Codec, modules map[string]appmodule.AppModule, + msgRouter *baseapp.MsgServiceRouter, + grpcRouter *baseapp.GRPCQueryRouter, ) *App { db := dbm.NewMemDB() @@ -80,14 +82,27 @@ func NewIntegrationApp( return moduleManager.EndBlock(sdkCtx) }) - msgRouter := baseapp.NewMsgServiceRouter() msgRouter.SetInterfaceRegistry(interfaceRegistry) bApp.SetMsgServiceRouter(msgRouter) + grpcRouter.SetInterfaceRegistry(interfaceRegistry) + bApp.SetGRPCQueryRouter(grpcRouter) if keys[consensusparamtypes.StoreKey] != nil { // set baseApp param store - consensusParamsKeeper := consensusparamkeeper.NewKeeper(appCodec, runtime.NewEnvironment(runtime.NewKVStoreService(keys[consensusparamtypes.StoreKey]), log.NewNopLogger(), runtime.EnvWithRouterService(baseapp.NewGRPCQueryRouter(), msgRouter)), authtypes.NewModuleAddress("gov").String()) + consensusParamsKeeper := consensusparamkeeper.NewKeeper(appCodec, runtime.NewEnvironment(runtime.NewKVStoreService(keys[consensusparamtypes.StoreKey]), log.NewNopLogger(), runtime.EnvWithRouterService(grpcRouter, msgRouter)), authtypes.NewModuleAddress("gov").String()) bApp.SetParamStore(consensusParamsKeeper.ParamsStore) + consensusparamtypes.RegisterQueryServer(grpcRouter, consensusParamsKeeper) + + _, err := consensusParamsKeeper.SetParams(sdkCtx, &consensusparamtypes.ConsensusMsgParams{ + Version: simtestutil.DefaultConsensusParams.Version, + Block: simtestutil.DefaultConsensusParams.Block, + Evidence: simtestutil.DefaultConsensusParams.Evidence, + Validator: simtestutil.DefaultConsensusParams.Validator, + Abci: simtestutil.DefaultConsensusParams.Abci, + }) + if err != nil { + panic(fmt.Errorf("failed to set consensus params: %w", err)) + } if err := bApp.LoadLatestVersion(); err != nil { panic(fmt.Errorf("failed to load application version from store: %w", err)) diff --git a/testutil/sims/app_helpers.go b/testutil/sims/app_helpers.go index ee240ad057f..d7c118a4ee9 100644 --- a/testutil/sims/app_helpers.go +++ b/testutil/sims/app_helpers.go @@ -34,6 +34,9 @@ const DefaultGenTxGas = 10000000 // DefaultConsensusParams defines the default CometBFT consensus params used in // SimApp testing. var DefaultConsensusParams = &cmtproto.ConsensusParams{ + Version: &cmtproto.VersionParams{ + App: 1, + }, Block: &cmtproto.BlockParams{ MaxBytes: 200000, MaxGas: 100_000_000, @@ -46,6 +49,7 @@ var DefaultConsensusParams = &cmtproto.ConsensusParams{ Validator: &cmtproto.ValidatorParams{ PubKeyTypes: []string{ cmttypes.ABCIPubKeyTypeEd25519, + cmttypes.ABCIPubKeyTypeSecp256k1, }, }, } diff --git a/types/context.go b/types/context.go index 0ebee5f132c..2212301e163 100644 --- a/types/context.go +++ b/types/context.go @@ -102,6 +102,8 @@ func (c Context) HeaderHash() []byte { return hash } +// Deprecated: getting consensus params from the context is deprecated and will be removed after 0.51 +// Querying the consensus module for the parameters is required in server/v2 func (c Context) ConsensusParams() cmtproto.ConsensusParams { return c.consParams } diff --git a/x/accounts/defaults/lockup/lockup_test.go b/x/accounts/defaults/lockup/lockup_test.go index 6d34540a85a..25477bc9c54 100644 --- a/x/accounts/defaults/lockup/lockup_test.go +++ b/x/accounts/defaults/lockup/lockup_test.go @@ -16,6 +16,7 @@ import ( ) func setup(t *testing.T, ctx context.Context, ss store.KVStoreService) *BaseLockup { + t.Helper() deps := makeMockDependencies(ss) owner := "owner" @@ -52,6 +53,7 @@ func TestInitLockupAccount(t *testing.T) { } for _, test := range testcases { + test := test _, err := baseLockup.Init(ctx, &test.msg) if test.expErr != nil { require.Equal(t, test.expErr, err) diff --git a/x/accounts/defaults/lockup/utils_test.go b/x/accounts/defaults/lockup/utils_test.go index 32912d32052..23702b051a7 100644 --- a/x/accounts/defaults/lockup/utils_test.go +++ b/x/accounts/defaults/lockup/utils_test.go @@ -53,6 +53,7 @@ func (a addressCodec) StringToBytes(text string) ([]byte, error) { return []byte func (a addressCodec) BytesToString(bz []byte) (string, error) { return string(bz), nil } func newMockContext(t *testing.T) (context.Context, store.KVStoreService) { + t.Helper() return accountstd.NewMockContext( 0, []byte("lockup_account"), []byte("sender"), TestFunds, func(ctx context.Context, sender []byte, msg, msgResp ProtoMsg) error { return nil diff --git a/x/auth/CHANGELOG.md b/x/auth/CHANGELOG.md index 1e8fa2a5bdf..2892a63d798 100644 --- a/x/auth/CHANGELOG.md +++ b/x/auth/CHANGELOG.md @@ -50,6 +50,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * [#19363](https://github.com/cosmos/cosmos-sdk/pull/19363) Remove `IterateAccounts` and `GetAllAccounts` methods from the AccountKeeper interface and Keeper. * [#19290](https://github.com/cosmos/cosmos-sdk/issues/19290) Pass `appmodule.Environment` to NewKeeper instead of passing individual services. * [#19535](https://github.com/cosmos/cosmos-sdk/pull/19535) Remove vesting account creation when the chain is running. The accounts module is required for creating vesting accounts on a running chain. +* [#19600](https://github.com/cosmos/cosmos-sdk/pull/19600) add a consensus query method to the consensus module in order for modules to query consensus for the consensus params. ### Consensus Breaking Changes diff --git a/x/auth/ante/ante.go b/x/auth/ante/ante.go index 7f823eef343..1e5f85b132a 100644 --- a/x/auth/ante/ante.go +++ b/x/auth/ante/ante.go @@ -1,6 +1,7 @@ package ante import ( + "cosmossdk.io/core/appmodule" errorsmod "cosmossdk.io/errors" storetypes "cosmossdk.io/store/types" "cosmossdk.io/x/auth/types" @@ -13,6 +14,7 @@ import ( // HandlerOptions are the options required for constructing a default SDK AnteHandler. type HandlerOptions struct { + Environment appmodule.Environment AccountKeeper AccountKeeper AccountAbstractionKeeper AccountAbstractionKeeper BankKeeper types.BankKeeper @@ -40,9 +42,9 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) { } anteDecorators := []sdk.AnteDecorator{ - NewSetUpContextDecorator(), // outermost AnteDecorator. SetUpContext must be called first + NewSetUpContextDecorator(options.Environment), // outermost AnteDecorator. SetUpContext must be called first NewExtensionOptionsDecorator(options.ExtensionOptionChecker), - NewValidateBasicDecorator(options.AccountKeeper.GetEnvironment()), + NewValidateBasicDecorator(options.Environment), NewTxTimeoutHeightDecorator(), NewValidateMemoDecorator(options.AccountKeeper), NewConsumeGasForTxSizeDecorator(options.AccountKeeper), diff --git a/x/auth/ante/ante_test.go b/x/auth/ante/ante_test.go index 5c26213f59b..7377638550a 100644 --- a/x/auth/ante/ante_test.go +++ b/x/auth/ante/ante_test.go @@ -1275,6 +1275,7 @@ func TestCustomSignatureVerificationGasConsumer(t *testing.T) { return errorsmod.Wrapf(sdkerrors.ErrInvalidPubKey, "unrecognized public key type: %T", pubkey) } }, + Environment: suite.env, }, ) require.NoError(t, err) diff --git a/x/auth/ante/setup.go b/x/auth/ante/setup.go index 66e69fb7b8b..cd2636d01f0 100644 --- a/x/auth/ante/setup.go +++ b/x/auth/ante/setup.go @@ -3,11 +3,13 @@ package ante import ( "fmt" + "cosmossdk.io/core/appmodule" errorsmod "cosmossdk.io/errors" storetypes "cosmossdk.io/store/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + consensusv1 "github.com/cosmos/cosmos-sdk/x/consensus/types" ) // GasTx defines a Tx with a GetGas() method which is needed to use SetUpContextDecorator @@ -21,10 +23,14 @@ type GasTx interface { // on gas provided and gas used. // CONTRACT: Must be first decorator in the chain // CONTRACT: Tx must implement GasTx interface -type SetUpContextDecorator struct{} +type SetUpContextDecorator struct { + env appmodule.Environment +} -func NewSetUpContextDecorator() SetUpContextDecorator { - return SetUpContextDecorator{} +func NewSetUpContextDecorator(env appmodule.Environment) SetUpContextDecorator { + return SetUpContextDecorator{ + env: env, + } } func (sud SetUpContextDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, _ bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) { @@ -39,11 +45,17 @@ func (sud SetUpContextDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, _ bool, newCtx = SetGasMeter(ctx, gasTx.GetGas()) - if cp := ctx.ConsensusParams(); cp.Block != nil { + // TODO: possibly cache the result of this query for other antehandlers to use + var res consensusv1.QueryParamsResponse + if err := sud.env.RouterService.QueryRouterService().InvokeTyped(ctx, &consensusv1.QueryParamsRequest{}, &res); err != nil { + return newCtx, err + } + + if res.Params.Block != nil { // If there exists a maximum block gas limit, we must ensure that the tx // does not exceed it. - if cp.Block.MaxGas > 0 && gasTx.GetGas() > uint64(cp.Block.MaxGas) { - return newCtx, errorsmod.Wrapf(sdkerrors.ErrInvalidGasLimit, "tx gas limit %d exceeds block max gas %d", gasTx.GetGas(), cp.Block.MaxGas) + if res.Params.Block.MaxGas > 0 && gasTx.GetGas() > uint64(res.Params.Block.MaxGas) { + return newCtx, errorsmod.Wrapf(sdkerrors.ErrInvalidGasLimit, "tx gas limit %d exceeds block max gas %d", gasTx.GetGas(), res.Params.Block.MaxGas) } } diff --git a/x/auth/ante/setup_test.go b/x/auth/ante/setup_test.go index 6f36e69a6be..3051c6b8f20 100644 --- a/x/auth/ante/setup_test.go +++ b/x/auth/ante/setup_test.go @@ -28,19 +28,19 @@ func TestSetupDecorator_BlockMaxGas(t *testing.T) { feeAmount := testdata.NewTestFeeAmount() require.NoError(t, suite.txBuilder.SetMsgs(msg)) suite.txBuilder.SetFeeAmount(feeAmount) - suite.txBuilder.SetGasLimit(101) + suite.txBuilder.SetGasLimit(10000000000) privs, accNums, accSeqs := []cryptotypes.PrivKey{priv1}, []uint64{0}, []uint64{0} tx, err := suite.CreateTestTx(suite.ctx, privs, accNums, accSeqs, suite.ctx.ChainID(), signing.SignMode_SIGN_MODE_DIRECT) require.NoError(t, err) - sud := ante.NewSetUpContextDecorator() + sud := ante.NewSetUpContextDecorator(suite.env) antehandler := sdk.ChainAnteDecorators(sud) suite.ctx = suite.ctx. WithBlockHeight(1). WithGasMeter(storetypes.NewGasMeter(0)). - WithConsensusParams(cmtproto.ConsensusParams{ + WithConsensusParams(cmtproto.ConsensusParams{ // TODO: This is being ignored Block: &cmtproto.BlockParams{ MaxGas: 100, }, @@ -69,7 +69,7 @@ func TestSetup(t *testing.T) { tx, err := suite.CreateTestTx(suite.ctx, privs, accNums, accSeqs, suite.ctx.ChainID(), signing.SignMode_SIGN_MODE_DIRECT) require.NoError(t, err) - sud := ante.NewSetUpContextDecorator() + sud := ante.NewSetUpContextDecorator(suite.env) antehandler := sdk.ChainAnteDecorators(sud) // Set height to non-zero value for GasMeter to be set @@ -104,7 +104,7 @@ func TestRecoverPanic(t *testing.T) { tx, err := suite.CreateTestTx(suite.ctx, privs, accNums, accSeqs, suite.ctx.ChainID(), signing.SignMode_SIGN_MODE_DIRECT) require.NoError(t, err) - sud := ante.NewSetUpContextDecorator() + sud := ante.NewSetUpContextDecorator(suite.env) antehandler := sdk.ChainAnteDecorators(sud, OutOfGasDecorator{}) // Set height to non-zero value for GasMeter to be set diff --git a/x/auth/ante/testutil/expected_keepers_mocks.go b/x/auth/ante/testutil/expected_keepers_mocks.go index d2a37f5c86a..4cbe4a09b41 100644 --- a/x/auth/ante/testutil/expected_keepers_mocks.go +++ b/x/auth/ante/testutil/expected_keepers_mocks.go @@ -12,6 +12,7 @@ import ( appmodule "cosmossdk.io/core/appmodule" types "cosmossdk.io/x/auth/types" types0 "github.com/cosmos/cosmos-sdk/types" + types1 "github.com/cosmos/cosmos-sdk/x/consensus/types" gomock "github.com/golang/mock/gomock" ) @@ -170,3 +171,41 @@ func (mr *MockFeegrantKeeperMockRecorder) UseGrantedFees(ctx, granter, grantee, mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UseGrantedFees", reflect.TypeOf((*MockFeegrantKeeper)(nil).UseGrantedFees), ctx, granter, grantee, fee, msgs) } + +// MockConsensusKeeper is a mock of ConsensusKeeper interface. +type MockConsensusKeeper struct { + ctrl *gomock.Controller + recorder *MockConsensusKeeperMockRecorder +} + +// MockConsensusKeeperMockRecorder is the mock recorder for MockConsensusKeeper. +type MockConsensusKeeperMockRecorder struct { + mock *MockConsensusKeeper +} + +// NewMockConsensusKeeper creates a new mock instance. +func NewMockConsensusKeeper(ctrl *gomock.Controller) *MockConsensusKeeper { + mock := &MockConsensusKeeper{ctrl: ctrl} + mock.recorder = &MockConsensusKeeperMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockConsensusKeeper) EXPECT() *MockConsensusKeeperMockRecorder { + return m.recorder +} + +// Params mocks base method. +func (m *MockConsensusKeeper) Params(arg0 context.Context, arg1 *types1.QueryParamsRequest) (*types1.QueryParamsResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Params", arg0, arg1) + ret0, _ := ret[0].(*types1.QueryParamsResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Params indicates an expected call of Params. +func (mr *MockConsensusKeeperMockRecorder) Params(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Params", reflect.TypeOf((*MockConsensusKeeper)(nil).Params), arg0, arg1) +} diff --git a/x/auth/ante/testutil_test.go b/x/auth/ante/testutil_test.go index d002ecb7704..ce2f76f5087 100644 --- a/x/auth/ante/testutil_test.go +++ b/x/auth/ante/testutil_test.go @@ -11,6 +11,7 @@ import ( // ref: https://github.com/cosmos/cosmos-sdk/issues/14647 _ "cosmossdk.io/api/cosmos/bank/v1beta1" _ "cosmossdk.io/api/cosmos/crypto/secp256k1" + "cosmossdk.io/core/appmodule" "cosmossdk.io/log" storetypes "cosmossdk.io/store/types" "cosmossdk.io/x/auth" @@ -23,6 +24,7 @@ import ( txtestutil "cosmossdk.io/x/auth/tx/testutil" "cosmossdk.io/x/auth/types" + "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/tx" codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" @@ -30,11 +32,13 @@ import ( "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil" clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" + simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" "github.com/cosmos/cosmos-sdk/testutil/testdata" _ "github.com/cosmos/cosmos-sdk/testutil/testdata/testpb" sdk "github.com/cosmos/cosmos-sdk/types" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" "github.com/cosmos/cosmos-sdk/types/tx/signing" + consensustypes "github.com/cosmos/cosmos-sdk/x/consensus/types" ) // TestAccount represents an account used in the tests in x/auth/ante. @@ -45,16 +49,18 @@ type TestAccount struct { // AnteTestSuite is a test suite to be used with ante handler tests. type AnteTestSuite struct { - anteHandler sdk.AnteHandler - ctx sdk.Context - clientCtx client.Context - txBuilder client.TxBuilder - accountKeeper keeper.AccountKeeper - bankKeeper *authtestutil.MockBankKeeper - acctsModKeeper *authtestutil.MockAccountsModKeeper - txBankKeeper *txtestutil.MockBankKeeper - feeGrantKeeper *antetestutil.MockFeegrantKeeper - encCfg moduletestutil.TestEncodingConfig + env appmodule.Environment + anteHandler sdk.AnteHandler + ctx sdk.Context + clientCtx client.Context + txBuilder client.TxBuilder + accountKeeper keeper.AccountKeeper + bankKeeper *authtestutil.MockBankKeeper + consensusKeeper *antetestutil.MockConsensusKeeper + acctsModKeeper *authtestutil.MockAccountsModKeeper + txBankKeeper *txtestutil.MockBankKeeper + feeGrantKeeper *antetestutil.MockFeegrantKeeper + encCfg moduletestutil.TestEncodingConfig } // SetupTest setups a new test, with new app, context, and anteHandler. @@ -82,6 +88,17 @@ func SetupTestSuite(t *testing.T, isCheckTx bool) *AnteTestSuite { "random": {"random"}, } + msgRouter := baseapp.NewMsgServiceRouter() + grpcQueryRouter := baseapp.NewGRPCQueryRouter() + grpcQueryRouter.SetInterfaceRegistry(suite.encCfg.InterfaceRegistry) + + suite.consensusKeeper = antetestutil.NewMockConsensusKeeper(ctrl) + suite.consensusKeeper.EXPECT().Params(gomock.Any(), gomock.Any()).Return(&consensustypes.QueryParamsResponse{ + Params: simtestutil.DefaultConsensusParams, + }, nil).AnyTimes() + consensustypes.RegisterQueryServer(grpcQueryRouter, suite.consensusKeeper) + + suite.env = runtime.NewEnvironment(runtime.NewKVStoreService(key), log.NewNopLogger(), runtime.EnvWithRouterService(grpcQueryRouter, msgRouter)) suite.accountKeeper = keeper.NewAccountKeeper( runtime.NewEnvironment(runtime.NewKVStoreService(key), log.NewNopLogger()), suite.encCfg.Codec, types.ProtoBaseAccount, suite.acctsModKeeper, maccPerms, authcodec.NewBech32Codec("cosmos"), sdk.Bech32MainPrefix, types.NewModuleAddress("gov").String(), @@ -105,6 +122,7 @@ func SetupTestSuite(t *testing.T, isCheckTx bool) *AnteTestSuite { FeegrantKeeper: suite.feeGrantKeeper, SignModeHandler: suite.encCfg.TxConfig.SignModeHandler(), SigGasConsumer: ante.DefaultSigVerificationGasConsumer, + Environment: suite.env, }, ) diff --git a/x/auth/tx/config/depinject.go b/x/auth/tx/config/depinject.go index 47009c706e1..82988b09d82 100644 --- a/x/auth/tx/config/depinject.go +++ b/x/auth/tx/config/depinject.go @@ -13,6 +13,7 @@ import ( bankv1beta1 "cosmossdk.io/api/cosmos/bank/v1beta1" txconfigv1 "cosmossdk.io/api/cosmos/tx/config/v1" "cosmossdk.io/core/address" + "cosmossdk.io/core/appmodule" "cosmossdk.io/depinject" "cosmossdk.io/depinject/appconfig" "cosmossdk.io/x/auth/ante" @@ -45,6 +46,7 @@ type ModuleInputs struct { ValidatorAddressCodec address.ValidatorAddressCodec Codec codec.Codec ProtoFileResolver txsigning.ProtoFileResolver + Environment appmodule.Environment // BankKeeper is the expected bank keeper to be passed to AnteHandlers BankKeeper authtypes.BankKeeper `optional:"true"` MetadataBankKeeper BankKeeper `optional:"true"` @@ -152,6 +154,7 @@ func newAnteHandler(txConfig client.TxConfig, in ModuleInputs) (sdk.AnteHandler, SignModeHandler: txConfig.SignModeHandler(), FeegrantKeeper: in.FeeGrantKeeper, SigGasConsumer: ante.DefaultSigVerificationGasConsumer, + Environment: in.Environment, }, ) if err != nil { diff --git a/x/evidence/keeper/infraction.go b/x/evidence/keeper/infraction.go index 4c0fe688a04..5f5772c86d7 100644 --- a/x/evidence/keeper/infraction.go +++ b/x/evidence/keeper/infraction.go @@ -8,6 +8,7 @@ import ( "cosmossdk.io/x/evidence/types" sdk "github.com/cosmos/cosmos-sdk/types" + consensusv1 "github.com/cosmos/cosmos-sdk/x/consensus/types" ) // HandleEquivocationEvidence implements an equivocation evidence handler. Assuming the @@ -72,17 +73,19 @@ func (k Keeper) handleEquivocationEvidence(ctx context.Context, evidence *types. // Reject evidence if the double-sign is too old. Evidence is considered stale // if the difference in time and number of blocks is greater than the allowed // parameters defined. - sdkCtx := sdk.UnwrapSDKContext(ctx) - cp := sdkCtx.ConsensusParams() // TODO: remove in favor of querying consensus module - if cp.Evidence != nil { - if ageDuration > cp.Evidence.MaxAgeDuration && ageBlocks > cp.Evidence.MaxAgeNumBlocks { + var res consensusv1.QueryParamsResponse + if err := k.RouterService.QueryRouterService().InvokeTyped(ctx, &consensusv1.QueryParamsRequest{}, &res); err != nil { + return fmt.Errorf("failed to query consensus params: %w", err) + } + if res.Params.Evidence != nil { + if ageDuration > res.Params.Evidence.MaxAgeDuration && ageBlocks > res.Params.Evidence.MaxAgeNumBlocks { k.Logger.Info( "ignored equivocation; evidence too old", "validator", consAddr, "infraction_height", infractionHeight, - "max_age_num_blocks", cp.Evidence.MaxAgeNumBlocks, + "max_age_num_blocks", res.Params.Evidence.MaxAgeNumBlocks, "infraction_time", infractionTime, - "max_age_duration", cp.Evidence.MaxAgeDuration, + "max_age_duration", res.Params.Evidence.MaxAgeDuration, ) return nil } diff --git a/x/gov/go.mod b/x/gov/go.mod index 0bda106cd24..870a0067a0b 100644 --- a/x/gov/go.mod +++ b/x/gov/go.mod @@ -176,5 +176,6 @@ replace ( cosmossdk.io/x/accounts => ../accounts cosmossdk.io/x/auth => ../auth cosmossdk.io/x/bank => ../bank + cosmossdk.io/x/protocolpool => ../protocolpool cosmossdk.io/x/staking => ../staking ) diff --git a/x/gov/go.sum b/x/gov/go.sum index 9ecd09297c5..2f52b4e0000 100644 --- a/x/gov/go.sum +++ b/x/gov/go.sum @@ -15,8 +15,6 @@ cosmossdk.io/store v1.0.2 h1:lSg5BTvJBHUDwswNNyeh4K/CbqiHER73VU4nDNb8uk0= cosmossdk.io/store v1.0.2/go.mod h1:EFtENTqVTuWwitGW1VwaBct+yDagk7oG/axBMPH+FXs= cosmossdk.io/x/accounts/defaults/lockup v0.0.0-20240417181816-5e7aae0db1f5 h1:eb0kcGyaYHSS0do7+MIWg7UKlskSH01biRNENbm/zDA= cosmossdk.io/x/accounts/defaults/lockup v0.0.0-20240417181816-5e7aae0db1f5/go.mod h1:drzY4oVisyWvSgpsM7ccQ7IX3efMuVIvd9Eij1Gm/6o= -cosmossdk.io/x/protocolpool v0.0.0-20230925135524-a1bc045b3190 h1:XQJj9Dv9Gtze0l2TF79BU5lkP6MkUveTUuKICmxoz+o= -cosmossdk.io/x/protocolpool v0.0.0-20230925135524-a1bc045b3190/go.mod h1:7WUGupOvmlHJoIMBz1JbObQxeo6/TDiuDBxmtod8HRg= cosmossdk.io/x/tx v0.13.3 h1:Ha4mNaHmxBc6RMun9aKuqul8yHiL78EKJQ8g23Zf73g= cosmossdk.io/x/tx v0.13.3/go.mod h1:I8xaHv0rhUdIvIdptKIqzYy27+n2+zBVaxO6fscFhys= filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= diff --git a/x/gov/keeper/common_test.go b/x/gov/keeper/common_test.go index c8eb206c0d7..fced8554ffe 100644 --- a/x/gov/keeper/common_test.go +++ b/x/gov/keeper/common_test.go @@ -43,7 +43,7 @@ var ( // See: https://github.com/cosmos/cosmos-sdk/blob/0e34478eb7420b69869ed50f129fc274a97a9b06/x/mint/types/keys.go#L13 const ( mintModuleName = "mint" - protocolModuleName = "protocol-pool" + protocolModuleName = "protocolpool" ) // getTestProposal creates and returns a test proposal message. @@ -77,7 +77,14 @@ type mocks struct { } func mockAccountKeeperExpectations(ctx sdk.Context, m mocks) { - m.acctKeeper.EXPECT().GetModuleAddress(types.ModuleName).Return(govAcct).AnyTimes() + m.acctKeeper.EXPECT().GetModuleAddress(types.ModuleName).DoAndReturn(func(name string) sdk.AccAddress { + if name == types.ModuleName { + return govAcct + } else if name == protocolModuleName { + return poolAcct + } + panic(fmt.Sprintf("unexpected module name: %s", name)) + }).AnyTimes() m.acctKeeper.EXPECT().GetModuleAddress(protocolModuleName).Return(poolAcct).AnyTimes() m.acctKeeper.EXPECT().GetModuleAccount(gomock.Any(), types.ModuleName).Return(authtypes.NewEmptyModuleAccount(types.ModuleName)).AnyTimes() m.acctKeeper.EXPECT().AddressCodec().Return(address.NewBech32Codec("cosmos")).AnyTimes() diff --git a/x/gov/testutil/expected_keepers_mocks.go b/x/gov/testutil/expected_keepers_mocks.go index 3784d76377c..ce5ec75f8f5 100644 --- a/x/gov/testutil/expected_keepers_mocks.go +++ b/x/gov/testutil/expected_keepers_mocks.go @@ -346,11 +346,12 @@ func (mr *MockBankKeeperMockRecorder) DenomsMetadata(arg0, arg1 interface{}) *go } // ExportGenesis mocks base method. -func (m *MockBankKeeper) ExportGenesis(arg0 context.Context) *types.GenesisState { +func (m *MockBankKeeper) ExportGenesis(arg0 context.Context) (*types.GenesisState, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "ExportGenesis", arg0) ret0, _ := ret[0].(*types.GenesisState) - return ret0 + ret1, _ := ret[1].(error) + return ret0, ret1 } // ExportGenesis indicates an expected call of ExportGenesis. diff --git a/x/staking/keeper/keeper_test.go b/x/staking/keeper/keeper_test.go index 4039aa0c3ab..0c75f5c28b0 100644 --- a/x/staking/keeper/keeper_test.go +++ b/x/staking/keeper/keeper_test.go @@ -29,6 +29,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" addresstypes "github.com/cosmos/cosmos-sdk/types/address" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" + consensustypes "github.com/cosmos/cosmos-sdk/x/consensus/types" ) var ( @@ -41,6 +42,7 @@ type KeeperTestSuite struct { suite.Suite ctx sdk.Context + baseApp *baseapp.BaseApp stakingKeeper *stakingkeeper.Keeper bankKeeper *stakingtestutil.MockBankKeeper accountKeeper *stakingtestutil.MockAccountKeeper @@ -55,20 +57,37 @@ func (s *KeeperTestSuite) SetupTest() { key := storetypes.NewKVStoreKey(stakingtypes.StoreKey) s.key = key storeService := runtime.NewKVStoreService(key) - env := runtime.NewEnvironment(storeService, log.NewNopLogger()) testCtx := testutil.DefaultContextWithDB(s.T(), key, storetypes.NewTransientStoreKey("transient_test")) s.key = key ctx := testCtx.Ctx.WithHeaderInfo(header.Info{Time: time.Now()}) encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}) s.cdc = encCfg.Codec + s.baseApp = baseapp.NewBaseApp( + "staking", + log.NewNopLogger(), + testCtx.DB, + encCfg.TxConfig.TxDecoder(), + ) + s.baseApp.SetCMS(testCtx.CMS) + s.baseApp.SetInterfaceRegistry(encCfg.InterfaceRegistry) + ctrl := gomock.NewController(s.T()) accountKeeper := stakingtestutil.NewMockAccountKeeper(ctrl) accountKeeper.EXPECT().GetModuleAddress(stakingtypes.BondedPoolName).Return(bondedAcc.GetAddress()) accountKeeper.EXPECT().GetModuleAddress(stakingtypes.NotBondedPoolName).Return(notBondedAcc.GetAddress()) accountKeeper.EXPECT().AddressCodec().Return(address.NewBech32Codec("cosmos")).AnyTimes() + // create consensus keeper + ck := stakingtestutil.NewMockConsensusKeeper(ctrl) + ck.EXPECT().Params(gomock.Any(), gomock.Any()).Return(&consensustypes.QueryParamsResponse{ + Params: simtestutil.DefaultConsensusParams, + }, nil).AnyTimes() + queryHelper := baseapp.NewQueryServerTestHelper(ctx, encCfg.InterfaceRegistry) + consensustypes.RegisterQueryServer(queryHelper, ck) + bankKeeper := stakingtestutil.NewMockBankKeeper(ctrl) + env := runtime.NewEnvironment(storeService, log.NewNopLogger(), runtime.EnvWithRouterService(queryHelper.GRPCQueryRouter, s.baseApp.MsgServiceRouter())) authority, err := accountKeeper.AddressCodec().BytesToString(authtypes.NewModuleAddress(stakingtypes.GovModuleName)) s.Require().NoError(err) keeper := stakingkeeper.NewKeeper( @@ -88,7 +107,6 @@ func (s *KeeperTestSuite) SetupTest() { s.accountKeeper = accountKeeper stakingtypes.RegisterInterfaces(encCfg.InterfaceRegistry) - queryHelper := baseapp.NewQueryServerTestHelper(ctx, encCfg.InterfaceRegistry) stakingtypes.RegisterQueryServer(queryHelper, stakingkeeper.Querier{Keeper: keeper}) s.queryClient = stakingtypes.NewQueryClient(queryHelper) s.msgServer = stakingkeeper.NewMsgServerImpl(keeper) diff --git a/x/staking/keeper/msg_server.go b/x/staking/keeper/msg_server.go index 53b2dc2ecb5..10e19e2e84e 100644 --- a/x/staking/keeper/msg_server.go +++ b/x/staking/keeper/msg_server.go @@ -23,6 +23,7 @@ import ( "github.com/cosmos/cosmos-sdk/telemetry" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + consensusv1 "github.com/cosmos/cosmos-sdk/x/consensus/types" ) type msgServer struct { @@ -67,14 +68,16 @@ func (k msgServer) CreateValidator(ctx context.Context, msg *types.MsgCreateVali return nil, errorsmod.Wrapf(sdkerrors.ErrInvalidType, "Expecting cryptotypes.PubKey, got %T", msg.Pubkey.GetCachedValue()) } - sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: remove this - cp := sdkCtx.ConsensusParams() - if cp.Validator != nil { + res := consensusv1.QueryParamsResponse{} + if err := k.RouterService.QueryRouterService().InvokeTyped(ctx, &consensusv1.QueryParamsRequest{}, &res); err != nil { + return nil, errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "failed to query consensus params: %s", err) + } + if res.Params.Validator != nil { pkType := pk.Type() - if !slices.Contains(cp.Validator.PubKeyTypes, pkType) { + if !slices.Contains(res.Params.Validator.PubKeyTypes, pkType) { return nil, errorsmod.Wrapf( types.ErrValidatorPubKeyTypeNotSupported, - "got: %s, expected: %s", pk.Type(), cp.Validator.PubKeyTypes, + "got: %s, expected: %s", pk.Type(), res.Params.Validator.PubKeyTypes, ) } @@ -112,7 +115,7 @@ func (k msgServer) CreateValidator(ctx context.Context, msg *types.MsgCreateVali commission := types.NewCommissionWithTime( msg.Commission.Rate, msg.Commission.MaxRate, - msg.Commission.MaxChangeRate, sdkCtx.HeaderInfo().Time, + msg.Commission.MaxChangeRate, k.HeaderService.HeaderInfo(ctx).Time, ) validator, err = validator.SetInitialCommission(commission) diff --git a/x/staking/testutil/expected_keepers_mocks.go b/x/staking/testutil/expected_keepers_mocks.go index f1f4cd652f1..b3f5867f169 100644 --- a/x/staking/testutil/expected_keepers_mocks.go +++ b/x/staking/testutil/expected_keepers_mocks.go @@ -15,6 +15,7 @@ import ( crypto "github.com/cometbft/cometbft/proto/tendermint/crypto" types0 "github.com/cosmos/cosmos-sdk/crypto/types" types1 "github.com/cosmos/cosmos-sdk/types" + types2 "github.com/cosmos/cosmos-sdk/x/consensus/types" gomock "github.com/golang/mock/gomock" ) @@ -727,3 +728,41 @@ func (mr *MockStakingHooksMockRecorder) BeforeValidatorSlashed(ctx, valAddr, fra mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BeforeValidatorSlashed", reflect.TypeOf((*MockStakingHooks)(nil).BeforeValidatorSlashed), ctx, valAddr, fraction) } + +// MockConsensusKeeper is a mock of ConsensusKeeper interface. +type MockConsensusKeeper struct { + ctrl *gomock.Controller + recorder *MockConsensusKeeperMockRecorder +} + +// MockConsensusKeeperMockRecorder is the mock recorder for MockConsensusKeeper. +type MockConsensusKeeperMockRecorder struct { + mock *MockConsensusKeeper +} + +// NewMockConsensusKeeper creates a new mock instance. +func NewMockConsensusKeeper(ctrl *gomock.Controller) *MockConsensusKeeper { + mock := &MockConsensusKeeper{ctrl: ctrl} + mock.recorder = &MockConsensusKeeperMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockConsensusKeeper) EXPECT() *MockConsensusKeeperMockRecorder { + return m.recorder +} + +// Params mocks base method. +func (m *MockConsensusKeeper) Params(arg0 context.Context, arg1 *types2.QueryParamsRequest) (*types2.QueryParamsResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Params", arg0, arg1) + ret0, _ := ret[0].(*types2.QueryParamsResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Params indicates an expected call of Params. +func (mr *MockConsensusKeeperMockRecorder) Params(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Params", reflect.TypeOf((*MockConsensusKeeper)(nil).Params), arg0, arg1) +} diff --git a/x/upgrade/keeper/abci.go b/x/upgrade/keeper/abci.go index 033df51057d..d1042d54427 100644 --- a/x/upgrade/keeper/abci.go +++ b/x/upgrade/keeper/abci.go @@ -10,6 +10,7 @@ import ( "github.com/cosmos/cosmos-sdk/telemetry" sdk "github.com/cosmos/cosmos-sdk/types" + consensusv1 "github.com/cosmos/cosmos-sdk/x/consensus/types" ) // PreBlocker will check if there is a scheduled plan and if it is ready to be executed. @@ -47,9 +48,12 @@ func (k Keeper) PreBlocker(ctx context.Context) error { if lastAppliedPlan != "" && !k.HasHandler(lastAppliedPlan) { var appVersion uint64 - cp := sdkCtx.ConsensusParams() - if cp.Version != nil { - appVersion = cp.Version.App + var res consensusv1.QueryParamsResponse + if err := k.RouterService.QueryRouterService().InvokeTyped(ctx, &consensusv1.QueryParamsRequest{}, &res); err != nil { + return errors.New("failed to query consensus params") + } + if res.Params.Version != nil { + appVersion = res.Params.Version.App } return fmt.Errorf("wrong app version %d, upgrade handler is missing for %s upgrade plan", appVersion, lastAppliedPlan) diff --git a/x/upgrade/keeper/abci_test.go b/x/upgrade/keeper/abci_test.go index 66c10f3cbd4..8b3c7849deb 100644 --- a/x/upgrade/keeper/abci_test.go +++ b/x/upgrade/keeper/abci_test.go @@ -38,6 +38,9 @@ type TestSuite struct { ctx sdk.Context baseApp *baseapp.BaseApp encCfg moduletestutil.TestEncodingConfig + + key storetypes.StoreKey + env appmodule.Environment } func (s *TestSuite) VerifyDoUpgrade(t *testing.T) { @@ -111,13 +114,13 @@ func (s *TestSuite) VerifySet(t *testing.T, skipUpgradeHeights map[int64]bool) { func setupTest(t *testing.T, height int64, skip map[int64]bool) *TestSuite { t.Helper() - s := TestSuite{} - s.encCfg = moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, upgrade.AppModule{}) key := storetypes.NewKVStoreKey(types.StoreKey) - storeService := runtime.NewKVStoreService(key) - env := runtime.NewEnvironment(storeService, log.NewNopLogger()) - testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) + s := TestSuite{ + key: key, + } + s.encCfg = moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, upgrade.AppModule{}) + testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) s.baseApp = baseapp.NewBaseApp( "upgrade", log.NewNopLogger(), @@ -125,12 +128,15 @@ func setupTest(t *testing.T, height int64, skip map[int64]bool) *TestSuite { s.encCfg.TxConfig.TxDecoder(), ) + storeService := runtime.NewKVStoreService(key) + s.env = runtime.NewEnvironment(storeService, log.NewNopLogger(), runtime.EnvWithRouterService(s.baseApp.GRPCQueryRouter(), s.baseApp.MsgServiceRouter())) + s.baseApp.SetParamStore(¶mStore{params: cmtproto.ConsensusParams{Version: &cmtproto.VersionParams{App: 1}}}) authority, err := addresscodec.NewBech32Codec("cosmos").BytesToString(authtypes.NewModuleAddress(govModuleName)) require.NoError(t, err) - s.keeper = keeper.NewKeeper(env, skip, s.encCfg.Codec, t.TempDir(), s.baseApp, authority) + s.keeper = keeper.NewKeeper(s.env, skip, s.encCfg.Codec, t.TempDir(), s.baseApp, authority) s.ctx = testCtx.Ctx.WithHeaderInfo(header.Info{Time: time.Now(), Height: height}) @@ -457,38 +463,23 @@ func TestBinaryVersion(t *testing.T) { } func TestDowngradeVerification(t *testing.T) { - // could not use setupTest() here, because we have to use the same key - // for the two keepers. - encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, upgrade.AppModule{}) - key := storetypes.NewKVStoreKey(types.StoreKey) - storeService := runtime.NewKVStoreService(key) - env := runtime.NewEnvironment(storeService, log.NewNopLogger()) - testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) - ctx := testCtx.Ctx.WithHeaderInfo(header.Info{Time: time.Now(), Height: 10}) - - skip := map[int64]bool{} - - authority, err := addresscodec.NewBech32Codec("cosmos").BytesToString(authtypes.NewModuleAddress(govModuleName)) - require.NoError(t, err) - - k := keeper.NewKeeper(env, skip, encCfg.Codec, t.TempDir(), nil, authority) - m := upgrade.NewAppModule(k) + s := setupTest(t, 10, map[int64]bool{}) // submit a plan. planName := "downgrade" - err = k.ScheduleUpgrade(ctx, types.Plan{Name: planName, Height: ctx.HeaderInfo().Height + 1}) + err := s.keeper.ScheduleUpgrade(s.ctx, types.Plan{Name: planName, Height: s.ctx.HeaderInfo().Height + 1}) require.NoError(t, err) - ctx = ctx.WithHeaderInfo(header.Info{Height: ctx.HeaderInfo().Height + 1}) + s.ctx = s.ctx.WithHeaderInfo(header.Info{Height: s.ctx.HeaderInfo().Height + 1}) // set the handler. - k.SetUpgradeHandler(planName, func(_ context.Context, _ types.Plan, vm module.VersionMap) (module.VersionMap, error) { + s.keeper.SetUpgradeHandler(planName, func(_ context.Context, _ types.Plan, vm module.VersionMap) (module.VersionMap, error) { return vm, nil }) // successful upgrade. - err = m.PreBlock(ctx) + err = s.preModule.PreBlock(s.ctx) require.NoError(t, err) - ctx = ctx.WithHeaderInfo(header.Info{Height: ctx.HeaderInfo().Height + 1}) + s.ctx = s.ctx.WithHeaderInfo(header.Info{Height: s.ctx.HeaderInfo().Height + 1}) testCases := map[string]struct { preRun func(*keeper.Keeper, sdk.Context, string) @@ -514,13 +505,13 @@ func TestDowngradeVerification(t *testing.T) { } for name, tc := range testCases { - ctx, _ := ctx.CacheContext() + ctx, _ := s.ctx.CacheContext() authority, err := addresscodec.NewBech32Codec("cosmos").BytesToString(authtypes.NewModuleAddress(govModuleName)) require.NoError(t, err) // downgrade. now keeper does not have the handler. - k := keeper.NewKeeper(env, skip, encCfg.Codec, t.TempDir(), nil, authority) + k := keeper.NewKeeper(s.env, map[int64]bool{}, s.encCfg.Codec, t.TempDir(), nil, authority) m := upgrade.NewAppModule(k) // assertions