From 1f285297739df649e7a75a10e0516c33f3cb77b7 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Mon, 26 Feb 2024 21:46:29 +0100 Subject: [PATCH 01/39] feat: message router service --- core/appmodule/environment.go | 14 +++++++++----- core/gas/{meter.go => service.go} | 0 core/go.mod | 3 +++ core/go.sum | 5 +++++ core/router/service.go | 9 +++++++++ runtime/router.go | 30 ++++++++++++++++++++++++++++++ 6 files changed, 56 insertions(+), 5 deletions(-) rename core/gas/{meter.go => service.go} (100%) create mode 100644 core/router/service.go create mode 100644 runtime/router.go diff --git a/core/appmodule/environment.go b/core/appmodule/environment.go index 17ab778191c0..5e3ec6a74965 100644 --- a/core/appmodule/environment.go +++ b/core/appmodule/environment.go @@ -5,17 +5,21 @@ import ( "cosmossdk.io/core/event" "cosmossdk.io/core/gas" "cosmossdk.io/core/header" + "cosmossdk.io/core/router" "cosmossdk.io/core/store" "cosmossdk.io/log" ) // Environment is used to get all services to their respective module type Environment struct { - BranchService branch.Service - EventService event.Service - GasService gas.Service - HeaderService header.Service + Logger log.Logger + + BranchService branch.Service + EventService event.Service + GasService gas.Service + HeaderService header.Service + MessageRouterService router.Service + KVStoreService store.KVStoreService MemStoreService store.MemoryStoreService - Logger log.Logger } diff --git a/core/gas/meter.go b/core/gas/service.go similarity index 100% rename from core/gas/meter.go rename to core/gas/service.go diff --git a/core/go.mod b/core/go.mod index e7bf2f319d5e..e732129de93a 100644 --- a/core/go.mod +++ b/core/go.mod @@ -4,6 +4,7 @@ go 1.20 require ( cosmossdk.io/log v1.3.1 + github.com/cosmos/gogoproto v1.4.11 github.com/stretchr/testify v1.8.4 google.golang.org/grpc v1.62.0 google.golang.org/protobuf v1.32.0 @@ -12,6 +13,7 @@ require ( require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/golang/protobuf v1.5.3 // indirect + github.com/google/go-cmp v0.6.0 // indirect github.com/kr/pretty v0.3.1 // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.20 // indirect @@ -19,6 +21,7 @@ require ( github.com/pmezard/go-difflib v1.0.0 // indirect github.com/rogpeppe/go-internal v1.11.0 // indirect github.com/rs/zerolog v1.32.0 // indirect + golang.org/x/exp v0.0.0-20230811145659-89c5cff77bcb // indirect golang.org/x/net v0.21.0 // indirect golang.org/x/sys v0.17.0 // indirect golang.org/x/text v0.14.0 // indirect diff --git a/core/go.sum b/core/go.sum index 105975b5b061..57133f587985 100644 --- a/core/go.sum +++ b/core/go.sum @@ -1,6 +1,8 @@ cosmossdk.io/log v1.3.1 h1:UZx8nWIkfbbNEWusZqzAx3ZGvu54TZacWib3EzUYmGI= cosmossdk.io/log v1.3.1/go.mod h1:2/dIomt8mKdk6vl3OWJcPk2be3pGOS8OQaLUM/3/tCM= github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= +github.com/cosmos/gogoproto v1.4.11 h1:LZcMHrx4FjUgrqQSWeaGC1v/TeuVFqSLa43CC6aWR2g= +github.com/cosmos/gogoproto v1.4.11/go.mod h1:/g39Mh8m17X8Q/GDEs5zYTSNaNnInBSohtaxzQnYq1Y= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -10,6 +12,7 @@ github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= @@ -36,6 +39,8 @@ 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/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +golang.org/x/exp v0.0.0-20230811145659-89c5cff77bcb h1:mIKbk8weKhSeLH2GmUTrvx8CjkyJmnU1wFmg59CUjFA= +golang.org/x/exp v0.0.0-20230811145659-89c5cff77bcb/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc= golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4= golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= diff --git a/core/router/service.go b/core/router/service.go new file mode 100644 index 000000000000..7d50df7a5b69 --- /dev/null +++ b/core/router/service.go @@ -0,0 +1,9 @@ +package router + +import gogoproto "github.com/cosmos/gogoproto/proto" + +// Service is the interface that wraps the basic methods for a router service. +type Service interface { + Handler(msg gogoproto.Message) Service + HandlerByTypeURL(typeURL string) Service +} diff --git a/runtime/router.go b/runtime/router.go new file mode 100644 index 000000000000..3060f3f91344 --- /dev/null +++ b/runtime/router.go @@ -0,0 +1,30 @@ +package runtime + +import ( + "cosmossdk.io/core/router" + "cosmossdk.io/core/store" + "github.com/cosmos/cosmos-sdk/baseapp" + "github.com/cosmos/gogoproto/proto" +) + +func NewMsgRouterService(storeService store.KVStoreService, router baseapp.MessageRouter) router.Service { + return &msgRouterService{ + storeService: storeService, + router: router, + } +} + +type msgRouterService struct { + storeService store.KVStoreService + router baseapp.MessageRouter +} + +// Handler implements router.Service. +func (m *msgRouterService) Handler(msg proto.Message) router.Service { + return m.router.Handler(msg) +} + +// HandlerByTypeURL implements router.Service. +func (*msgRouterService) HandlerByTypeURL(typeURL string) router.Service { + panic("unimplemented") +} From c8622b32830cdb8c44edeafbd6bd148c0f477b3b Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Mon, 26 Feb 2024 23:46:33 +0100 Subject: [PATCH 02/39] updates --- core/router/service.go | 10 +++++++--- runtime/environment.go | 34 ++++++++++++++++++++++++++++++---- runtime/module.go | 17 ++++++++++------- runtime/router.go | 25 +++++++++++++++++-------- testutil/integration/router.go | 2 +- 5 files changed, 65 insertions(+), 23 deletions(-) diff --git a/core/router/service.go b/core/router/service.go index 7d50df7a5b69..fcf5c0c44599 100644 --- a/core/router/service.go +++ b/core/router/service.go @@ -1,9 +1,13 @@ package router -import gogoproto "github.com/cosmos/gogoproto/proto" +import ( + "context" + + "google.golang.org/protobuf/runtime/protoiface" +) // Service is the interface that wraps the basic methods for a router service. type Service interface { - Handler(msg gogoproto.Message) Service - HandlerByTypeURL(typeURL string) Service + InvokeTyped(ctx context.Context, req, res protoiface.MessageV1) error + // InvokeUntyped(ctx context.Context, req protoiface.MessageV1) (res protoiface.MessageV1, err error) } diff --git a/runtime/environment.go b/runtime/environment.go index 2a592363eb6d..d314e479c031 100644 --- a/runtime/environment.go +++ b/runtime/environment.go @@ -4,17 +4,43 @@ import ( "cosmossdk.io/core/appmodule" "cosmossdk.io/core/store" "cosmossdk.io/log" + "github.com/cosmos/cosmos-sdk/baseapp" ) // NewEnvironment creates a new environment for the application -// if memstoreservice is needed, it can be added to the environment: environment.MemStoreService = memstoreservice -func NewEnvironment(kvService store.KVStoreService, logger log.Logger) appmodule.Environment { - return appmodule.Environment{ +// For setting custom services that aren't set by default, use the EnvOption +// Note: Depinject always provide an environment with all services (mandatory and optional) +func NewEnvironment( + kvService store.KVStoreService, + logger log.Logger, + opts ...EnvOption, +) appmodule.Environment { + env := appmodule.Environment{ + Logger: logger, EventService: EventService{}, HeaderService: HeaderService{}, BranchService: BranchService{}, GasService: GasService{}, KVStoreService: kvService, - Logger: logger, + } + + for _, opt := range opts { + opt(&env) + } + + return env +} + +type EnvOption func(*appmodule.Environment) + +func EnvWithMessageRouterService(msgServiceRouter *baseapp.MsgServiceRouter) EnvOption { + return func(env *appmodule.Environment) { + env.MessageRouterService = NewMsgRouterService(env.KVStoreService, msgServiceRouter) + } +} + +func EnvWithMemStoreService(memStoreService store.MemoryStoreService) EnvOption { + return func(env *appmodule.Environment) { + env.MemStoreService = memStoreService } } diff --git a/runtime/module.go b/runtime/module.go index e00063df8642..328dea4bb49e 100644 --- a/runtime/module.go +++ b/runtime/module.go @@ -67,7 +67,6 @@ func init() { ProvideMemoryStoreKey, ProvideGenesisTxHandler, ProvideEnvironment, - ProvideMemoryStoreService, ProvideTransientStoreService, ProvideModuleManager, ProvideAppVersionModifier, @@ -212,15 +211,19 @@ func ProvideGenesisTxHandler(appBuilder *AppBuilder) genesis.TxHandler { return appBuilder.app } -func ProvideEnvironment(config *runtimev1alpha1.Module, key depinject.ModuleKey, app *AppBuilder, logger log.Logger) (store.KVStoreService, appmodule.Environment) { +func ProvideEnvironment(logger log.Logger, config *runtimev1alpha1.Module, key depinject.ModuleKey, app *AppBuilder, msgServiceRouter *baseapp.MsgServiceRouter) (store.KVStoreService, store.MemoryStoreService, appmodule.Environment) { storeKey := ProvideKVStoreKey(config, key, app) kvService := kvStoreService{key: storeKey} - return kvService, NewEnvironment(kvService, logger) -} -func ProvideMemoryStoreService(key depinject.ModuleKey, app *AppBuilder) store.MemoryStoreService { - storeKey := ProvideMemoryStoreKey(key, app) - return memStoreService{key: storeKey} + memStoreKey := ProvideMemoryStoreKey(key, app) + memStoreService := memStoreService{key: memStoreKey} + + return kvService, memStoreService, NewEnvironment( + kvService, + logger, + EnvWithMessageRouterService(msgServiceRouter), + EnvWithMemStoreService(memStoreService), + ) } func ProvideTransientStoreService(key depinject.ModuleKey, app *AppBuilder) store.TransientStoreService { diff --git a/runtime/router.go b/runtime/router.go index 3060f3f91344..d951dee4bd14 100644 --- a/runtime/router.go +++ b/runtime/router.go @@ -1,13 +1,17 @@ package runtime import ( + "context" + "cosmossdk.io/core/router" "cosmossdk.io/core/store" "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/gogoproto/proto" + protov2 "google.golang.org/protobuf/proto" + "google.golang.org/protobuf/runtime/protoiface" ) -func NewMsgRouterService(storeService store.KVStoreService, router baseapp.MessageRouter) router.Service { +func NewMsgRouterService(storeService store.KVStoreService, router *baseapp.MsgServiceRouter) router.Service { return &msgRouterService{ storeService: storeService, router: router, @@ -16,15 +20,20 @@ func NewMsgRouterService(storeService store.KVStoreService, router baseapp.Messa type msgRouterService struct { storeService store.KVStoreService - router baseapp.MessageRouter + router *baseapp.MsgServiceRouter } -// Handler implements router.Service. -func (m *msgRouterService) Handler(msg proto.Message) router.Service { - return m.router.Handler(msg) +// InvokeTyped implements router.Service. +func (m *msgRouterService) InvokeTyped(ctx context.Context, req protoiface.MessageV1, res protoiface.MessageV1) error { + messageName := msgTypeURL(req) + return m.router.HybridHandlerByMsgName(messageName)(ctx, req, res) } -// HandlerByTypeURL implements router.Service. -func (*msgRouterService) HandlerByTypeURL(typeURL string) router.Service { - panic("unimplemented") +// msgTypeURL returns the TypeURL of a `sdk.Msg`. +func msgTypeURL(msg proto.Message) string { + if m, ok := msg.(protov2.Message); ok { + return "/" + string(m.ProtoReflect().Descriptor().FullName()) + } + + return "/" + proto.MessageName(msg) } diff --git a/testutil/integration/router.go b/testutil/integration/router.go index 2784118eb2a2..6f4e2a647638 100644 --- a/testutil/integration/router.go +++ b/testutil/integration/router.go @@ -81,7 +81,7 @@ func NewIntegrationApp( if keys[consensusparamtypes.StoreKey] != nil { // set baseApp param store - consensusParamsKeeper := consensusparamkeeper.NewKeeper(appCodec, runtime.NewEnvironment(runtime.NewKVStoreService(keys[consensusparamtypes.StoreKey]), log.NewNopLogger()), authtypes.NewModuleAddress("gov").String()) + consensusParamsKeeper := consensusparamkeeper.NewKeeper(appCodec, runtime.NewEnvironment(runtime.NewKVStoreService(keys[consensusparamtypes.StoreKey]), log.NewNopLogger(), runtime.EnvWithMessageRouterService(router)), authtypes.NewModuleAddress("gov").String()) bApp.SetParamStore(consensusParamsKeeper.ParamsStore) if err := bApp.LoadLatestVersion(); err != nil { From cf6ff8a91ad97f39f5b874a5bbfd786381a6ae43 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Tue, 27 Feb 2024 00:03:20 +0100 Subject: [PATCH 03/39] `make lint-fix` --- runtime/environment.go | 1 + runtime/router.go | 10 ++++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/runtime/environment.go b/runtime/environment.go index d314e479c031..da4f1e9ba13f 100644 --- a/runtime/environment.go +++ b/runtime/environment.go @@ -4,6 +4,7 @@ import ( "cosmossdk.io/core/appmodule" "cosmossdk.io/core/store" "cosmossdk.io/log" + "github.com/cosmos/cosmos-sdk/baseapp" ) diff --git a/runtime/router.go b/runtime/router.go index d951dee4bd14..64669b177de9 100644 --- a/runtime/router.go +++ b/runtime/router.go @@ -3,12 +3,14 @@ package runtime import ( "context" - "cosmossdk.io/core/router" - "cosmossdk.io/core/store" - "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/gogoproto/proto" protov2 "google.golang.org/protobuf/proto" "google.golang.org/protobuf/runtime/protoiface" + + "cosmossdk.io/core/router" + "cosmossdk.io/core/store" + + "github.com/cosmos/cosmos-sdk/baseapp" ) func NewMsgRouterService(storeService store.KVStoreService, router *baseapp.MsgServiceRouter) router.Service { @@ -24,7 +26,7 @@ type msgRouterService struct { } // InvokeTyped implements router.Service. -func (m *msgRouterService) InvokeTyped(ctx context.Context, req protoiface.MessageV1, res protoiface.MessageV1) error { +func (m *msgRouterService) InvokeTyped(ctx context.Context, req, res protoiface.MessageV1) error { messageName := msgTypeURL(req) return m.router.HybridHandlerByMsgName(messageName)(ctx, req, res) } From 3c550b23763bfcecd85bc44bde9072047786a13b Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Tue, 27 Feb 2024 08:48:10 +0100 Subject: [PATCH 04/39] updates --- core/router/service.go | 2 +- runtime/router.go | 40 +++++++++++++++++++++++++++++++++++++--- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/core/router/service.go b/core/router/service.go index fcf5c0c44599..669d43db2c1d 100644 --- a/core/router/service.go +++ b/core/router/service.go @@ -9,5 +9,5 @@ import ( // Service is the interface that wraps the basic methods for a router service. type Service interface { InvokeTyped(ctx context.Context, req, res protoiface.MessageV1) error - // InvokeUntyped(ctx context.Context, req protoiface.MessageV1) (res protoiface.MessageV1, err error) + InvokeUntyped(ctx context.Context, req protoiface.MessageV1) (res protoiface.MessageV1, err error) } diff --git a/runtime/router.go b/runtime/router.go index 64669b177de9..baebea58ecca 100644 --- a/runtime/router.go +++ b/runtime/router.go @@ -2,9 +2,12 @@ package runtime import ( "context" + "fmt" "github.com/cosmos/gogoproto/proto" protov2 "google.golang.org/protobuf/proto" + "google.golang.org/protobuf/reflect/protoreflect" + "google.golang.org/protobuf/reflect/protoregistry" "google.golang.org/protobuf/runtime/protoiface" "cosmossdk.io/core/router" @@ -17,18 +20,49 @@ func NewMsgRouterService(storeService store.KVStoreService, router *baseapp.MsgS return &msgRouterService{ storeService: storeService, router: router, + resolver: protoregistry.GlobalTypes, } } type msgRouterService struct { storeService store.KVStoreService router *baseapp.MsgServiceRouter + resolver protoregistry.MessageTypeResolver } // InvokeTyped implements router.Service. -func (m *msgRouterService) InvokeTyped(ctx context.Context, req, res protoiface.MessageV1) error { - messageName := msgTypeURL(req) - return m.router.HybridHandlerByMsgName(messageName)(ctx, req, res) +func (m *msgRouterService) InvokeTyped(ctx context.Context, msg, msgResp protoiface.MessageV1) error { + messageName := msgTypeURL(msg) + handler := m.router.HybridHandlerByMsgName(messageName) + if handler == nil { + return fmt.Errorf("unknown message: %s", messageName) + } + + return handler(ctx, msg, msgResp) +} + +// InvokeUntyped implements router.Service. +func (m *msgRouterService) InvokeUntyped(ctx context.Context, msg protoiface.MessageV1) (protoiface.MessageV1, error) { + messageName := msgTypeURL(msg) + respName := m.router.ResponseNameByRequestName(messageName) + if respName == "" { + return nil, fmt.Errorf("could not find response type for message %T", msg) + } + + // get response type + resp, err := m.resolver.FindMessageByName(protoreflect.FullName(respName)) + if err != nil { + return nil, err + } + + handler := m.router.HybridHandlerByMsgName(messageName) + if handler == nil { + return nil, fmt.Errorf("unknown message: %s", messageName) + } + + msgResp := resp.New().Interface().(protoiface.MessageV1) + err = handler(ctx, msg, msgResp) + return msgResp, err } // msgTypeURL returns the TypeURL of a `sdk.Msg`. From 9700f787e7269a7ecf7d39be1e66d29400c1262d Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Tue, 27 Feb 2024 12:47:48 +0100 Subject: [PATCH 05/39] updates --- CHANGELOG.md | 1 + baseapp/msg_service_router.go | 3 +++ core/CHANGELOG.md | 3 ++- runtime/router.go | 26 ++++++++++++++------------ 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3e9939c7bd8d..c5d15e6869f4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,6 +42,7 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i ### Features +* (runtime) [#19571](https://github.com/cosmos/cosmos-sdk/pull/19571) Implement `core/router.Service` it in runtime. This service is present in all modules (when using depinject). * (types) [#19164](https://github.com/cosmos/cosmos-sdk/pull/19164) Add a ValueCodec for the math.Uint type that can be used in collections maps. * (types) [#19281](https://github.com/cosmos/cosmos-sdk/pull/19281) Added a new method, `IsGT`, for `types.Coin`. This method is used to check if a `types.Coin` is greater than another `types.Coin`. * (client) [#18557](https://github.com/cosmos/cosmos-sdk/pull/18557) Add `--qrcode` flag to `keys show` command to support displaying keys address QR code. diff --git a/baseapp/msg_service_router.go b/baseapp/msg_service_router.go index fe4488d2673c..22f76cbafa3c 100644 --- a/baseapp/msg_service_router.go +++ b/baseapp/msg_service_router.go @@ -24,6 +24,9 @@ import ( type MessageRouter interface { Handler(msg sdk.Msg) MsgServiceHandler HandlerByTypeURL(typeURL string) MsgServiceHandler + + ResponseNameByRequestName(msgName string) string + HybridHandlerByMsgName(msgName string) func(ctx context.Context, req, resp protoiface.MessageV1) error } // MsgServiceRouter routes fully-qualified Msg service methods to their handler. diff --git a/core/CHANGELOG.md b/core/CHANGELOG.md index 27ee7b8be825..49a3e692f14d 100644 --- a/core/CHANGELOG.md +++ b/core/CHANGELOG.md @@ -42,7 +42,8 @@ Ref: https://keepachangelog.com/en/1.0.0/ * [#18457](https://github.com/cosmos/cosmos-sdk/pull/18457) Add branch.ExecuteWithGasLimit. * [#19041](https://github.com/cosmos/cosmos-sdk/pull/19041) Add `appmodule.Environment` interface to fetch different services * [#19370](https://github.com/cosmos/cosmos-sdk/pull/19370) Add `appmodule.Migrations` interface to handle migrations - +* [#19571](https://github.com/cosmos/cosmos-sdk/pull/19571) Add `router.Service` and add it in `appmodule.Environment` + ### API Breaking Changes * [#18857](https://github.com/cosmos/cosmos-sdk/pull/18857) Moved `FormatCoins` to `x/tx`. diff --git a/runtime/router.go b/runtime/router.go index baebea58ecca..f690e213d54e 100644 --- a/runtime/router.go +++ b/runtime/router.go @@ -3,10 +3,10 @@ package runtime import ( "context" "fmt" + "reflect" "github.com/cosmos/gogoproto/proto" protov2 "google.golang.org/protobuf/proto" - "google.golang.org/protobuf/reflect/protoreflect" "google.golang.org/protobuf/reflect/protoregistry" "google.golang.org/protobuf/runtime/protoiface" @@ -16,7 +16,7 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" ) -func NewMsgRouterService(storeService store.KVStoreService, router *baseapp.MsgServiceRouter) router.Service { +func NewMsgRouterService(storeService store.KVStoreService, router baseapp.MessageRouter) router.Service { return &msgRouterService{ storeService: storeService, router: router, @@ -26,22 +26,24 @@ func NewMsgRouterService(storeService store.KVStoreService, router *baseapp.MsgS type msgRouterService struct { storeService store.KVStoreService - router *baseapp.MsgServiceRouter + router baseapp.MessageRouter resolver protoregistry.MessageTypeResolver } -// InvokeTyped implements router.Service. -func (m *msgRouterService) InvokeTyped(ctx context.Context, msg, msgResp protoiface.MessageV1) error { +// InvokeTyped execute a message and fill-in a response. +// The response must be known and passed as a parameter. +// Use InvokeUntyped if the response type is not known. +func (m *msgRouterService) InvokeTyped(ctx context.Context, msg, resp protoiface.MessageV1) error { messageName := msgTypeURL(msg) handler := m.router.HybridHandlerByMsgName(messageName) if handler == nil { return fmt.Errorf("unknown message: %s", messageName) } - return handler(ctx, msg, msgResp) + return handler(ctx, msg, resp) } -// InvokeUntyped implements router.Service. +// InvokeUntyped execute a message and returns a response. func (m *msgRouterService) InvokeUntyped(ctx context.Context, msg protoiface.MessageV1) (protoiface.MessageV1, error) { messageName := msgTypeURL(msg) respName := m.router.ResponseNameByRequestName(messageName) @@ -50,18 +52,18 @@ func (m *msgRouterService) InvokeUntyped(ctx context.Context, msg protoiface.Mes } // get response type - resp, err := m.resolver.FindMessageByName(protoreflect.FullName(respName)) - if err != nil { - return nil, err + typ := proto.MessageType(respName) + if typ == nil { + return nil, fmt.Errorf("no message type found for %s", respName) } + msgResp := reflect.New(typ.Elem()).Interface().(protoiface.MessageV1) handler := m.router.HybridHandlerByMsgName(messageName) if handler == nil { return nil, fmt.Errorf("unknown message: %s", messageName) } - msgResp := resp.New().Interface().(protoiface.MessageV1) - err = handler(ctx, msg, msgResp) + err := handler(ctx, msg, msgResp) return msgResp, err } From c7b8a8a12190c878ca2ef79f32ca7aef68c49632 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Tue, 27 Feb 2024 12:49:11 +0100 Subject: [PATCH 06/39] nit --- runtime/router.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/router.go b/runtime/router.go index f690e213d54e..03e73f5fdf1d 100644 --- a/runtime/router.go +++ b/runtime/router.go @@ -67,7 +67,7 @@ func (m *msgRouterService) InvokeUntyped(ctx context.Context, msg protoiface.Mes return msgResp, err } -// msgTypeURL returns the TypeURL of a `sdk.Msg`. +// msgTypeURL returns the TypeURL of a proto message. func msgTypeURL(msg proto.Message) string { if m, ok := msg.(protov2.Message); ok { return "/" + string(m.ProtoReflect().Descriptor().FullName()) From 37c08d2fad678970f8dfb16606a7723e93e80715 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Tue, 27 Feb 2024 15:28:48 +0100 Subject: [PATCH 07/39] feedback --- baseapp/msg_service_router.go | 6 +++--- runtime/router.go | 5 ++++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/baseapp/msg_service_router.go b/baseapp/msg_service_router.go index 22f76cbafa3c..ddbd3f8fe153 100644 --- a/baseapp/msg_service_router.go +++ b/baseapp/msg_service_router.go @@ -25,7 +25,7 @@ type MessageRouter interface { Handler(msg sdk.Msg) MsgServiceHandler HandlerByTypeURL(typeURL string) MsgServiceHandler - ResponseNameByRequestName(msgName string) string + ResponseNameByRequestName(requestName string) string HybridHandlerByMsgName(msgName string) func(ctx context.Context, req, resp protoiface.MessageV1) error } @@ -93,8 +93,8 @@ func (msr *MsgServiceRouter) HybridHandlerByMsgName(msgName string) func(ctx con return msr.hybridHandlers[msgName] } -func (msr *MsgServiceRouter) ResponseNameByRequestName(msgName string) string { - return msr.responseByRequest[msgName] +func (msr *MsgServiceRouter) ResponseNameByRequestName(requestName string) string { + return msr.responseByRequest[requestName] } func (msr *MsgServiceRouter) registerHybridHandler(sd *grpc.ServiceDesc, method grpc.MethodDesc, handler interface{}) error { diff --git a/runtime/router.go b/runtime/router.go index 03e73f5fdf1d..b2237be3d592 100644 --- a/runtime/router.go +++ b/runtime/router.go @@ -56,7 +56,10 @@ func (m *msgRouterService) InvokeUntyped(ctx context.Context, msg protoiface.Mes if typ == nil { return nil, fmt.Errorf("no message type found for %s", respName) } - msgResp := reflect.New(typ.Elem()).Interface().(protoiface.MessageV1) + msgResp, ok := reflect.New(typ.Elem()).Interface().(protoiface.MessageV1) + if !ok { + return nil, fmt.Errorf("could not create response message %s", respName) + } handler := m.router.HybridHandlerByMsgName(messageName) if handler == nil { From ad4ec723229401e8477f522ab1bc36eb7f9e993a Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 29 Feb 2024 10:04:05 +0100 Subject: [PATCH 08/39] go docs --- core/router/service.go | 1 + runtime/router.go | 4 +--- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/core/router/service.go b/core/router/service.go index 669d43db2c1d..43cc7e8fb9b8 100644 --- a/core/router/service.go +++ b/core/router/service.go @@ -7,6 +7,7 @@ import ( ) // Service is the interface that wraps the basic methods for a router service. +// This service allows to invoke messages and queries via a message router. type Service interface { InvokeTyped(ctx context.Context, req, res protoiface.MessageV1) error InvokeUntyped(ctx context.Context, req protoiface.MessageV1) (res protoiface.MessageV1, err error) diff --git a/runtime/router.go b/runtime/router.go index b2237be3d592..9b629d18a5e3 100644 --- a/runtime/router.go +++ b/runtime/router.go @@ -7,7 +7,6 @@ import ( "github.com/cosmos/gogoproto/proto" protov2 "google.golang.org/protobuf/proto" - "google.golang.org/protobuf/reflect/protoregistry" "google.golang.org/protobuf/runtime/protoiface" "cosmossdk.io/core/router" @@ -16,18 +15,17 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" ) +// NewMsgRouterService creates a router.Service which allows to invoke messages and queries using the msg router. func NewMsgRouterService(storeService store.KVStoreService, router baseapp.MessageRouter) router.Service { return &msgRouterService{ storeService: storeService, router: router, - resolver: protoregistry.GlobalTypes, } } type msgRouterService struct { storeService store.KVStoreService router baseapp.MessageRouter - resolver protoregistry.MessageTypeResolver } // InvokeTyped execute a message and fill-in a response. From 3a986faddfa920e670c2ee085f40790f746a3999 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 29 Feb 2024 10:39:17 +0100 Subject: [PATCH 09/39] add test --- client/grpc_query_test.go | 2 +- runtime/router_test.go | 42 ++++++++++++++++++++++++++++++++++++++ x/counter/depinject.go | 9 +++----- x/counter/keeper/keeper.go | 12 +++++------ 4 files changed, 52 insertions(+), 13 deletions(-) create mode 100644 runtime/router_test.go diff --git a/client/grpc_query_test.go b/client/grpc_query_test.go index 7aaf78a85445..a493fc548ff1 100644 --- a/client/grpc_query_test.go +++ b/client/grpc_query_test.go @@ -47,7 +47,7 @@ func (s *IntegrationTestSuite) SetupSuite() { s.testClient = testdata.NewQueryClient(queryHelper) kvs := runtime.NewKVStoreService(keys[countertypes.StoreKey]) - counterKeeper := counterkeeper.NewKeeper(kvs, runtime.EventService{}) + counterKeeper := counterkeeper.NewKeeper(runtime.NewEnvironment(kvs, logger)) countertypes.RegisterQueryServer(queryHelper, counterKeeper) s.counterClient = countertypes.NewQueryClient(queryHelper) } diff --git a/runtime/router_test.go b/runtime/router_test.go new file mode 100644 index 000000000000..db6e88527f53 --- /dev/null +++ b/runtime/router_test.go @@ -0,0 +1,42 @@ +package runtime_test + +import ( + "context" + "testing" + + "cosmossdk.io/log" + storetypes "cosmossdk.io/store/types" + "github.com/cosmos/cosmos-sdk/baseapp" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/cosmos/cosmos-sdk/runtime" + counterkeeper "github.com/cosmos/cosmos-sdk/x/counter/keeper" + countertypes "github.com/cosmos/cosmos-sdk/x/counter/types" + "github.com/stretchr/testify/require" +) + +func TestMsgRouterService(t *testing.T) { + router := baseapp.NewMsgServiceRouter() + interfaceRegistry := codectypes.NewInterfaceRegistry() + router.SetInterfaceRegistry(interfaceRegistry) + key := storetypes.NewKVStoreKey(countertypes.StoreKey) + storeService := runtime.NewKVStoreService(key) + counterKeeper := counterkeeper.NewKeeper(runtime.NewEnvironment(storeService, log.NewNopLogger())) + countertypes.RegisterInterfaces(interfaceRegistry) + countertypes.RegisterMsgServer(router, counterKeeper) + countertypes.RegisterQueryServer(router, counterKeeper) + + routerService := runtime.NewMsgRouterService(storeService, router) + + resp, err := routerService.InvokeUntyped(context.Background(), &countertypes.MsgIncreaseCounter{ + Signer: "cosmos1", + Count: 42, + }) + require.NoError(t, err) + require.NotNil(t, resp) + + resp = &countertypes.QueryGetCountResponse{} + err = routerService.InvokeTyped(context.Background(), &countertypes.QueryGetCountRequest{}, &countertypes.QueryGetCountResponse{}) + require.NoError(t, err) + require.NotNil(t, resp) + require.Equal(t, &countertypes.QueryGetCountResponse{TotalCount: 42}, resp) +} diff --git a/x/counter/depinject.go b/x/counter/depinject.go index a1297170602b..4cbe20acf4a2 100644 --- a/x/counter/depinject.go +++ b/x/counter/depinject.go @@ -3,8 +3,6 @@ package counter import ( modulev1 "cosmossdk.io/api/cosmos/counter/module/v1" "cosmossdk.io/core/appmodule" - "cosmossdk.io/core/event" - storetypes "cosmossdk.io/core/store" "cosmossdk.io/depinject" "cosmossdk.io/depinject/appconfig" @@ -26,9 +24,8 @@ func init() { type ModuleInputs struct { depinject.In - Config *modulev1.Module - StoreService storetypes.KVStoreService - EventManager event.Service + Config *modulev1.Module + Environment appmodule.Environment } type ModuleOutputs struct { @@ -39,7 +36,7 @@ type ModuleOutputs struct { } func ProvideModule(in ModuleInputs) ModuleOutputs { - k := keeper.NewKeeper(in.StoreService, in.EventManager) + k := keeper.NewKeeper(in.Environment) m := NewAppModule(k) return ModuleOutputs{ diff --git a/x/counter/keeper/keeper.go b/x/counter/keeper/keeper.go index 6d7fd422e8c3..f03b978ad1e4 100644 --- a/x/counter/keeper/keeper.go +++ b/x/counter/keeper/keeper.go @@ -9,8 +9,8 @@ import ( "google.golang.org/grpc/status" "cosmossdk.io/collections" + "cosmossdk.io/core/appmodule" "cosmossdk.io/core/event" - storetypes "cosmossdk.io/core/store" "github.com/cosmos/cosmos-sdk/x/counter/types" ) @@ -18,15 +18,15 @@ import ( var StoreKey = "Counter" type Keeper struct { - event event.Service + env appmodule.Environment CountStore collections.Item[int64] } -func NewKeeper(storeService storetypes.KVStoreService, em event.Service) Keeper { - sb := collections.NewSchemaBuilder(storeService) +func NewKeeper(env appmodule.Environment) Keeper { + sb := collections.NewSchemaBuilder(env.KVStoreService) return Keeper{ - event: em, + env: env, CountStore: collections.NewItem(sb, collections.NewPrefix(0), "count", collections.Int64Value), } } @@ -67,7 +67,7 @@ func (k Keeper) IncreaseCount(ctx context.Context, msg *types.MsgIncreaseCounter return nil, err } - if err := k.event.EventManager(ctx).EmitKV( + if err := k.env.EventService.EventManager(ctx).EmitKV( "increase_counter", event.NewAttribute("signer", msg.Signer), event.NewAttribute("new count", fmt.Sprint(num+msg.Count))); err != nil { From e8f8d24e35511b4fc7fd046211483f60f4fed436 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 29 Feb 2024 10:44:44 +0100 Subject: [PATCH 10/39] updates --- core/router/service.go | 2 ++ runtime/router.go | 2 +- runtime/router_test.go | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/core/router/service.go b/core/router/service.go index 43cc7e8fb9b8..634e18064649 100644 --- a/core/router/service.go +++ b/core/router/service.go @@ -9,6 +9,8 @@ import ( // Service is the interface that wraps the basic methods for a router service. // This service allows to invoke messages and queries via a message router. type Service interface { + // InvokeTyped execute a message or query. It should be used when the called knows the type of the response. InvokeTyped(ctx context.Context, req, res protoiface.MessageV1) error + // InvokeUntyped execute a message or query. It should be used when the called doesn't know the type of the response. InvokeUntyped(ctx context.Context, req protoiface.MessageV1) (res protoiface.MessageV1, err error) } diff --git a/runtime/router.go b/runtime/router.go index 9b629d18a5e3..48e6d24294da 100644 --- a/runtime/router.go +++ b/runtime/router.go @@ -46,7 +46,7 @@ func (m *msgRouterService) InvokeUntyped(ctx context.Context, msg protoiface.Mes messageName := msgTypeURL(msg) respName := m.router.ResponseNameByRequestName(messageName) if respName == "" { - return nil, fmt.Errorf("could not find response type for message %T", msg) + return nil, fmt.Errorf("could not find response type for message %s (%T)", messageName, msg) } // get response type diff --git a/runtime/router_test.go b/runtime/router_test.go index db6e88527f53..8c2a36540f45 100644 --- a/runtime/router_test.go +++ b/runtime/router_test.go @@ -23,7 +23,7 @@ func TestMsgRouterService(t *testing.T) { counterKeeper := counterkeeper.NewKeeper(runtime.NewEnvironment(storeService, log.NewNopLogger())) countertypes.RegisterInterfaces(interfaceRegistry) countertypes.RegisterMsgServer(router, counterKeeper) - countertypes.RegisterQueryServer(router, counterKeeper) + // countertypes.RegisterQueryServer(router, counterKeeper) routerService := runtime.NewMsgRouterService(storeService, router) From 64a92c437d84efff74b24a592b5c62ee5d09167b Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 29 Feb 2024 11:01:30 +0100 Subject: [PATCH 11/39] updates --- runtime/router_test.go | 60 +++++++++++++++++++++++++++++++++--------- 1 file changed, 47 insertions(+), 13 deletions(-) diff --git a/runtime/router_test.go b/runtime/router_test.go index 8c2a36540f45..dd9bec43c4d8 100644 --- a/runtime/router_test.go +++ b/runtime/router_test.go @@ -1,14 +1,16 @@ package runtime_test import ( - "context" "testing" + bankv1beta1 "cosmossdk.io/api/cosmos/bank/v1beta1" + counterv1 "cosmossdk.io/api/cosmos/counter/v1" "cosmossdk.io/log" storetypes "cosmossdk.io/store/types" "github.com/cosmos/cosmos-sdk/baseapp" codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/runtime" + "github.com/cosmos/cosmos-sdk/testutil" counterkeeper "github.com/cosmos/cosmos-sdk/x/counter/keeper" countertypes "github.com/cosmos/cosmos-sdk/x/counter/types" "github.com/stretchr/testify/require" @@ -23,20 +25,52 @@ func TestMsgRouterService(t *testing.T) { counterKeeper := counterkeeper.NewKeeper(runtime.NewEnvironment(storeService, log.NewNopLogger())) countertypes.RegisterInterfaces(interfaceRegistry) countertypes.RegisterMsgServer(router, counterKeeper) - // countertypes.RegisterQueryServer(router, counterKeeper) + countertypes.RegisterQueryServer(router, counterKeeper) routerService := runtime.NewMsgRouterService(storeService, router) + testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) - resp, err := routerService.InvokeUntyped(context.Background(), &countertypes.MsgIncreaseCounter{ - Signer: "cosmos1", - Count: 42, + t.Run("invalid msg", func(t *testing.T) { + _, err := routerService.InvokeUntyped(testCtx.Ctx, &bankv1beta1.MsgSend{}) + require.ErrorContains(t, err, "could not find response type for message /cosmos.bank.v1beta1.MsgSend") + }) + + t.Run("valid msg (proto v1)", func(t *testing.T) { + resp, err := routerService.InvokeUntyped(testCtx.Ctx, &countertypes.MsgIncreaseCounter{ + Signer: "cosmos1", + Count: 42, + }) + require.NoError(t, err) + require.NotNil(t, resp) + }) + + t.Run("valid msg (proto v2)", func(t *testing.T) { + resp, err := routerService.InvokeUntyped(testCtx.Ctx, &counterv1.MsgIncreaseCounter{ + Signer: "cosmos1", + Count: 42, + }) + require.NoError(t, err) + require.NotNil(t, resp) + }) + + t.Run("invalid query", func(t *testing.T) { + err := routerService.InvokeTyped(testCtx.Ctx, &bankv1beta1.QueryBalanceRequest{}, &bankv1beta1.QueryBalanceResponse{}) + require.ErrorContains(t, err, "unknown message: /cosmos.bank.v1beta1.QueryBalanceRequest") + }) + + t.Run("valid query (proto v1)", func(t *testing.T) { + resp := &countertypes.QueryGetCountResponse{} + err := routerService.InvokeTyped(testCtx.Ctx, &countertypes.QueryGetCountRequest{}, resp) + require.NoError(t, err) + require.NotNil(t, resp) + require.Equal(t, &countertypes.QueryGetCountResponse{TotalCount: 42}, resp) + }) + + t.Run("valid query (proto v2)", func(t *testing.T) { + resp := &counterv1.QueryGetCountResponse{} + err := routerService.InvokeTyped(testCtx.Ctx, &counterv1.QueryGetCountRequest{}, resp) + require.NoError(t, err) + require.NotNil(t, resp) + require.Equal(t, &counterv1.QueryGetCountResponse{TotalCount: 42}, resp) }) - require.NoError(t, err) - require.NotNil(t, resp) - - resp = &countertypes.QueryGetCountResponse{} - err = routerService.InvokeTyped(context.Background(), &countertypes.QueryGetCountRequest{}, &countertypes.QueryGetCountResponse{}) - require.NoError(t, err) - require.NotNil(t, resp) - require.Equal(t, &countertypes.QueryGetCountResponse{TotalCount: 42}, resp) } From aebdf33148a62b0c4dda98fefe741699f9210ece Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Thu, 29 Feb 2024 12:05:11 +0100 Subject: [PATCH 12/39] migrate to query Consensus Params --- core/go.mod | 3 --- core/go.sum | 5 ----- simapp/ante.go | 2 +- simapp/app.go | 3 +++ types/context.go | 2 ++ x/auth/ante/ante.go | 4 +++- x/auth/ante/setup.go | 24 ++++++++++++++++++------ x/auth/ante/setup_test.go | 8 +++++--- x/evidence/keeper/infraction.go | 15 +++++++++------ x/staking/keeper/msg_server.go | 15 +++++++++------ x/upgrade/keeper/abci.go | 10 +++++++--- 11 files changed, 57 insertions(+), 34 deletions(-) diff --git a/core/go.mod b/core/go.mod index e732129de93a..e7bf2f319d5e 100644 --- a/core/go.mod +++ b/core/go.mod @@ -4,7 +4,6 @@ go 1.20 require ( cosmossdk.io/log v1.3.1 - github.com/cosmos/gogoproto v1.4.11 github.com/stretchr/testify v1.8.4 google.golang.org/grpc v1.62.0 google.golang.org/protobuf v1.32.0 @@ -13,7 +12,6 @@ require ( require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/golang/protobuf v1.5.3 // indirect - github.com/google/go-cmp v0.6.0 // indirect github.com/kr/pretty v0.3.1 // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.20 // indirect @@ -21,7 +19,6 @@ require ( github.com/pmezard/go-difflib v1.0.0 // indirect github.com/rogpeppe/go-internal v1.11.0 // indirect github.com/rs/zerolog v1.32.0 // indirect - golang.org/x/exp v0.0.0-20230811145659-89c5cff77bcb // indirect golang.org/x/net v0.21.0 // indirect golang.org/x/sys v0.17.0 // indirect golang.org/x/text v0.14.0 // indirect diff --git a/core/go.sum b/core/go.sum index 57133f587985..105975b5b061 100644 --- a/core/go.sum +++ b/core/go.sum @@ -1,8 +1,6 @@ cosmossdk.io/log v1.3.1 h1:UZx8nWIkfbbNEWusZqzAx3ZGvu54TZacWib3EzUYmGI= cosmossdk.io/log v1.3.1/go.mod h1:2/dIomt8mKdk6vl3OWJcPk2be3pGOS8OQaLUM/3/tCM= github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= -github.com/cosmos/gogoproto v1.4.11 h1:LZcMHrx4FjUgrqQSWeaGC1v/TeuVFqSLa43CC6aWR2g= -github.com/cosmos/gogoproto v1.4.11/go.mod h1:/g39Mh8m17X8Q/GDEs5zYTSNaNnInBSohtaxzQnYq1Y= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -12,7 +10,6 @@ github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= -github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= @@ -39,8 +36,6 @@ 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/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -golang.org/x/exp v0.0.0-20230811145659-89c5cff77bcb h1:mIKbk8weKhSeLH2GmUTrvx8CjkyJmnU1wFmg59CUjFA= -golang.org/x/exp v0.0.0-20230811145659-89c5cff77bcb/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc= golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4= golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= diff --git a/simapp/ante.go b/simapp/ante.go index 8fde65c79aee..4ca4fb7cc855 100644 --- a/simapp/ante.go +++ b/simapp/ante.go @@ -34,7 +34,7 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) { } 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(), diff --git a/simapp/app.go b/simapp/app.go index c806c50216ee..606292498b43 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -140,6 +140,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 @@ -267,6 +268,7 @@ func NewSimApp( app := &SimApp{ BaseApp: bApp, + logger: logger, legacyAmino: legacyAmino, appCodec: appCodec, txConfig: txConfig, @@ -576,6 +578,7 @@ func (app *SimApp) setAnteHandler(txConfig client.TxConfig) { anteHandler, err := NewAnteHandler( HandlerOptions{ ante.HandlerOptions{ + Environment: runtime.NewEnvironment(nil, app.logger), // nil is set as the kvstoreservice to avoid module access AccountAbstractionKeeper: app.AccountsKeeper, AccountKeeper: app.AuthKeeper, BankKeeper: app.BankKeeper, diff --git a/types/context.go b/types/context.go index 1eb9d41e4068..f9adf4ff0d08 100644 --- a/types/context.go +++ b/types/context.go @@ -104,6 +104,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/auth/ante/ante.go b/x/auth/ante/ante.go index 657489a0c545..fd074370090d 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,7 +42,7 @@ 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(), NewTxTimeoutHeightDecorator(), diff --git a/x/auth/ante/setup.go b/x/auth/ante/setup.go index 4fbe8dac856e..ed17b35e1acc 100644 --- a/x/auth/ante/setup.go +++ b/x/auth/ante/setup.go @@ -3,6 +3,8 @@ package ante import ( "fmt" + consensusv1 "cosmossdk.io/api/cosmos/consensus/v1" + "cosmossdk.io/core/appmodule" errorsmod "cosmossdk.io/errors" storetypes "cosmossdk.io/store/types" @@ -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, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) { @@ -39,11 +45,17 @@ func (sud SetUpContextDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate 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.MessageRouterService.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 6f36e69a6be8..fcaaf8b59077 100644 --- a/x/auth/ante/setup_test.go +++ b/x/auth/ante/setup_test.go @@ -6,10 +6,12 @@ import ( cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/stretchr/testify/require" + "cosmossdk.io/log" storetypes "cosmossdk.io/store/types" "cosmossdk.io/x/auth/ante" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" + "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -34,7 +36,7 @@ func TestSetupDecorator_BlockMaxGas(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(runtime.NewEnvironment(nil, log.NewNopLogger())) antehandler := sdk.ChainAnteDecorators(sud) suite.ctx = suite.ctx. @@ -69,7 +71,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(runtime.NewEnvironment(nil, log.NewNopLogger())) antehandler := sdk.ChainAnteDecorators(sud) // Set height to non-zero value for GasMeter to be set @@ -104,7 +106,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(runtime.NewEnvironment(nil, log.NewNopLogger())) antehandler := sdk.ChainAnteDecorators(sud, OutOfGasDecorator{}) // Set height to non-zero value for GasMeter to be set diff --git a/x/evidence/keeper/infraction.go b/x/evidence/keeper/infraction.go index d0adc0e9f9c8..58b13fa0d385 100644 --- a/x/evidence/keeper/infraction.go +++ b/x/evidence/keeper/infraction.go @@ -4,6 +4,7 @@ import ( "context" "fmt" + consensusv1 "cosmossdk.io/api/cosmos/consensus/v1" st "cosmossdk.io/api/cosmos/staking/v1beta1" "cosmossdk.io/x/evidence/types" @@ -73,17 +74,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.environment.MessageRouterService.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.AsDuration() && ageBlocks > res.Params.Evidence.MaxAgeNumBlocks { 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/staking/keeper/msg_server.go b/x/staking/keeper/msg_server.go index dbbfb7a6499b..968ac86889b1 100644 --- a/x/staking/keeper/msg_server.go +++ b/x/staking/keeper/msg_server.go @@ -12,6 +12,7 @@ import ( "google.golang.org/grpc/codes" "google.golang.org/grpc/status" + consensusv1 "cosmossdk.io/api/cosmos/consensus/v1" "cosmossdk.io/collections" "cosmossdk.io/core/event" errorsmod "cosmossdk.io/errors" @@ -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.environment.MessageRouterService.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.environment.HeaderService.GetHeaderInfo(ctx).Time, ) validator, err = validator.SetInitialCommission(commission) diff --git a/x/upgrade/keeper/abci.go b/x/upgrade/keeper/abci.go index cd867f9f654b..05ea254ea48f 100644 --- a/x/upgrade/keeper/abci.go +++ b/x/upgrade/keeper/abci.go @@ -6,6 +6,7 @@ import ( "fmt" "time" + consensusv1 "cosmossdk.io/api/cosmos/consensus/v1" "cosmossdk.io/core/appmodule" storetypes "cosmossdk.io/store/types" "cosmossdk.io/x/upgrade/types" @@ -49,9 +50,12 @@ func (k Keeper) PreBlocker(ctx context.Context) (appmodule.ResponsePreBlock, err 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.environment.MessageRouterService.InvokeTyped(ctx, &consensusv1.QueryParamsRequest{}, &res); err != nil { + return nil, errors.New("failed to query consensus params") + } + if res.Params.Version != nil { + appVersion = res.Params.Version.App } return nil, fmt.Errorf("wrong app version %d, upgrade handler is missing for %s upgrade plan", appVersion, lastAppliedPlan) From c68b7679ad76b177368a76e90e5fdc9ad58c2b72 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Thu, 29 Feb 2024 12:11:43 +0100 Subject: [PATCH 13/39] fix lint --- runtime/router_test.go | 4 +++- types/context.go | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/runtime/router_test.go b/runtime/router_test.go index dd9bec43c4d8..ad276cb2a15d 100644 --- a/runtime/router_test.go +++ b/runtime/router_test.go @@ -3,17 +3,19 @@ package runtime_test import ( "testing" + "github.com/stretchr/testify/require" + bankv1beta1 "cosmossdk.io/api/cosmos/bank/v1beta1" counterv1 "cosmossdk.io/api/cosmos/counter/v1" "cosmossdk.io/log" storetypes "cosmossdk.io/store/types" + "github.com/cosmos/cosmos-sdk/baseapp" codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil" counterkeeper "github.com/cosmos/cosmos-sdk/x/counter/keeper" countertypes "github.com/cosmos/cosmos-sdk/x/counter/types" - "github.com/stretchr/testify/require" ) func TestMsgRouterService(t *testing.T) { diff --git a/types/context.go b/types/context.go index f9adf4ff0d08..649b95a129c3 100644 --- a/types/context.go +++ b/types/context.go @@ -104,7 +104,7 @@ func (c Context) HeaderHash() []byte { return hash } -// DEPRECATED: getting consensus params from the context is deprecated and will be removed after 0.51 +// 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 From 29223e36229a8731cf05278f36157a6275faebc0 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Mon, 4 Mar 2024 13:56:19 +0100 Subject: [PATCH 14/39] fix things --- x/auth/ante/setup.go | 2 +- x/evidence/keeper/infraction.go | 2 +- x/staking/keeper/msg_server.go | 2 +- x/upgrade/keeper/abci.go | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/x/auth/ante/setup.go b/x/auth/ante/setup.go index db138867becc..c370fbdb4b27 100644 --- a/x/auth/ante/setup.go +++ b/x/auth/ante/setup.go @@ -47,7 +47,7 @@ func (sud SetUpContextDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, _ bool, // TODO: possibly cache the result of this query for other antehandlers to use var res consensusv1.QueryParamsResponse - if err := sud.env.MessageRouterService.InvokeTyped(ctx, &consensusv1.QueryParamsRequest{}, &res); err != nil { + if err := sud.env.RouterService.InvokeTyped(ctx, &consensusv1.QueryParamsRequest{}, &res); err != nil { return newCtx, err } diff --git a/x/evidence/keeper/infraction.go b/x/evidence/keeper/infraction.go index 58b13fa0d385..946a44f9eff8 100644 --- a/x/evidence/keeper/infraction.go +++ b/x/evidence/keeper/infraction.go @@ -75,7 +75,7 @@ func (k Keeper) handleEquivocationEvidence(ctx context.Context, evidence *types. // if the difference in time and number of blocks is greater than the allowed // parameters defined. var res consensusv1.QueryParamsResponse - if err := k.environment.MessageRouterService.InvokeTyped(ctx, &consensusv1.QueryParamsRequest{}, &res); err != nil { + if err := k.environment.RouterService.InvokeTyped(ctx, &consensusv1.QueryParamsRequest{}, &res); err != nil { return fmt.Errorf("failed to query consensus params: %w", err) } if res.Params.Evidence != nil { diff --git a/x/staking/keeper/msg_server.go b/x/staking/keeper/msg_server.go index 968ac86889b1..6fc0fb7a284d 100644 --- a/x/staking/keeper/msg_server.go +++ b/x/staking/keeper/msg_server.go @@ -69,7 +69,7 @@ func (k msgServer) CreateValidator(ctx context.Context, msg *types.MsgCreateVali } res := consensusv1.QueryParamsResponse{} - if err := k.environment.MessageRouterService.InvokeTyped(ctx, &consensusv1.QueryParamsRequest{}, &res); err != nil { + if err := k.environment.RouterService.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 { diff --git a/x/upgrade/keeper/abci.go b/x/upgrade/keeper/abci.go index 05ea254ea48f..25ac661ef265 100644 --- a/x/upgrade/keeper/abci.go +++ b/x/upgrade/keeper/abci.go @@ -51,7 +51,7 @@ func (k Keeper) PreBlocker(ctx context.Context) (appmodule.ResponsePreBlock, err var appVersion uint64 var res consensusv1.QueryParamsResponse - if err := k.environment.MessageRouterService.InvokeTyped(ctx, &consensusv1.QueryParamsRequest{}, &res); err != nil { + if err := k.environment.RouterService.InvokeTyped(ctx, &consensusv1.QueryParamsRequest{}, &res); err != nil { return nil, errors.New("failed to query consensus params") } if res.Params.Version != nil { From 2b1c3c831169422b64aab57882879e889c170779 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Mon, 4 Mar 2024 13:59:28 +0100 Subject: [PATCH 15/39] fix import --- x/auth/ante/setup.go | 2 +- x/evidence/keeper/infraction.go | 2 +- x/staking/keeper/msg_server.go | 2 +- x/upgrade/keeper/abci.go | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/x/auth/ante/setup.go b/x/auth/ante/setup.go index c370fbdb4b27..98a6ee83583b 100644 --- a/x/auth/ante/setup.go +++ b/x/auth/ante/setup.go @@ -47,7 +47,7 @@ func (sud SetUpContextDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, _ bool, // TODO: possibly cache the result of this query for other antehandlers to use var res consensusv1.QueryParamsResponse - if err := sud.env.RouterService.InvokeTyped(ctx, &consensusv1.QueryParamsRequest{}, &res); err != nil { + if err := sud.env.RouterService.QueryRouterService().InvokeTyped(ctx, &consensusv1.QueryParamsRequest{}, &res); err != nil { return newCtx, err } diff --git a/x/evidence/keeper/infraction.go b/x/evidence/keeper/infraction.go index 946a44f9eff8..1424811b3683 100644 --- a/x/evidence/keeper/infraction.go +++ b/x/evidence/keeper/infraction.go @@ -75,7 +75,7 @@ func (k Keeper) handleEquivocationEvidence(ctx context.Context, evidence *types. // if the difference in time and number of blocks is greater than the allowed // parameters defined. var res consensusv1.QueryParamsResponse - if err := k.environment.RouterService.InvokeTyped(ctx, &consensusv1.QueryParamsRequest{}, &res); err != nil { + if err := k.environment.RouterService.QueryRouterService().InvokeTyped(ctx, &consensusv1.QueryParamsRequest{}, &res); err != nil { return fmt.Errorf("failed to query consensus params: %w", err) } if res.Params.Evidence != nil { diff --git a/x/staking/keeper/msg_server.go b/x/staking/keeper/msg_server.go index 6fc0fb7a284d..54eafb7cd0f5 100644 --- a/x/staking/keeper/msg_server.go +++ b/x/staking/keeper/msg_server.go @@ -69,7 +69,7 @@ func (k msgServer) CreateValidator(ctx context.Context, msg *types.MsgCreateVali } res := consensusv1.QueryParamsResponse{} - if err := k.environment.RouterService.InvokeTyped(ctx, &consensusv1.QueryParamsRequest{}, &res); err != nil { + if err := k.environment.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 { diff --git a/x/upgrade/keeper/abci.go b/x/upgrade/keeper/abci.go index 25ac661ef265..02ef1a273e3f 100644 --- a/x/upgrade/keeper/abci.go +++ b/x/upgrade/keeper/abci.go @@ -51,7 +51,7 @@ func (k Keeper) PreBlocker(ctx context.Context) (appmodule.ResponsePreBlock, err var appVersion uint64 var res consensusv1.QueryParamsResponse - if err := k.environment.RouterService.InvokeTyped(ctx, &consensusv1.QueryParamsRequest{}, &res); err != nil { + if err := k.environment.RouterService.QueryRouterService().InvokeTyped(ctx, &consensusv1.QueryParamsRequest{}, &res); err != nil { return nil, errors.New("failed to query consensus params") } if res.Params.Version != nil { From 9d70599219e0d2f69d523b27db1ffc95e3c88cb6 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Tue, 19 Mar 2024 16:44:04 +0100 Subject: [PATCH 16/39] push some changes --- x/gov/testutil/expected_keepers_mocks.go | 5 ++- x/staking/keeper/keeper_test.go | 24 ++++++++++-- x/staking/testutil/expected_keepers_mocks.go | 39 ++++++++++++++++++++ x/staking/types/expected_keepers.go | 5 +++ 4 files changed, 68 insertions(+), 5 deletions(-) diff --git a/x/gov/testutil/expected_keepers_mocks.go b/x/gov/testutil/expected_keepers_mocks.go index 3784d76377cd..ce5ec75f8f5a 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 de6cfe138b5f..ca803b3116f1 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,13 +57,23 @@ 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( + "authz", + log.NewNopLogger(), + testCtx.DB, + encCfg.TxConfig.TxDecoder(), + ) + s.baseApp.SetCMS(testCtx.CMS) + s.baseApp.SetInterfaceRegistry(encCfg.InterfaceRegistry) + + // consensusKeeper := + ctrl := gomock.NewController(s.T()) accountKeeper := stakingtestutil.NewMockAccountKeeper(ctrl) accountKeeper.EXPECT().GetModuleAddress(stakingtypes.BondedPoolName).Return(bondedAcc.GetAddress()) @@ -70,6 +82,12 @@ func (s *KeeperTestSuite) SetupTest() { bankKeeper := stakingtestutil.NewMockBankKeeper(ctrl) + // create consensus keeper + ck := stakingtestutil.NewMockConsensusKeeper(ctrl) + queryHelper := baseapp.NewQueryServerTestHelper(ctx, encCfg.InterfaceRegistry) + consensustypes.RegisterQueryServer(queryHelper, ck) + + env := runtime.NewEnvironment(storeService, log.NewNopLogger(), runtime.EnvWithRouterService(s.baseApp.GRPCQueryRouter(), nil)) keeper := stakingkeeper.NewKeeper( encCfg.Codec, env, @@ -87,8 +105,8 @@ func (s *KeeperTestSuite) SetupTest() { s.accountKeeper = accountKeeper stakingtypes.RegisterInterfaces(encCfg.InterfaceRegistry) - queryHelper := baseapp.NewQueryServerTestHelper(ctx, encCfg.InterfaceRegistry) - stakingtypes.RegisterQueryServer(queryHelper, stakingkeeper.Querier{Keeper: keeper}) + queryHelper2 := baseapp.NewQueryServerTestHelper(ctx, encCfg.InterfaceRegistry) + stakingtypes.RegisterQueryServer(queryHelper2, stakingkeeper.Querier{Keeper: keeper}) s.queryClient = stakingtypes.NewQueryClient(queryHelper) s.msgServer = stakingkeeper.NewMsgServerImpl(keeper) } diff --git a/x/staking/testutil/expected_keepers_mocks.go b/x/staking/testutil/expected_keepers_mocks.go index f1f4cd652f1f..b3f5867f1695 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/staking/types/expected_keepers.go b/x/staking/types/expected_keepers.go index 7b11f9e1ece6..182930e72f80 100644 --- a/x/staking/types/expected_keepers.go +++ b/x/staking/types/expected_keepers.go @@ -11,6 +11,7 @@ import ( cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" + consensustypes "github.com/cosmos/cosmos-sdk/x/consensus/types" ) // AccountKeeper defines the expected account keeper (noalias) @@ -115,3 +116,7 @@ type StakingHooksWrapper struct{ StakingHooks } // IsOnePerModuleType implements the depinject.OnePerModuleType interface. func (StakingHooksWrapper) IsOnePerModuleType() {} + +type ConsensusKeeper interface { + Params(context.Context, *consensustypes.QueryParamsRequest) (*consensustypes.QueryParamsResponse, error) +} From 1cb6f9afdccdb0d9f9d268637784833873917b48 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Tue, 19 Mar 2024 21:14:37 +0100 Subject: [PATCH 17/39] updates --- x/staking/keeper/keeper_test.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/x/staking/keeper/keeper_test.go b/x/staking/keeper/keeper_test.go index ca803b3116f1..91373c113656 100644 --- a/x/staking/keeper/keeper_test.go +++ b/x/staking/keeper/keeper_test.go @@ -64,7 +64,7 @@ func (s *KeeperTestSuite) SetupTest() { s.cdc = encCfg.Codec s.baseApp = baseapp.NewBaseApp( - "authz", + "staking", log.NewNopLogger(), testCtx.DB, encCfg.TxConfig.TxDecoder(), @@ -72,21 +72,19 @@ func (s *KeeperTestSuite) SetupTest() { s.baseApp.SetCMS(testCtx.CMS) s.baseApp.SetInterfaceRegistry(encCfg.InterfaceRegistry) - // consensusKeeper := - 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() - bankKeeper := stakingtestutil.NewMockBankKeeper(ctrl) - // create consensus keeper ck := stakingtestutil.NewMockConsensusKeeper(ctrl) queryHelper := baseapp.NewQueryServerTestHelper(ctx, encCfg.InterfaceRegistry) consensustypes.RegisterQueryServer(queryHelper, ck) + bankKeeper := stakingtestutil.NewMockBankKeeper(ctrl) + env := runtime.NewEnvironment(storeService, log.NewNopLogger(), runtime.EnvWithRouterService(s.baseApp.GRPCQueryRouter(), nil)) keeper := stakingkeeper.NewKeeper( encCfg.Codec, From d6cdc35ae232d8304e3ee69b2fa22b2b2d547417 Mon Sep 17 00:00:00 2001 From: Facundo Date: Wed, 3 Apr 2024 00:41:13 +0200 Subject: [PATCH 18/39] fix most tests --- orm/model/ormdb/module.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 | 1 + testutil/integration/router.go | 19 ++++++- testutil/sims/app_helpers.go | 4 ++ x/auth/ante/ante_test.go | 1 + x/auth/ante/expected_keepers.go | 5 ++ x/auth/ante/setup_test.go | 12 ++--- .../ante/testutil/expected_keepers_mocks.go | 39 +++++++++++++++ x/auth/ante/testutil_test.go | 38 ++++++++++---- x/auth/tx/config/depinject.go | 3 ++ x/gov/keeper/common_test.go | 11 ++++- x/staking/keeper/keeper_test.go | 8 +-- x/upgrade/keeper/abci_test.go | 49 ++++++++----------- 21 files changed, 204 insertions(+), 74 deletions(-) diff --git a/orm/model/ormdb/module.go b/orm/model/ormdb/module.go index 605e641729ad..5b9082fd1f0d 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 // TODO should be appmodule.HasGenesisAuto with core v1 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 { // TODO should be appmodule.HasGenesisAuto with core v1 return appModuleGenesisWrapper{m} } diff --git a/tests/integration/bank/keeper/deterministic_test.go b/tests/integration/bank/keeper/deterministic_test.go index 635e061dd915..8c1b5a00595d 100644 --- a/tests/integration/bank/keeper/deterministic_test.go +++ b/tests/integration/bank/keeper/deterministic_test.go @@ -22,6 +22,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" @@ -92,7 +93,6 @@ func initDeterministicFixture(t *testing.T) *deterministicFixture { accountKeeper.GetAuthority(): false, } bankKeeper := keeper.NewBaseKeeper( - runtime.NewEnvironment(runtime.NewKVStoreService(keys[banktypes.StoreKey]), log.NewNopLogger()), cdc, accountKeeper, @@ -109,7 +109,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 962d6c8779e9..8fc09c224f5f 100644 --- a/tests/integration/distribution/keeper/msg_server_test.go +++ b/tests/integration/distribution/keeper/msg_server_test.go @@ -31,6 +31,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 ( "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 ( @@ -66,6 +68,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 @@ -106,7 +109,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()) @@ -149,7 +155,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 4dcc9b3e8298..d26aef8a0485 100644 --- a/tests/integration/evidence/keeper/infraction_test.go +++ b/tests/integration/evidence/keeper/infraction_test.go @@ -39,6 +39,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" @@ -90,6 +91,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) @@ -126,13 +129,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) @@ -152,7 +155,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 e921c175021b..b463422d245e 100644 --- a/tests/integration/example/example_test.go +++ b/tests/integration/example/example_test.go @@ -17,6 +17,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" @@ -72,6 +73,8 @@ func Example() { authtypes.ModuleName: authModule, minttypes.ModuleName: mintModule, }, + baseapp.NewMsgServiceRouter(), + baseapp.NewGRPCQueryRouter(), ) // register the message and query servers @@ -157,6 +160,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 1a7b2608163c..fe39dcae8fd6 100644 --- a/tests/integration/gov/keeper/keeper_test.go +++ b/tests/integration/gov/keeper/keeper_test.go @@ -138,7 +138,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 a74665167221..5ecf9f06efe0 100644 --- a/tests/integration/slashing/keeper/keeper_test.go +++ b/tests/integration/slashing/keeper/keeper_test.go @@ -28,6 +28,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" @@ -36,6 +37,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 { @@ -55,7 +57,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 @@ -73,8 +75,11 @@ func initFixture(tb testing.TB) *fixture { stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking}, } + msgRouter := baseapp.NewMsgServiceRouter() + queryRouter := baseapp.NewGRPCQueryRouter() + 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, maccPerms, @@ -87,16 +92,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) @@ -109,7 +114,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 f864019603c0..90ead9ce8473 100644 --- a/tests/integration/staking/keeper/common_test.go +++ b/tests/integration/staking/keeper/common_test.go @@ -23,7 +23,9 @@ import ( stakingkeeper "cosmossdk.io/x/staking/keeper" "cosmossdk.io/x/staking/testutil" "cosmossdk.io/x/staking/types" + consensustypes "github.com/cosmos/cosmos-sdk/x/consensus/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" @@ -102,11 +104,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) @@ -123,7 +128,7 @@ func initFixture(tb testing.TB) *fixture { } 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, maccPerms, @@ -143,7 +148,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, authsims.RandomGenesisAccounts) bankModule := bank.NewAppModule(cdc, bankKeeper, accountKeeper) @@ -156,7 +161,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 cc8c2fbae654..dcd4ced94af3 100644 --- a/tests/integration/staking/keeper/deterministic_test.go +++ b/tests/integration/staking/keeper/deterministic_test.go @@ -25,6 +25,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" @@ -120,7 +121,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 41e9fb1feb04..7f0574123d13 100644 --- a/tests/sims/feegrant/operations_test.go +++ b/tests/sims/feegrant/operations_test.go @@ -86,6 +86,7 @@ func (suite *SimTestSuite) getTestingAccounts(r *rand.Rand, n int) []simtypes.Ac // add coins to the accounts for _, account := range accounts { + suite.accountKeeper.NewAccountWithAddress(suite.ctx, account.Address) err := banktestutil.FundAccount(suite.ctx, suite.bankKeeper, account.Address, initCoins) suite.Require().NoError(err) } diff --git a/testutil/integration/router.go b/testutil/integration/router.go index 9bf25657cff7..94262363726a 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 c97b70c0a0b0..3aadc2084238 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/x/auth/ante/ante_test.go b/x/auth/ante/ante_test.go index 5c26213f59b6..7377638550a6 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/expected_keepers.go b/x/auth/ante/expected_keepers.go index c33dcaa685d3..85abb7b202a2 100644 --- a/x/auth/ante/expected_keepers.go +++ b/x/auth/ante/expected_keepers.go @@ -5,6 +5,7 @@ import ( "cosmossdk.io/core/address" "cosmossdk.io/x/auth/types" + consensustypes "github.com/cosmos/cosmos-sdk/x/consensus/types" sdk "github.com/cosmos/cosmos-sdk/types" ) @@ -24,3 +25,7 @@ type AccountKeeper interface { type FeegrantKeeper interface { UseGrantedFees(ctx context.Context, granter, grantee sdk.AccAddress, fee sdk.Coins, msgs []sdk.Msg) error } + +type ConsensusKeeper interface { + Params(context.Context, *consensustypes.QueryParamsRequest) (*consensustypes.QueryParamsResponse, error) +} diff --git a/x/auth/ante/setup_test.go b/x/auth/ante/setup_test.go index fcaaf8b59077..3051c6b8f20f 100644 --- a/x/auth/ante/setup_test.go +++ b/x/auth/ante/setup_test.go @@ -6,12 +6,10 @@ import ( cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/stretchr/testify/require" - "cosmossdk.io/log" storetypes "cosmossdk.io/store/types" "cosmossdk.io/x/auth/ante" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" - "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -30,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(runtime.NewEnvironment(nil, log.NewNopLogger())) + 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, }, @@ -71,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(runtime.NewEnvironment(nil, log.NewNopLogger())) + sud := ante.NewSetUpContextDecorator(suite.env) antehandler := sdk.ChainAnteDecorators(sud) // Set height to non-zero value for GasMeter to be set @@ -106,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(runtime.NewEnvironment(nil, log.NewNopLogger())) + 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 091ae6477359..325b99804ca3 100644 --- a/x/auth/ante/testutil/expected_keepers_mocks.go +++ b/x/auth/ante/testutil/expected_keepers_mocks.go @@ -11,6 +11,7 @@ import ( address "cosmossdk.io/core/address" 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" ) @@ -155,3 +156,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 1814e94f2b29..63d0dc535596 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,15 +49,17 @@ 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 - txBankKeeper *txtestutil.MockBankKeeper - feeGrantKeeper *antetestutil.MockFeegrantKeeper - encCfg moduletestutil.TestEncodingConfig + anteHandler sdk.AnteHandler + ctx sdk.Context + clientCtx client.Context + txBuilder client.TxBuilder + accountKeeper keeper.AccountKeeper + bankKeeper *authtestutil.MockBankKeeper + txBankKeeper *txtestutil.MockBankKeeper + feeGrantKeeper *antetestutil.MockFeegrantKeeper + consensusKeeper *antetestutil.MockConsensusKeeper + encCfg moduletestutil.TestEncodingConfig + env appmodule.Environment } // SetupTest setups a new test, with new app, context, and anteHandler. @@ -79,8 +85,19 @@ 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, maccPerms, authcodec.NewBech32Codec("cosmos"), + suite.env, suite.encCfg.Codec, types.ProtoBaseAccount, maccPerms, authcodec.NewBech32Codec("cosmos"), sdk.Bech32MainPrefix, types.NewModuleAddress("gov").String(), ) suite.accountKeeper.GetModuleAccount(suite.ctx, types.FeeCollectorName) @@ -102,6 +119,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 47009c706e1e..82988b09d82c 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/gov/keeper/common_test.go b/x/gov/keeper/common_test.go index 1ab164143397..dd83cb30a066 100644 --- a/x/gov/keeper/common_test.go +++ b/x/gov/keeper/common_test.go @@ -44,7 +44,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. @@ -68,7 +68,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/staking/keeper/keeper_test.go b/x/staking/keeper/keeper_test.go index 91373c113656..b414eb7e9eb2 100644 --- a/x/staking/keeper/keeper_test.go +++ b/x/staking/keeper/keeper_test.go @@ -80,12 +80,15 @@ func (s *KeeperTestSuite) SetupTest() { // 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(s.baseApp.GRPCQueryRouter(), nil)) + env := runtime.NewEnvironment(storeService, log.NewNopLogger(), runtime.EnvWithRouterService(queryHelper.GRPCQueryRouter, s.baseApp.MsgServiceRouter())) keeper := stakingkeeper.NewKeeper( encCfg.Codec, env, @@ -103,8 +106,7 @@ func (s *KeeperTestSuite) SetupTest() { s.accountKeeper = accountKeeper stakingtypes.RegisterInterfaces(encCfg.InterfaceRegistry) - queryHelper2 := baseapp.NewQueryServerTestHelper(ctx, encCfg.InterfaceRegistry) - stakingtypes.RegisterQueryServer(queryHelper2, stakingkeeper.Querier{Keeper: keeper}) + stakingtypes.RegisterQueryServer(queryHelper, stakingkeeper.Querier{Keeper: keeper}) s.queryClient = stakingtypes.NewQueryClient(queryHelper) s.msgServer = stakingkeeper.NewMsgServerImpl(keeper) } diff --git a/x/upgrade/keeper/abci_test.go b/x/upgrade/keeper/abci_test.go index 66c10f3cbd43..8b3c7849debf 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 From 3d9756666eb2297706fd86842560a5d0cfc18843 Mon Sep 17 00:00:00 2001 From: Facundo Date: Wed, 3 Apr 2024 13:07:01 +0200 Subject: [PATCH 19/39] fix more tests --- tests/sims/feegrant/operations_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/sims/feegrant/operations_test.go b/tests/sims/feegrant/operations_test.go index 7f0574123d13..4a5214ee5294 100644 --- a/tests/sims/feegrant/operations_test.go +++ b/tests/sims/feegrant/operations_test.go @@ -86,7 +86,7 @@ func (suite *SimTestSuite) getTestingAccounts(r *rand.Rand, n int) []simtypes.Ac // add coins to the accounts for _, account := range accounts { - suite.accountKeeper.NewAccountWithAddress(suite.ctx, account.Address) + suite.accountKeeper.SetAccount(suite.ctx, suite.accountKeeper.NewAccountWithAddress(suite.ctx, account.Address)) err := banktestutil.FundAccount(suite.ctx, suite.bankKeeper, account.Address, initCoins) suite.Require().NoError(err) } From 42cf7581aa1682bf24279e8b7c183c851d3a4626 Mon Sep 17 00:00:00 2001 From: Facundo Date: Wed, 3 Apr 2024 17:43:35 +0200 Subject: [PATCH 20/39] fix lint --- x/accounts/defaults/lockup/lockup.go | 5 +++-- x/accounts/defaults/lockup/protov2_wrapper.go | 6 ++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/x/accounts/defaults/lockup/lockup.go b/x/accounts/defaults/lockup/lockup.go index 6917f2407b5d..b991f28c3e8b 100644 --- a/x/accounts/defaults/lockup/lockup.go +++ b/x/accounts/defaults/lockup/lockup.go @@ -6,6 +6,8 @@ import ( "fmt" "time" + "github.com/cosmos/gogoproto/proto" + "cosmossdk.io/collections" collcodec "cosmossdk.io/collections/codec" "cosmossdk.io/core/address" @@ -15,9 +17,8 @@ import ( "cosmossdk.io/x/accounts/accountstd" lockuptypes "cosmossdk.io/x/accounts/defaults/lockup/types" banktypes "cosmossdk.io/x/bank/types" - codectypes "github.com/cosmos/cosmos-sdk/codec/types" - "github.com/cosmos/gogoproto/proto" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ) diff --git a/x/accounts/defaults/lockup/protov2_wrapper.go b/x/accounts/defaults/lockup/protov2_wrapper.go index 782f9e301594..caee0c60398f 100644 --- a/x/accounts/defaults/lockup/protov2_wrapper.go +++ b/x/accounts/defaults/lockup/protov2_wrapper.go @@ -1,12 +1,14 @@ package lockup import ( + "google.golang.org/protobuf/proto" + "google.golang.org/protobuf/runtime/protoiface" + bankv1beta1 "cosmossdk.io/api/cosmos/bank/v1beta1" v1beta1 "cosmossdk.io/api/cosmos/base/v1beta1" stakingv1beta1 "cosmossdk.io/api/cosmos/staking/v1beta1" + sdk "github.com/cosmos/cosmos-sdk/types" - "google.golang.org/protobuf/proto" - "google.golang.org/protobuf/runtime/protoiface" ) type ProtoMsg = protoiface.MessageV1 From c3b1f3eafd4287e919f298730bf0f55adb349fea Mon Sep 17 00:00:00 2001 From: Facundo Date: Wed, 3 Apr 2024 18:13:52 +0200 Subject: [PATCH 21/39] fix legacy simapp tests --- go.mod | 2 +- go.sum | 2 ++ simapp/app.go | 4 ++-- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index d49e7d1d18b9..a3b147af966a 100644 --- a/go.mod +++ b/go.mod @@ -189,7 +189,7 @@ replace ( cosmossdk.io/x/staking => ./x/staking ) -replace github.com/cosmos/iavl => github.com/cosmos/iavl v1.0.1 // TODO remove +// 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 ( diff --git a/go.sum b/go.sum index 6698d47da21c..8527313166bf 100644 --- a/go.sum +++ b/go.sum @@ -148,6 +148,8 @@ github.com/cosmos/gogoproto v1.4.12 h1:vB6Lbe/rtnYGjQuFxkPiPYiCybqFT8QvLipDZP8Jp github.com/cosmos/gogoproto v1.4.12/go.mod h1:LnZob1bXRdUoqMMtwYlcR3wjiElmlC+FkjaZRv1/eLY= github.com/cosmos/iavl v1.0.1 h1:D+mYbcRO2wptYzOM1Hxl9cpmmHU1ZEt9T2Wv5nZTeUw= github.com/cosmos/iavl v1.0.1/go.mod h1:8xIUkgVvwvVrBu81scdPty+/Dx9GqwHnAvXz4cwF7RY= +github.com/cosmos/iavl v1.1.1 h1:64nTi8s3gEoGqhA8TyAWFWfz7/pg0anKzHNSc1ETc7Q= +github.com/cosmos/iavl v1.1.1/go.mod h1:jLeUvm6bGT1YutCaL2fIar/8vGUE8cPZvh/gXEWDaDM= github.com/cosmos/ics23/go v0.10.0 h1:iXqLLgp2Lp+EdpIuwXTYIQU+AiHj9mOC2X9ab++bZDM= github.com/cosmos/ics23/go v0.10.0/go.mod h1:ZfJSmng/TBNTBkFemHHHj5YY7VAU/MBU980F4VU1NG0= github.com/cosmos/keyring v1.2.0 h1:8C1lBP9xhImmIabyXW4c3vFjjLiBdGCmfLUfeZlV1Yo= diff --git a/simapp/app.go b/simapp/app.go index 9d71f4b73ff1..50bf4076a5ab 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -337,7 +337,7 @@ func NewSimApp( app.txConfig = txConfig app.StakingKeeper = stakingkeeper.NewKeeper( - appCodec, runtime.NewEnvironment(runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), logger), app.AuthKeeper, app.BankKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(), signingCtx.ValidatorAddressCodec(), authcodec.NewBech32Codec(sdk.Bech32PrefixConsAddr), + appCodec, runtime.NewEnvironment(runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), logger, 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), app.StakingKeeper, app.AuthKeeper, app.BankKeeper, authtypes.FeeCollectorName, authtypes.NewModuleAddress(govtypes.ModuleName).String()) @@ -583,7 +583,7 @@ func (app *SimApp) setAnteHandler(txConfig client.TxConfig) { anteHandler, err := NewAnteHandler( HandlerOptions{ ante.HandlerOptions{ - Environment: runtime.NewEnvironment(nil, app.logger), // nil is set as the kvstoreservice to avoid module access + 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, From 0e13333576a31d04775191a9846297c7c0f39c04 Mon Sep 17 00:00:00 2001 From: Facundo Date: Wed, 3 Apr 2024 18:26:55 +0200 Subject: [PATCH 22/39] mod tidy --- go.sum | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/go.sum b/go.sum index 8527313166bf..cd1c13a4f067 100644 --- a/go.sum +++ b/go.sum @@ -146,10 +146,8 @@ github.com/cosmos/gogogateway v1.2.0/go.mod h1:iQpLkGWxYcnCdz5iAdLcRBSw3h7NXeOkZ github.com/cosmos/gogoproto v1.4.2/go.mod h1:cLxOsn1ljAHSV527CHOtaIP91kK6cCrZETRBrkzItWU= github.com/cosmos/gogoproto v1.4.12 h1:vB6Lbe/rtnYGjQuFxkPiPYiCybqFT8QvLipDZP8JpFE= github.com/cosmos/gogoproto v1.4.12/go.mod h1:LnZob1bXRdUoqMMtwYlcR3wjiElmlC+FkjaZRv1/eLY= -github.com/cosmos/iavl v1.0.1 h1:D+mYbcRO2wptYzOM1Hxl9cpmmHU1ZEt9T2Wv5nZTeUw= -github.com/cosmos/iavl v1.0.1/go.mod h1:8xIUkgVvwvVrBu81scdPty+/Dx9GqwHnAvXz4cwF7RY= -github.com/cosmos/iavl v1.1.1 h1:64nTi8s3gEoGqhA8TyAWFWfz7/pg0anKzHNSc1ETc7Q= -github.com/cosmos/iavl v1.1.1/go.mod h1:jLeUvm6bGT1YutCaL2fIar/8vGUE8cPZvh/gXEWDaDM= +github.com/cosmos/iavl v1.0.0 h1:bw6t0Mv/mVCJvlMTOPHWLs5uUE3BRBfVWCRelOzl+so= +github.com/cosmos/iavl v1.0.0/go.mod h1:CmTGqMnRnucjxbjduneZXT+0vPgNElYvdefjX2q9tYc= github.com/cosmos/ics23/go v0.10.0 h1:iXqLLgp2Lp+EdpIuwXTYIQU+AiHj9mOC2X9ab++bZDM= github.com/cosmos/ics23/go v0.10.0/go.mod h1:ZfJSmng/TBNTBkFemHHHj5YY7VAU/MBU980F4VU1NG0= github.com/cosmos/keyring v1.2.0 h1:8C1lBP9xhImmIabyXW4c3vFjjLiBdGCmfLUfeZlV1Yo= From cec0d7f75d86b85e10c24d76527865bd90844f4c Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Thu, 4 Apr 2024 09:50:11 +0900 Subject: [PATCH 23/39] linting --- tests/integration/staking/keeper/common_test.go | 2 +- x/auth/ante/expected_keepers.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/integration/staking/keeper/common_test.go b/tests/integration/staking/keeper/common_test.go index 90ead9ce8473..affc17b01383 100644 --- a/tests/integration/staking/keeper/common_test.go +++ b/tests/integration/staking/keeper/common_test.go @@ -23,7 +23,6 @@ import ( stakingkeeper "cosmossdk.io/x/staking/keeper" "cosmossdk.io/x/staking/testutil" "cosmossdk.io/x/staking/types" - consensustypes "github.com/cosmos/cosmos-sdk/x/consensus/types" "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" @@ -34,6 +33,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) diff --git a/x/auth/ante/expected_keepers.go b/x/auth/ante/expected_keepers.go index 85abb7b202a2..52ea0dbac9f6 100644 --- a/x/auth/ante/expected_keepers.go +++ b/x/auth/ante/expected_keepers.go @@ -5,9 +5,9 @@ import ( "cosmossdk.io/core/address" "cosmossdk.io/x/auth/types" - consensustypes "github.com/cosmos/cosmos-sdk/x/consensus/types" sdk "github.com/cosmos/cosmos-sdk/types" + consensustypes "github.com/cosmos/cosmos-sdk/x/consensus/types" ) // AccountKeeper defines the contract needed for AccountKeeper related APIs. From 3ba007a6abe8dac138792fd786298aede41d0f5a Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Thu, 4 Apr 2024 23:25:14 +0900 Subject: [PATCH 24/39] changelog and fix db test --- store/db/db_test.go | 9 --------- store/db/rocksdb_test.go | 20 ++++++++++++++++++++ x/auth/CHANGELOG.md | 1 + 3 files changed, 21 insertions(+), 9 deletions(-) create mode 100644 store/db/rocksdb_test.go diff --git a/store/db/db_test.go b/store/db/db_test.go index 39ef0403d74b..cad62a426445 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 000000000000..75147a56855d --- /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/x/auth/CHANGELOG.md b/x/auth/CHANGELOG.md index 585075a9d39e..fd18194b91da 100644 --- a/x/auth/CHANGELOG.md +++ b/x/auth/CHANGELOG.md @@ -49,6 +49,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 From 4b13f047a9d31de5851d8302980dc191ae394e6c Mon Sep 17 00:00:00 2001 From: Facundo Date: Thu, 4 Apr 2024 16:40:11 +0200 Subject: [PATCH 25/39] fix --- x/gov/go.mod | 1 + x/gov/go.sum | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/x/gov/go.mod b/x/gov/go.mod index 52c80772a3f4..3475fd8062f1 100644 --- a/x/gov/go.mod +++ b/x/gov/go.mod @@ -177,5 +177,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 9dd0fa597675..21ad41099f6d 100644 --- a/x/gov/go.sum +++ b/x/gov/go.sum @@ -14,8 +14,6 @@ cosmossdk.io/math v1.3.0 h1:RC+jryuKeytIiictDslBP9i1fhkVm6ZDmZEoNP316zE= cosmossdk.io/math v1.3.0/go.mod h1:vnRTxewy+M7BtXBNFybkuhSH4WfedVAAnERHgVFhp3k= 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/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.1 h1:Mg+EMp67Pz+NukbJqYxuo8uRp7N/a9uR+oVS9pONtj8= cosmossdk.io/x/tx v0.13.1/go.mod h1:CBCU6fsRVz23QGFIQBb1DNX2DztJCf3jWyEkHY2nJQ0= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= From 9104f146abfe415d986c53673d3c2881ab2663a9 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Mon, 15 Apr 2024 13:49:58 +0200 Subject: [PATCH 26/39] fixes --- simapp/app_config.go | 1 - simapp/app_di.go | 2 +- simapp/upgrades.go | 1 + store/db/db.go | 6 ++-- store/db/rocksdb_noflag.go | 36 ------------------- .../auth/keeper/msg_server_test.go | 2 +- .../slashing/keeper/keeper_test.go | 4 +++ x/auth/ante/testutil_test.go | 28 +++++++-------- 8 files changed, 22 insertions(+), 58 deletions(-) diff --git a/simapp/app_config.go b/simapp/app_config.go index 1ac042beaa76..95d978c7a6cc 100644 --- a/simapp/app_config.go +++ b/simapp/app_config.go @@ -31,7 +31,6 @@ import ( vestingmodulev1 "cosmossdk.io/api/cosmos/vesting/module/v1" "cosmossdk.io/depinject/appconfig" "cosmossdk.io/x/accounts" - _ "cosmossdk.io/x/accounts" // import for side-effects _ "cosmossdk.io/x/auth/tx/config" // import for side-effects authtypes "cosmossdk.io/x/auth/types" _ "cosmossdk.io/x/auth/vesting" // import for side-effects diff --git a/simapp/app_di.go b/simapp/app_di.go index 2630778ebbc2..997565a4b1dc 100644 --- a/simapp/app_di.go +++ b/simapp/app_di.go @@ -306,7 +306,7 @@ func NewSimApp( return app } -// overwritte default ante handlers with custom ante handlers +// overwrite default ante handlers with custom ante handlers // set SkipAnteHandler to true in app config and set custom ante handler on baseapp func (app *SimApp) setCustomAnteHandler() { anteHandler, err := NewAnteHandler( diff --git a/simapp/upgrades.go b/simapp/upgrades.go index 4351e99f1063..ed6d35c0b490 100644 --- a/simapp/upgrades.go +++ b/simapp/upgrades.go @@ -8,6 +8,7 @@ import ( epochstypes "cosmossdk.io/x/epochs/types" protocolpooltypes "cosmossdk.io/x/protocolpool/types" upgradetypes "cosmossdk.io/x/upgrade/types" + "github.com/cosmos/cosmos-sdk/types/module" crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types" ) diff --git a/store/db/db.go b/store/db/db.go index dbbe25068ff4..e24c6e66c72c 100644 --- a/store/db/db.go +++ b/store/db/db.go @@ -10,9 +10,9 @@ type RawDBType string const ( DBTypeGoLevelDB RawDBType = "goleveldb" - DBTypeRocksDB = "rocksdb" - DBTypePebbleDB = "pebbledb" - DBTypePrefixDB = "prefixdb" + DBTypeRocksDB RawDBType = "rocksdb" + DBTypePebbleDB RawDBType = "pebbledb" + DBTypePrefixDB RawDBType = "prefixdb" DBFileSuffix string = ".db" ) diff --git a/store/db/rocksdb_noflag.go b/store/db/rocksdb_noflag.go index 100171a077ce..8ad44e66f926 100644 --- a/store/db/rocksdb_noflag.go +++ b/store/db/rocksdb_noflag.go @@ -50,39 +50,3 @@ func (db *RocksDB) NewBatch() store.RawBatch { func (db *RocksDB) NewBatchWithSize(_ int) store.RawBatch { return db.NewBatch() } - -var _ corestore.Iterator = (*rocksDBIterator)(nil) - -type rocksDBIterator struct{} - -func (itr *rocksDBIterator) Domain() (start, end []byte) { - panic("rocksdb must be built with -tags rocksdb") -} - -func (itr *rocksDBIterator) Valid() bool { - panic("rocksdb must be built with -tags rocksdb") -} - -func (itr *rocksDBIterator) Key() []byte { - panic("rocksdb must be built with -tags rocksdb") -} - -func (itr *rocksDBIterator) Value() []byte { - panic("rocksdb must be built with -tags rocksdb") -} - -func (itr *rocksDBIterator) Next() { - panic("rocksdb must be built with -tags rocksdb") -} - -func (itr *rocksDBIterator) Error() error { - panic("rocksdb must be built with -tags rocksdb") -} - -func (itr *rocksDBIterator) Close() error { - panic("rocksdb must be built with -tags rocksdb") -} - -func (itr *rocksDBIterator) assertIsValid() { - panic("rocksdb must be built with -tags rocksdb") -} diff --git a/tests/integration/auth/keeper/msg_server_test.go b/tests/integration/auth/keeper/msg_server_test.go index b7ae43e00c1d..a4610f22bddb 100644 --- a/tests/integration/auth/keeper/msg_server_test.go +++ b/tests/integration/auth/keeper/msg_server_test.go @@ -131,7 +131,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/slashing/keeper/keeper_test.go b/tests/integration/slashing/keeper/keeper_test.go index e2ae716d6932..294dbbccb8ee 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" @@ -76,6 +77,9 @@ 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) diff --git a/x/auth/ante/testutil_test.go b/x/auth/ante/testutil_test.go index cbb210fc2f76..ce2f76f50875 100644 --- a/x/auth/ante/testutil_test.go +++ b/x/auth/ante/testutil_test.go @@ -49,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. @@ -98,13 +100,7 @@ func SetupTestSuite(t *testing.T, isCheckTx bool) *AnteTestSuite { suite.env = runtime.NewEnvironment(runtime.NewKVStoreService(key), log.NewNopLogger(), runtime.EnvWithRouterService(grpcQueryRouter, msgRouter)) suite.accountKeeper = keeper.NewAccountKeeper( -<<<<<<< HEAD - suite.env, suite.encCfg.Codec, types.ProtoBaseAccount, maccPerms, authcodec.NewBech32Codec("cosmos"), -||||||| edd1c71072 - runtime.NewEnvironment(runtime.NewKVStoreService(key), log.NewNopLogger()), suite.encCfg.Codec, types.ProtoBaseAccount, maccPerms, authcodec.NewBech32Codec("cosmos"), -======= runtime.NewEnvironment(runtime.NewKVStoreService(key), log.NewNopLogger()), suite.encCfg.Codec, types.ProtoBaseAccount, suite.acctsModKeeper, maccPerms, authcodec.NewBech32Codec("cosmos"), ->>>>>>> main sdk.Bech32MainPrefix, types.NewModuleAddress("gov").String(), ) suite.accountKeeper.GetModuleAccount(suite.ctx, types.FeeCollectorName) From 2e0439236c6d77d9dacf0a4b3c4aebf763f1634c Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Mon, 15 Apr 2024 13:52:09 +0200 Subject: [PATCH 27/39] linting --- baseapp/abci_test.go | 2 +- baseapp/abci_utils.go | 6 +++--- .../auth/keeper/msg_server_test.go | 20 +++++++++---------- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/baseapp/abci_test.go b/baseapp/abci_test.go index 4a3693094353..9430a4793719 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 e4ae40f71273..dd554ce3ad0f 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/tests/integration/auth/keeper/msg_server_test.go b/tests/integration/auth/keeper/msg_server_test.go index a4610f22bddb..de10459e91aa 100644 --- a/tests/integration/auth/keeper/msg_server_test.go +++ b/tests/integration/auth/keeper/msg_server_test.go @@ -17,10 +17,8 @@ import ( "cosmossdk.io/x/auth" authkeeper "cosmossdk.io/x/auth/keeper" authsims "cosmossdk.io/x/auth/simulation" - "cosmossdk.io/x/auth/types" authtypes "cosmossdk.io/x/auth/types" "cosmossdk.io/x/bank" - "cosmossdk.io/x/bank/keeper" bankkeeper "cosmossdk.io/x/bank/keeper" "cosmossdk.io/x/bank/testutil" banktypes "cosmossdk.io/x/bank/types" @@ -109,7 +107,7 @@ func initFixture(t *testing.T) *fixture { blockedAddresses := map[string]bool{ authKeeper.GetAuthority(): false, } - bankKeeper := keeper.NewBaseKeeper( + bankKeeper := bankkeeper.NewBaseKeeper( runtime.NewEnvironment(runtime.NewKVStoreService(keys[banktypes.StoreKey]), log.NewNopLogger()), cdc, authKeeper, @@ -187,13 +185,13 @@ func TestAsyncExec(t *testing.T) { testCases := []struct { name string - req *types.MsgNonAtomicExec + req *authtypes.MsgNonAtomicExec expectErr bool expErrMsg string }{ { name: "empty signer address", - req: &types.MsgNonAtomicExec{ + req: &authtypes.MsgNonAtomicExec{ Signer: "", Msgs: []*codectypes.Any{}, }, @@ -202,7 +200,7 @@ func TestAsyncExec(t *testing.T) { }, { name: "invalid signer address", - req: &types.MsgNonAtomicExec{ + req: &authtypes.MsgNonAtomicExec{ Signer: "invalid", Msgs: []*codectypes.Any{}, }, @@ -211,7 +209,7 @@ func TestAsyncExec(t *testing.T) { }, { name: "empty msgs", - req: &types.MsgNonAtomicExec{ + req: &authtypes.MsgNonAtomicExec{ Signer: addrs[0].String(), Msgs: []*codectypes.Any{}, }, @@ -220,7 +218,7 @@ func TestAsyncExec(t *testing.T) { }, { name: "valid msg", - req: &types.MsgNonAtomicExec{ + req: &authtypes.MsgNonAtomicExec{ Signer: addrs[0].String(), Msgs: []*codectypes.Any{msgAny}, }, @@ -228,7 +226,7 @@ func TestAsyncExec(t *testing.T) { }, { name: "multiple messages being executed", - req: &types.MsgNonAtomicExec{ + req: &authtypes.MsgNonAtomicExec{ Signer: addrs[0].String(), Msgs: []*codectypes.Any{msgAny, msgAny}, }, @@ -236,7 +234,7 @@ func TestAsyncExec(t *testing.T) { }, { name: "multiple messages with different signers", - req: &types.MsgNonAtomicExec{ + req: &authtypes.MsgNonAtomicExec{ Signer: addrs[0].String(), Msgs: []*codectypes.Any{msgAny, msgAny2}, }, @@ -245,7 +243,7 @@ func TestAsyncExec(t *testing.T) { }, { name: "multi msg with one failing being executed", - req: &types.MsgNonAtomicExec{ + req: &authtypes.MsgNonAtomicExec{ Signer: addrs[0].String(), Msgs: []*codectypes.Any{msgAny, failingMsgAny}, }, From 5ad437dd4a09e1c191728f89cf05e5040dff13ed Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Mon, 15 Apr 2024 16:58:02 +0200 Subject: [PATCH 28/39] remove line --- go.mod | 2 -- 1 file changed, 2 deletions(-) diff --git a/go.mod b/go.mod index 90dbc1f53dab..8b1c944ab694 100644 --- a/go.mod +++ b/go.mod @@ -189,8 +189,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 From fe09a4f4394cb6d0ecdc58b167818296ece102f5 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Mon, 15 Apr 2024 18:57:36 +0200 Subject: [PATCH 29/39] remove comments --- orm/model/ormdb/module.go | 4 ++-- x/staking/types/expected_keepers.go | 5 ----- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/orm/model/ormdb/module.go b/orm/model/ormdb/module.go index 5b9082fd1f0d..35d264196a3e 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.HasGenesisAuto // 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.HasGenesisAuto { // TODO should be appmodule.HasGenesisAuto with core v1 +func (m moduleDB) GenesisHandler() appmodule.HasGenesisAuto { return appModuleGenesisWrapper{m} } diff --git a/x/staking/types/expected_keepers.go b/x/staking/types/expected_keepers.go index 182930e72f80..7b11f9e1ece6 100644 --- a/x/staking/types/expected_keepers.go +++ b/x/staking/types/expected_keepers.go @@ -11,7 +11,6 @@ import ( cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" - consensustypes "github.com/cosmos/cosmos-sdk/x/consensus/types" ) // AccountKeeper defines the expected account keeper (noalias) @@ -116,7 +115,3 @@ type StakingHooksWrapper struct{ StakingHooks } // IsOnePerModuleType implements the depinject.OnePerModuleType interface. func (StakingHooksWrapper) IsOnePerModuleType() {} - -type ConsensusKeeper interface { - Params(context.Context, *consensustypes.QueryParamsRequest) (*consensustypes.QueryParamsResponse, error) -} From 84b1a1565de0600dee4606e1a16052182caea6c5 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Mon, 15 Apr 2024 19:00:21 +0200 Subject: [PATCH 30/39] use protov1 types --- x/auth/ante/setup.go | 2 +- x/evidence/keeper/infraction.go | 2 +- x/staking/keeper/msg_server.go | 2 +- x/upgrade/keeper/abci.go | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/x/auth/ante/setup.go b/x/auth/ante/setup.go index adecdb2d60eb..e6ddaa0cf650 100644 --- a/x/auth/ante/setup.go +++ b/x/auth/ante/setup.go @@ -3,10 +3,10 @@ package ante import ( "fmt" - consensusv1 "cosmossdk.io/api/cosmos/consensus/v1" "cosmossdk.io/core/appmodule" errorsmod "cosmossdk.io/errors" storetypes "cosmossdk.io/store/types" + consensusv1 "github.com/cosmos/cosmos-sdk/x/consensus/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" diff --git a/x/evidence/keeper/infraction.go b/x/evidence/keeper/infraction.go index 1424811b3683..c7e9aeb101f5 100644 --- a/x/evidence/keeper/infraction.go +++ b/x/evidence/keeper/infraction.go @@ -4,11 +4,11 @@ import ( "context" "fmt" - consensusv1 "cosmossdk.io/api/cosmos/consensus/v1" st "cosmossdk.io/api/cosmos/staking/v1beta1" "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 diff --git a/x/staking/keeper/msg_server.go b/x/staking/keeper/msg_server.go index 54eafb7cd0f5..d0c43fca3000 100644 --- a/x/staking/keeper/msg_server.go +++ b/x/staking/keeper/msg_server.go @@ -12,7 +12,6 @@ import ( "google.golang.org/grpc/codes" "google.golang.org/grpc/status" - consensusv1 "cosmossdk.io/api/cosmos/consensus/v1" "cosmossdk.io/collections" "cosmossdk.io/core/event" errorsmod "cosmossdk.io/errors" @@ -24,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 { diff --git a/x/upgrade/keeper/abci.go b/x/upgrade/keeper/abci.go index 51e941119d01..a9e50a000e83 100644 --- a/x/upgrade/keeper/abci.go +++ b/x/upgrade/keeper/abci.go @@ -5,12 +5,12 @@ import ( "errors" "fmt" - consensusv1 "cosmossdk.io/api/cosmos/consensus/v1" storetypes "cosmossdk.io/store/types" "cosmossdk.io/x/upgrade/types" "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. From 6d0b2e97e8d123cef1e035cdd1ad3e4a3760c92f Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Mon, 15 Apr 2024 19:00:45 +0200 Subject: [PATCH 31/39] fix build --- x/evidence/keeper/infraction.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/evidence/keeper/infraction.go b/x/evidence/keeper/infraction.go index c7e9aeb101f5..54f8ed84170a 100644 --- a/x/evidence/keeper/infraction.go +++ b/x/evidence/keeper/infraction.go @@ -79,7 +79,7 @@ func (k Keeper) handleEquivocationEvidence(ctx context.Context, evidence *types. return fmt.Errorf("failed to query consensus params: %w", err) } if res.Params.Evidence != nil { - if ageDuration > res.Params.Evidence.MaxAgeDuration.AsDuration() && ageBlocks > res.Params.Evidence.MaxAgeNumBlocks { + if ageDuration > res.Params.Evidence.MaxAgeDuration && ageBlocks > res.Params.Evidence.MaxAgeNumBlocks { logger.Info( "ignored equivocation; evidence too old", "validator", consAddr, From 241b63bd0cf0c69d4bacf10a659b2fbf6d623a50 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Tue, 16 Apr 2024 12:21:28 +0200 Subject: [PATCH 32/39] remove extra code --- x/auth/ante/expected_keepers.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/x/auth/ante/expected_keepers.go b/x/auth/ante/expected_keepers.go index 60adcdcb14f4..52bf0acc31f3 100644 --- a/x/auth/ante/expected_keepers.go +++ b/x/auth/ante/expected_keepers.go @@ -8,7 +8,6 @@ import ( "cosmossdk.io/x/auth/types" sdk "github.com/cosmos/cosmos-sdk/types" - consensustypes "github.com/cosmos/cosmos-sdk/x/consensus/types" ) type HasEnvironment interface { @@ -31,7 +30,3 @@ type AccountKeeper interface { type FeegrantKeeper interface { UseGrantedFees(ctx context.Context, granter, grantee sdk.AccAddress, fee sdk.Coins, msgs []sdk.Msg) error } - -type ConsensusKeeper interface { - Params(context.Context, *consensustypes.QueryParamsRequest) (*consensustypes.QueryParamsResponse, error) -} From 620d121f9794532a57bf079d3412c25983a75844 Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Thu, 18 Apr 2024 20:16:48 -0500 Subject: [PATCH 33/39] add .Environment as param --- simapp/ante.go | 8 ++++++-- simapp/app_di.go | 1 + x/auth/ante/ante.go | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/simapp/ante.go b/simapp/ante.go index 09d4937d60c2..359494d91fff 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(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_di.go b/simapp/app_di.go index 997565a4b1dc..15869bf755e9 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/x/auth/ante/ante.go b/x/auth/ante/ante.go index d49f9bf3768b..1e5f85b132a1 100644 --- a/x/auth/ante/ante.go +++ b/x/auth/ante/ante.go @@ -44,7 +44,7 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) { anteDecorators := []sdk.AnteDecorator{ 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), From d0e75e851de6845dbe81f0eff1560c7062880c1a Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Fri, 19 Apr 2024 13:44:37 -0500 Subject: [PATCH 34/39] fix simapp v1 test --- simapp/app.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/simapp/app.go b/simapp/app.go index 491aa40fa7fe..fcb756cb7ba3 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -338,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()) @@ -380,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 @@ -407,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 From 1c51342988916c6e912f212f9238cfb3a84c4b6b Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Fri, 19 Apr 2024 13:57:07 -0500 Subject: [PATCH 35/39] linter fix --- x/auth/ante/setup.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/auth/ante/setup.go b/x/auth/ante/setup.go index e6ddaa0cf650..cd2636d01f03 100644 --- a/x/auth/ante/setup.go +++ b/x/auth/ante/setup.go @@ -6,10 +6,10 @@ import ( "cosmossdk.io/core/appmodule" errorsmod "cosmossdk.io/errors" storetypes "cosmossdk.io/store/types" - consensusv1 "github.com/cosmos/cosmos-sdk/x/consensus/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 From ce24f2238e164fcfa18b386bad235042d91a0dd7 Mon Sep 17 00:00:00 2001 From: Facundo Date: Tue, 23 Apr 2024 14:41:13 +0200 Subject: [PATCH 36/39] fix: setting interface registry already happens at NewIntegrationApp --- tests/integration/auth/keeper/msg_server_test.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/integration/auth/keeper/msg_server_test.go b/tests/integration/auth/keeper/msg_server_test.go index 2747debf965b..1078d85040a9 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)) From e9e816f32d962695646e60323669b9793e3d7029 Mon Sep 17 00:00:00 2001 From: Hieu Vu <72878483+hieuvubk@users.noreply.github.com> Date: Tue, 23 Apr 2024 20:14:02 +0700 Subject: [PATCH 37/39] fix build orm --- orm/go.mod | 11 +++++++++-- orm/go.sum | 18 ++++++++++++++++-- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/orm/go.mod b/orm/go.mod index a702ecf90ae0..1039c4df2e0a 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.52.2 // 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 e3e1a7a8ef23..d87d68c22cbe 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= From 975281b9fe5ce64e88f1dc8d408ebb359a150924 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Thu, 25 Apr 2024 11:32:39 +0200 Subject: [PATCH 38/39] lint fixing --- simapp/sim_test.go | 1 + tests/sims/feegrant/operations_test.go | 2 +- x/accounts/defaults/lockup/lockup_test.go | 2 ++ x/accounts/defaults/lockup/utils_test.go | 1 + 4 files changed, 5 insertions(+), 1 deletion(-) diff --git a/simapp/sim_test.go b/simapp/sim_test.go index c26545e579f3..781a649d6294 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/tests/sims/feegrant/operations_test.go b/tests/sims/feegrant/operations_test.go index 21ef34e3aa57..9da29e67b53b 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/x/accounts/defaults/lockup/lockup_test.go b/x/accounts/defaults/lockup/lockup_test.go index 6d34540a85a6..25477bc9c542 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 32912d320527..23702b051a71 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 From 669ac75d8b60715d1595aa61bd3f3705ab63e6d8 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Thu, 25 Apr 2024 11:33:00 +0200 Subject: [PATCH 39/39] go mod tidy --- go.sum | 4 ++-- x/gov/go.sum | 2 -- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/go.sum b/go.sum index c58a190dc700..78dc0769d91e 100644 --- a/go.sum +++ b/go.sum @@ -115,8 +115,8 @@ github.com/cosmos/gogogateway v1.2.0/go.mod h1:iQpLkGWxYcnCdz5iAdLcRBSw3h7NXeOkZ github.com/cosmos/gogoproto v1.4.2/go.mod h1:cLxOsn1ljAHSV527CHOtaIP91kK6cCrZETRBrkzItWU= github.com/cosmos/gogoproto v1.4.12 h1:vB6Lbe/rtnYGjQuFxkPiPYiCybqFT8QvLipDZP8JpFE= github.com/cosmos/gogoproto v1.4.12/go.mod h1:LnZob1bXRdUoqMMtwYlcR3wjiElmlC+FkjaZRv1/eLY= -github.com/cosmos/iavl v1.0.0 h1:bw6t0Mv/mVCJvlMTOPHWLs5uUE3BRBfVWCRelOzl+so= -github.com/cosmos/iavl v1.0.0/go.mod h1:CmTGqMnRnucjxbjduneZXT+0vPgNElYvdefjX2q9tYc= +github.com/cosmos/iavl v1.0.1 h1:D+mYbcRO2wptYzOM1Hxl9cpmmHU1ZEt9T2Wv5nZTeUw= +github.com/cosmos/iavl v1.0.1/go.mod h1:8xIUkgVvwvVrBu81scdPty+/Dx9GqwHnAvXz4cwF7RY= github.com/cosmos/ics23/go v0.10.0 h1:iXqLLgp2Lp+EdpIuwXTYIQU+AiHj9mOC2X9ab++bZDM= github.com/cosmos/ics23/go v0.10.0/go.mod h1:ZfJSmng/TBNTBkFemHHHj5YY7VAU/MBU980F4VU1NG0= github.com/cosmos/keyring v1.2.0 h1:8C1lBP9xhImmIabyXW4c3vFjjLiBdGCmfLUfeZlV1Yo= diff --git a/x/gov/go.sum b/x/gov/go.sum index 9ecd09297c5a..2f52b4e00002 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=