From eb8a69a72c24082faafb547c7d06245b4c28ab40 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 4 Apr 2024 13:11:55 +0200 Subject: [PATCH 1/6] feat(core,runtime): transaction service (exec mode) --- core/appmodule/v2/environment.go | 12 +- core/transaction/service.go | 24 ++++ runtime/autocli.go | 165 +++++++++++++++++++++++---- runtime/environment.go | 13 ++- runtime/module.go | 39 ++++++- runtime/{services => }/reflection.go | 2 +- runtime/services.go | 21 ---- runtime/services/autocli.go | 148 ------------------------ runtime/transaction.go | 19 +++ 9 files changed, 234 insertions(+), 209 deletions(-) create mode 100644 core/transaction/service.go rename runtime/{services => }/reflection.go (98%) delete mode 100644 runtime/services.go delete mode 100644 runtime/services/autocli.go create mode 100644 runtime/transaction.go diff --git a/core/appmodule/v2/environment.go b/core/appmodule/v2/environment.go index eccc7eb297af..e3592eb210ad 100644 --- a/core/appmodule/v2/environment.go +++ b/core/appmodule/v2/environment.go @@ -7,6 +7,7 @@ import ( "cosmossdk.io/core/header" "cosmossdk.io/core/router" "cosmossdk.io/core/store" + "cosmossdk.io/core/transaction" "cosmossdk.io/log" ) @@ -14,11 +15,12 @@ import ( type Environment struct { Logger log.Logger - BranchService branch.Service - EventService event.Service - GasService gas.Service - HeaderService header.Service - RouterService router.Service + BranchService branch.Service + EventService event.Service + GasService gas.Service + HeaderService header.Service + RouterService router.Service + TransactionService transaction.Service KVStoreService store.KVStoreService MemStoreService store.MemoryStoreService diff --git a/core/transaction/service.go b/core/transaction/service.go new file mode 100644 index 000000000000..ac97b9a0595d --- /dev/null +++ b/core/transaction/service.go @@ -0,0 +1,24 @@ +package transaction + +import "context" + +// ExecMode defines the execution mode which can be set on a Context. +type ExecMode uint8 + +// All possible execution modes. +const ( + ExecModeCheck ExecMode = iota + _ + ExecModeSimulate + _ + _ + _ + _ + ExecModeFinalize +) + +// Service creates a transaction service. +// This service is used to get information about which context is used to execute a transaction. +type Service interface { + ExecMode(ctx context.Context) ExecMode +} diff --git a/runtime/autocli.go b/runtime/autocli.go index a942a3bee2fa..e7929876a892 100644 --- a/runtime/autocli.go +++ b/runtime/autocli.go @@ -1,33 +1,148 @@ package runtime import ( + "context" + + gogogrpc "github.com/cosmos/gogoproto/grpc" + "github.com/cosmos/gogoproto/proto" + "google.golang.org/grpc" + protobuf "google.golang.org/protobuf/proto" + "google.golang.org/protobuf/reflect/protoreflect" + "google.golang.org/protobuf/reflect/protoregistry" + autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" - reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1" + cosmosmsg "cosmossdk.io/api/cosmos/msg/v1" + "cosmossdk.io/core/appmodule" + + "github.com/cosmos/cosmos-sdk/types/module" ) -func (m appModule) AutoCLIOptions() *autocliv1.ModuleOptions { - return &autocliv1.ModuleOptions{ - Query: &autocliv1.ServiceCommandDescriptor{ - SubCommands: map[string]*autocliv1.ServiceCommandDescriptor{ - "autocli": { - Service: autocliv1.Query_ServiceDesc.ServiceName, - RpcCommandOptions: []*autocliv1.RpcCommandOptions{ - { - RpcMethod: "AppOptions", - Short: "Query the custom autocli options", - }, - }, - }, - "reflection": { - Service: reflectionv1.ReflectionService_ServiceDesc.ServiceName, - RpcCommandOptions: []*autocliv1.RpcCommandOptions{ - { - RpcMethod: "FileDescriptors", - Short: "Query the app's protobuf file descriptors", - }, - }, - }, - }, - }, +// AutoCLIQueryService implements the cosmos.autocli.v1.Query service. +type AutoCLIQueryService struct { + autocliv1.UnimplementedQueryServer + + moduleOptions map[string]*autocliv1.ModuleOptions +} + +// NewAutoCLIQueryService returns a AutoCLIQueryService for the provided modules. +func NewAutoCLIQueryService(appModules map[string]appmodule.AppModule) *AutoCLIQueryService { + return &AutoCLIQueryService{ + moduleOptions: ExtractAutoCLIOptions(appModules), + } +} + +// ExtractAutoCLIOptions extracts autocli ModuleOptions from the provided app modules. +// +// Example Usage: +// +// ExtractAutoCLIOptions(ModuleManager.Modules) +func ExtractAutoCLIOptions(appModules map[string]appmodule.AppModule) map[string]*autocliv1.ModuleOptions { + moduleOptions := map[string]*autocliv1.ModuleOptions{} + for modName, mod := range appModules { + if autoCliMod, ok := mod.(interface { + AutoCLIOptions() *autocliv1.ModuleOptions + }); ok { + moduleOptions[modName] = autoCliMod.AutoCLIOptions() + continue + } + + cfg := &autocliConfigurator{} + + // try to auto-discover options based on the last msg and query + // services registered for the module + if mod, ok := mod.(module.HasServices); ok { + mod.RegisterServices(cfg) + } + + if mod, ok := mod.(appmodule.HasServices); ok { + err := mod.RegisterServices(cfg) + if err != nil { + panic(err) + } + } + + // check for errors in the configurator + if cfg.Error() != nil { + panic(cfg.Error()) + } + + haveServices := false + modOptions := &autocliv1.ModuleOptions{} + if cfg.msgServer.serviceName != "" { + haveServices = true + modOptions.Tx = &autocliv1.ServiceCommandDescriptor{ + Service: cfg.msgServer.serviceName, + } + } + + if cfg.queryServer.serviceName != "" { + haveServices = true + modOptions.Query = &autocliv1.ServiceCommandDescriptor{ + Service: cfg.queryServer.serviceName, + } + } + + if haveServices { + moduleOptions[modName] = modOptions + } } + return moduleOptions +} + +func (a AutoCLIQueryService) AppOptions(context.Context, *autocliv1.AppOptionsRequest) (*autocliv1.AppOptionsResponse, error) { + return &autocliv1.AppOptionsResponse{ + ModuleOptions: a.moduleOptions, + }, nil +} + +// autocliConfigurator allows us to call RegisterServices and introspect the services +type autocliConfigurator struct { + msgServer autocliServiceRegistrar + queryServer autocliServiceRegistrar + registryCache *protoregistry.Files + err error } + +var _ module.Configurator = &autocliConfigurator{} // nolint:staticcheck // SA1019: Configurator is deprecated but still used in runtime v1. + +func (a *autocliConfigurator) MsgServer() gogogrpc.Server { return &a.msgServer } + +func (a *autocliConfigurator) QueryServer() gogogrpc.Server { return &a.queryServer } + +func (a *autocliConfigurator) RegisterMigration(string, uint64, module.MigrationHandler) error { + return nil +} + +func (a *autocliConfigurator) Register(string, uint64, appmodule.MigrationHandler) error { + return nil +} + +func (a *autocliConfigurator) RegisterService(sd *grpc.ServiceDesc, ss interface{}) { + if a.registryCache == nil { + a.registryCache, a.err = proto.MergedRegistry() + } + + desc, err := a.registryCache.FindDescriptorByName(protoreflect.FullName(sd.ServiceName)) + if err != nil { + a.err = err + return + } + + if protobuf.HasExtension(desc.Options(), cosmosmsg.E_Service) { + a.msgServer.RegisterService(sd, ss) + } else { + a.queryServer.RegisterService(sd, ss) + } +} +func (a *autocliConfigurator) Error() error { return nil } + +// autocliServiceRegistrar is used to capture the service name for registered services +type autocliServiceRegistrar struct { + serviceName string +} + +func (a *autocliServiceRegistrar) RegisterService(sd *grpc.ServiceDesc, _ interface{}) { + a.serviceName = sd.ServiceName +} + +var _ autocliv1.QueryServer = &AutoCLIQueryService{} diff --git a/runtime/environment.go b/runtime/environment.go index 38500ecb6b35..6fce64b35dec 100644 --- a/runtime/environment.go +++ b/runtime/environment.go @@ -17,12 +17,13 @@ func NewEnvironment( opts ...EnvOption, ) appmodule.Environment { env := appmodule.Environment{ - Logger: logger, - EventService: EventService{}, - HeaderService: HeaderService{}, - BranchService: BranchService{}, - GasService: GasService{}, - KVStoreService: kvService, + Logger: logger, + EventService: EventService{}, + HeaderService: HeaderService{}, + BranchService: BranchService{}, + GasService: GasService{}, + TransactionService: TransactionService{}, + KVStoreService: kvService, } for _, opt := range opts { diff --git a/runtime/module.go b/runtime/module.go index 41b6b55318d0..2a848bc8f91d 100644 --- a/runtime/module.go +++ b/runtime/module.go @@ -11,6 +11,8 @@ import ( runtimev1alpha1 "cosmossdk.io/api/cosmos/app/runtime/v1alpha1" appv1alpha1 "cosmossdk.io/api/cosmos/app/v1alpha1" authmodulev1 "cosmossdk.io/api/cosmos/auth/module/v1" + autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" + reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1" stakingmodulev1 "cosmossdk.io/api/cosmos/staking/module/v1" "cosmossdk.io/core/address" "cosmossdk.io/core/appmodule" @@ -31,19 +33,50 @@ import ( "github.com/cosmos/cosmos-sdk/types/msgservice" ) +// appModule defines runtime as an AppModule type appModule struct { app *App } +func (m appModule) IsOnePerModuleType() {} +func (m appModule) IsAppModule() {} + func (m appModule) RegisterServices(configurator module.Configurator) { // nolint:staticcheck // SA1019: Configurator is deprecated but still used in runtime v1. - err := m.app.registerRuntimeServices(configurator) + autocliv1.RegisterQueryServer(configurator.QueryServer(), NewAutoCLIQueryService(m.app.ModuleManager.Modules)) + + reflectionSvc, err := NewReflectionService() if err != nil { panic(err) } + reflectionv1.RegisterReflectionServiceServer(configurator.QueryServer(), reflectionSvc) } -func (m appModule) IsOnePerModuleType() {} -func (m appModule) IsAppModule() {} +func (m appModule) AutoCLIOptions() *autocliv1.ModuleOptions { + return &autocliv1.ModuleOptions{ + Query: &autocliv1.ServiceCommandDescriptor{ + SubCommands: map[string]*autocliv1.ServiceCommandDescriptor{ + "autocli": { + Service: autocliv1.Query_ServiceDesc.ServiceName, + RpcCommandOptions: []*autocliv1.RpcCommandOptions{ + { + RpcMethod: "AppOptions", + Short: "Query the custom autocli options", + }, + }, + }, + "reflection": { + Service: reflectionv1.ReflectionService_ServiceDesc.ServiceName, + RpcCommandOptions: []*autocliv1.RpcCommandOptions{ + { + RpcMethod: "FileDescriptors", + Short: "Query the app's protobuf file descriptors", + }, + }, + }, + }, + }, + } +} var ( _ appmodule.AppModule = appModule{} diff --git a/runtime/services/reflection.go b/runtime/reflection.go similarity index 98% rename from runtime/services/reflection.go rename to runtime/reflection.go index 65225a482606..2a82b27d896f 100644 --- a/runtime/services/reflection.go +++ b/runtime/reflection.go @@ -1,4 +1,4 @@ -package services +package runtime import ( "context" diff --git a/runtime/services.go b/runtime/services.go deleted file mode 100644 index 2f453898ff88..000000000000 --- a/runtime/services.go +++ /dev/null @@ -1,21 +0,0 @@ -package runtime - -import ( - autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" - reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1" - - "github.com/cosmos/cosmos-sdk/runtime/services" - "github.com/cosmos/cosmos-sdk/types/module" -) - -func (a *App) registerRuntimeServices(cfg module.Configurator) error { // nolint:staticcheck // SA1019: Configurator is deprecated but still used in runtime v1. - autocliv1.RegisterQueryServer(cfg.QueryServer(), services.NewAutoCLIQueryService(a.ModuleManager.Modules)) - - reflectionSvc, err := services.NewReflectionService() - if err != nil { - return err - } - reflectionv1.RegisterReflectionServiceServer(cfg.QueryServer(), reflectionSvc) - - return nil -} diff --git a/runtime/services/autocli.go b/runtime/services/autocli.go deleted file mode 100644 index b130af0f1c11..000000000000 --- a/runtime/services/autocli.go +++ /dev/null @@ -1,148 +0,0 @@ -package services - -import ( - "context" - - gogogrpc "github.com/cosmos/gogoproto/grpc" - "github.com/cosmos/gogoproto/proto" - "google.golang.org/grpc" - protobuf "google.golang.org/protobuf/proto" - "google.golang.org/protobuf/reflect/protoreflect" - "google.golang.org/protobuf/reflect/protoregistry" - - autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" - cosmosmsg "cosmossdk.io/api/cosmos/msg/v1" - "cosmossdk.io/core/appmodule" - - "github.com/cosmos/cosmos-sdk/types/module" -) - -// AutoCLIQueryService implements the cosmos.autocli.v1.Query service. -type AutoCLIQueryService struct { - autocliv1.UnimplementedQueryServer - - moduleOptions map[string]*autocliv1.ModuleOptions -} - -// NewAutoCLIQueryService returns a AutoCLIQueryService for the provided modules. -func NewAutoCLIQueryService(appModules map[string]appmodule.AppModule) *AutoCLIQueryService { - return &AutoCLIQueryService{ - moduleOptions: ExtractAutoCLIOptions(appModules), - } -} - -// ExtractAutoCLIOptions extracts autocli ModuleOptions from the provided app modules. -// -// Example Usage: -// -// ExtractAutoCLIOptions(ModuleManager.Modules) -func ExtractAutoCLIOptions(appModules map[string]appmodule.AppModule) map[string]*autocliv1.ModuleOptions { - moduleOptions := map[string]*autocliv1.ModuleOptions{} - for modName, mod := range appModules { - if autoCliMod, ok := mod.(interface { - AutoCLIOptions() *autocliv1.ModuleOptions - }); ok { - moduleOptions[modName] = autoCliMod.AutoCLIOptions() - continue - } - - cfg := &autocliConfigurator{} - - // try to auto-discover options based on the last msg and query - // services registered for the module - if mod, ok := mod.(module.HasServices); ok { - mod.RegisterServices(cfg) - } - - if mod, ok := mod.(appmodule.HasServices); ok { - err := mod.RegisterServices(cfg) - if err != nil { - panic(err) - } - } - - // check for errors in the configurator - if cfg.Error() != nil { - panic(cfg.Error()) - } - - haveServices := false - modOptions := &autocliv1.ModuleOptions{} - if cfg.msgServer.serviceName != "" { - haveServices = true - modOptions.Tx = &autocliv1.ServiceCommandDescriptor{ - Service: cfg.msgServer.serviceName, - } - } - - if cfg.queryServer.serviceName != "" { - haveServices = true - modOptions.Query = &autocliv1.ServiceCommandDescriptor{ - Service: cfg.queryServer.serviceName, - } - } - - if haveServices { - moduleOptions[modName] = modOptions - } - } - return moduleOptions -} - -func (a AutoCLIQueryService) AppOptions(context.Context, *autocliv1.AppOptionsRequest) (*autocliv1.AppOptionsResponse, error) { - return &autocliv1.AppOptionsResponse{ - ModuleOptions: a.moduleOptions, - }, nil -} - -// autocliConfigurator allows us to call RegisterServices and introspect the services -type autocliConfigurator struct { - msgServer autocliServiceRegistrar - queryServer autocliServiceRegistrar - registryCache *protoregistry.Files - err error -} - -var _ module.Configurator = &autocliConfigurator{} // nolint:staticcheck // SA1019: Configurator is deprecated but still used in runtime v1. - -func (a *autocliConfigurator) MsgServer() gogogrpc.Server { return &a.msgServer } - -func (a *autocliConfigurator) QueryServer() gogogrpc.Server { return &a.queryServer } - -func (a *autocliConfigurator) RegisterMigration(string, uint64, module.MigrationHandler) error { - return nil -} - -func (a *autocliConfigurator) Register(string, uint64, appmodule.MigrationHandler) error { - return nil -} - -func (a *autocliConfigurator) RegisterService(sd *grpc.ServiceDesc, ss interface{}) { - if a.registryCache == nil { - a.registryCache, a.err = proto.MergedRegistry() - } - - desc, err := a.registryCache.FindDescriptorByName(protoreflect.FullName(sd.ServiceName)) - if err != nil { - a.err = err - return - } - - if protobuf.HasExtension(desc.Options(), cosmosmsg.E_Service) { - a.msgServer.RegisterService(sd, ss) - } else { - a.queryServer.RegisterService(sd, ss) - } -} -func (a *autocliConfigurator) Error() error { return nil } - -// autocliServiceRegistrar is used to capture the service name for registered services -type autocliServiceRegistrar struct { - serviceName string -} - -func (a *autocliServiceRegistrar) RegisterService(sd *grpc.ServiceDesc, _ interface{}) { - a.serviceName = sd.ServiceName -} - -var _ autocliv1.QueryServer = &AutoCLIQueryService{} diff --git a/runtime/transaction.go b/runtime/transaction.go new file mode 100644 index 000000000000..27b4734661d1 --- /dev/null +++ b/runtime/transaction.go @@ -0,0 +1,19 @@ +package runtime + +import ( + "context" + + "cosmossdk.io/core/transaction" + + sdk "github.com/cosmos/cosmos-sdk/types" +) + +var _ transaction.Service = TransactionService{} + +type TransactionService struct{} + +// ExecMode implements transaction.Service. +func (t TransactionService) ExecMode(ctx context.Context) transaction.ExecMode { + sdkCtx := sdk.UnwrapSDKContext(ctx) + return transaction.ExecMode(sdkCtx.ExecMode()) +} From eeb366199f4e7ad4ce0f8faa45304fd88d1002ae Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 4 Apr 2024 13:14:17 +0200 Subject: [PATCH 2/6] changelogs --- CHANGELOG.md | 1 + core/CHANGELOG.md | 1 + 2 files changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 76f93f30c5f8..ec9f6e51fc52 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) [#19953](https://github.com/cosmos/cosmos-sdk/pull/19953) Implement `core/transaction.Service` it in runtime. * (client) [#19905](https://github.com/cosmos/cosmos-sdk/pull/19905) Add grpc client config to `client.toml`. * (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. diff --git a/core/CHANGELOG.md b/core/CHANGELOG.md index d44c84f4c1a0..15de1f38e2df 100644 --- a/core/CHANGELOG.md +++ b/core/CHANGELOG.md @@ -38,6 +38,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Features +* [#19953](https://github.com/cosmos/cosmos-sdk/pull/19953) Add transaction service. * [#18379](https://github.com/cosmos/cosmos-sdk/pull/18379) Add branch service. * [#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 From a742f1c8b668c63eadaf9781d9c8c9dbc8bf4a5f Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 4 Apr 2024 13:15:58 +0200 Subject: [PATCH 3/6] godoc --- core/transaction/service.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/transaction/service.go b/core/transaction/service.go index ac97b9a0595d..bddc2ba4e634 100644 --- a/core/transaction/service.go +++ b/core/transaction/service.go @@ -2,10 +2,11 @@ package transaction import "context" -// ExecMode defines the execution mode which can be set on a Context. +// ExecMode defines the execution mode type ExecMode uint8 // All possible execution modes. +// For backwards compatibility and easier casting, the exec mode values must be the same as in cosmos/cosmos-sdk/types package. const ( ExecModeCheck ExecMode = iota _ @@ -18,7 +19,6 @@ const ( ) // Service creates a transaction service. -// This service is used to get information about which context is used to execute a transaction. type Service interface { ExecMode(ctx context.Context) ExecMode } From f23c4d18aca69b55b9cf0effc2db291e4727739b Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 4 Apr 2024 13:32:52 +0200 Subject: [PATCH 4/6] less diff --- runtime/module.go | 5 +---- runtime/services.go | 21 ++++++++++++++++++++ runtime/{ => services}/autocli.go | 2 +- runtime/services/reflection.go | 33 +++++++++++++++++++++++++++++++ 4 files changed, 56 insertions(+), 5 deletions(-) create mode 100644 runtime/services.go rename runtime/{ => services}/autocli.go (99%) create mode 100644 runtime/services/reflection.go diff --git a/runtime/module.go b/runtime/module.go index 2a848bc8f91d..65a3ddcf4ec2 100644 --- a/runtime/module.go +++ b/runtime/module.go @@ -42,13 +42,10 @@ func (m appModule) IsOnePerModuleType() {} func (m appModule) IsAppModule() {} func (m appModule) RegisterServices(configurator module.Configurator) { // nolint:staticcheck // SA1019: Configurator is deprecated but still used in runtime v1. - autocliv1.RegisterQueryServer(configurator.QueryServer(), NewAutoCLIQueryService(m.app.ModuleManager.Modules)) - - reflectionSvc, err := NewReflectionService() + err := m.app.registerRuntimeServices(configurator) if err != nil { panic(err) } - reflectionv1.RegisterReflectionServiceServer(configurator.QueryServer(), reflectionSvc) } func (m appModule) AutoCLIOptions() *autocliv1.ModuleOptions { diff --git a/runtime/services.go b/runtime/services.go new file mode 100644 index 000000000000..2f453898ff88 --- /dev/null +++ b/runtime/services.go @@ -0,0 +1,21 @@ +package runtime + +import ( + autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" + reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1" + + "github.com/cosmos/cosmos-sdk/runtime/services" + "github.com/cosmos/cosmos-sdk/types/module" +) + +func (a *App) registerRuntimeServices(cfg module.Configurator) error { // nolint:staticcheck // SA1019: Configurator is deprecated but still used in runtime v1. + autocliv1.RegisterQueryServer(cfg.QueryServer(), services.NewAutoCLIQueryService(a.ModuleManager.Modules)) + + reflectionSvc, err := services.NewReflectionService() + if err != nil { + return err + } + reflectionv1.RegisterReflectionServiceServer(cfg.QueryServer(), reflectionSvc) + + return nil +} diff --git a/runtime/autocli.go b/runtime/services/autocli.go similarity index 99% rename from runtime/autocli.go rename to runtime/services/autocli.go index e7929876a892..b130af0f1c11 100644 --- a/runtime/autocli.go +++ b/runtime/services/autocli.go @@ -1,4 +1,4 @@ -package runtime +package services import ( "context" diff --git a/runtime/services/reflection.go b/runtime/services/reflection.go new file mode 100644 index 000000000000..65225a482606 --- /dev/null +++ b/runtime/services/reflection.go @@ -0,0 +1,33 @@ +package services + +import ( + "context" + + "github.com/cosmos/gogoproto/proto" + "google.golang.org/protobuf/types/descriptorpb" + + reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1" +) + +// ReflectionService implements the cosmos.reflection.v1 service. +type ReflectionService struct { + reflectionv1.UnimplementedReflectionServiceServer + files *descriptorpb.FileDescriptorSet +} + +func NewReflectionService() (*ReflectionService, error) { + fds, err := proto.MergedGlobalFileDescriptors() + if err != nil { + return nil, err + } + + return &ReflectionService{files: fds}, nil +} + +func (r ReflectionService) FileDescriptors(_ context.Context, _ *reflectionv1.FileDescriptorsRequest) (*reflectionv1.FileDescriptorsResponse, error) { + return &reflectionv1.FileDescriptorsResponse{ + Files: r.files.File, + }, nil +} + +var _ reflectionv1.ReflectionServiceServer = &ReflectionService{} From 88aac5631c4787cf0803a085b095eb6cf171a5b0 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 4 Apr 2024 13:33:52 +0200 Subject: [PATCH 5/6] nit --- runtime/reflection.go | 33 --------------------------------- 1 file changed, 33 deletions(-) delete mode 100644 runtime/reflection.go diff --git a/runtime/reflection.go b/runtime/reflection.go deleted file mode 100644 index 2a82b27d896f..000000000000 --- a/runtime/reflection.go +++ /dev/null @@ -1,33 +0,0 @@ -package runtime - -import ( - "context" - - "github.com/cosmos/gogoproto/proto" - "google.golang.org/protobuf/types/descriptorpb" - - reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1" -) - -// ReflectionService implements the cosmos.reflection.v1 service. -type ReflectionService struct { - reflectionv1.UnimplementedReflectionServiceServer - files *descriptorpb.FileDescriptorSet -} - -func NewReflectionService() (*ReflectionService, error) { - fds, err := proto.MergedGlobalFileDescriptors() - if err != nil { - return nil, err - } - - return &ReflectionService{files: fds}, nil -} - -func (r ReflectionService) FileDescriptors(_ context.Context, _ *reflectionv1.FileDescriptorsRequest) (*reflectionv1.FileDescriptorsResponse, error) { - return &reflectionv1.FileDescriptorsResponse{ - Files: r.files.File, - }, nil -} - -var _ reflectionv1.ReflectionServiceServer = &ReflectionService{} From 2a6ce59c9925edf893efaac67b0d96367a2ab0fe Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 4 Apr 2024 13:34:25 +0200 Subject: [PATCH 6/6] nit --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ec9f6e51fc52..419f2ec401ee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,9 +42,9 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i ### Features -* (runtime) [#19953](https://github.com/cosmos/cosmos-sdk/pull/19953) Implement `core/transaction.Service` it in runtime. +* (runtime) [#19953](https://github.com/cosmos/cosmos-sdk/pull/19953) Implement `core/transaction.Service` in runtime. * (client) [#19905](https://github.com/cosmos/cosmos-sdk/pull/19905) Add grpc client config to `client.toml`. -* (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). +* (runtime) [#19571](https://github.com/cosmos/cosmos-sdk/pull/19571) Implement `core/router.Service` 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.