From fe1c8af22ae3768ffa840c6caaf8ff0cb27149b5 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Tue, 4 Feb 2025 13:41:40 +0100 Subject: [PATCH] fix(runtime/v2): properly register runtime services (#23607) --- runtime/v2/CHANGELOG.md | 2 ++ runtime/v2/module.go | 18 ++++++++++++------ runtime/v2/services/autocli.go | 15 ++------------- runtime/v2/services/reflection.go | 13 ++----------- tests/systemtests/grpc_test.go | 2 -- 5 files changed, 18 insertions(+), 32 deletions(-) diff --git a/runtime/v2/CHANGELOG.md b/runtime/v2/CHANGELOG.md index 91f694078b..7eb4889fb1 100644 --- a/runtime/v2/CHANGELOG.md +++ b/runtime/v2/CHANGELOG.md @@ -22,6 +22,8 @@ Each entry must include the Github issue reference in the following format: ## [Unreleased] +* [#23607](https://github.com/cosmos/cosmos-sdk/pull/23607) Register runtime services properly. + ## [v2.0.0-beta.1](https://github.com/cosmos/cosmos-sdk/releases/tag/runtime/v2.0.0-beta.1) Initial tag of `cosmossdk.io/runtime/v2`. diff --git a/runtime/v2/module.go b/runtime/v2/module.go index 9f638bb9c0..18d43108ec 100644 --- a/runtime/v2/module.go +++ b/runtime/v2/module.go @@ -45,18 +45,24 @@ func (m appModule[T]) IsOnePerModuleType() {} func (m appModule[T]) IsAppModule() {} func (m appModule[T]) RegisterServices(registrar grpc.ServiceRegistrar) error { - autoCliQueryService, err := services.NewAutoCLIQueryService(m.app.moduleManager.modules) + moduleOptions, err := services.ExtractAutoCLIOptions(m.app.moduleManager.modules) if err != nil { return err } - autocliv1.RegisterQueryServer(registrar, autoCliQueryService) - - reflectionSvc, err := services.NewReflectionService() + fds, err := proto.MergedGlobalFileDescriptors() if err != nil { return err } - reflectionv1.RegisterReflectionServiceServer(registrar, reflectionSvc) + + // manually register types in for gogoproto + proto.RegisterType(&reflectionv1.FileDescriptorsRequest{}, "cosmos.reflection.v1.FileDescriptorsRequest") + proto.RegisterType(&reflectionv1.FileDescriptorsResponse{}, "cosmos.reflection.v1.FileDescriptorsResponse") + proto.RegisterType(&autocliv1.AppOptionsRequest{}, "cosmos.autocli.v1.AppOptionsRequest") + proto.RegisterType(&autocliv1.AppOptionsResponse{}, "cosmos.autocli.v1.AppOptionsResponse") + + registrar.RegisterService(&autocliv1.Query_ServiceDesc, &services.AutoCLIQueryService{ModuleOptions: moduleOptions}) + registrar.RegisterService(&reflectionv1.ReflectionService_ServiceDesc, &services.ReflectionService{Files: fds}) return nil } @@ -68,7 +74,7 @@ func (m appModule[T]) AutoCLIOptions() *autocliv1.ModuleOptions { RpcCommandOptions: []*autocliv1.RpcCommandOptions{ { RpcMethod: "Config", - Short: "Query the current app config", + Skip: true, // The config command has been deprecated }, }, SubCommands: map[string]*autocliv1.ServiceCommandDescriptor{ diff --git a/runtime/v2/services/autocli.go b/runtime/v2/services/autocli.go index 208b922a0c..cac7cce2e5 100644 --- a/runtime/v2/services/autocli.go +++ b/runtime/v2/services/autocli.go @@ -13,24 +13,13 @@ import ( autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" cosmosmsg "cosmossdk.io/api/cosmos/msg/v1" "cosmossdk.io/core/appmodule" - appmodulev2 "cosmossdk.io/core/appmodule/v2" ) // 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]appmodulev2.AppModule) (*AutoCLIQueryService, error) { - moduleOptions, err := ExtractAutoCLIOptions(appModules) - if err != nil { - return nil, err - } - - return &AutoCLIQueryService{moduleOptions: moduleOptions}, nil + ModuleOptions map[string]*autocliv1.ModuleOptions } // ExtractAutoCLIOptions extracts autocli ModuleOptions from the provided app modules. @@ -91,7 +80,7 @@ func ExtractAutoCLIOptions(appModules map[string]appmodule.AppModule) (map[strin func (a AutoCLIQueryService) AppOptions(context.Context, *autocliv1.AppOptionsRequest) (*autocliv1.AppOptionsResponse, error) { return &autocliv1.AppOptionsResponse{ - ModuleOptions: a.moduleOptions, + ModuleOptions: a.ModuleOptions, }, nil } diff --git a/runtime/v2/services/reflection.go b/runtime/v2/services/reflection.go index 65225a4826..64f10b265d 100644 --- a/runtime/v2/services/reflection.go +++ b/runtime/v2/services/reflection.go @@ -3,7 +3,6 @@ package services import ( "context" - "github.com/cosmos/gogoproto/proto" "google.golang.org/protobuf/types/descriptorpb" reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1" @@ -12,21 +11,13 @@ import ( // 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 + Files *descriptorpb.FileDescriptorSet } func (r ReflectionService) FileDescriptors(_ context.Context, _ *reflectionv1.FileDescriptorsRequest) (*reflectionv1.FileDescriptorsResponse, error) { return &reflectionv1.FileDescriptorsResponse{ - Files: r.files.File, + Files: r.Files.File, }, nil } diff --git a/tests/systemtests/grpc_test.go b/tests/systemtests/grpc_test.go index a549ea4690..cd9e851fbc 100644 --- a/tests/systemtests/grpc_test.go +++ b/tests/systemtests/grpc_test.go @@ -50,8 +50,6 @@ func TestGRPC(t *testing.T) { } func TestGRPCQueryAutoCLIOptions(t *testing.T) { - t.Skip() // TODO(@julienrbrt): re-add autocli query in v2 in follow-up - systest.Sut.ResetChain(t) systest.Sut.StartChain(t)