fix(runtime/v2): properly register runtime services (#23607)

This commit is contained in:
Julien Robert 2025-02-04 13:41:40 +01:00 committed by GitHub
parent e41dfb6fb6
commit fe1c8af22a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 18 additions and 32 deletions

View File

@ -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`.

View File

@ -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{

View File

@ -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
}

View File

@ -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
}

View File

@ -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)