Skip to content

Commit c79e19d

Browse files
authored
fix(server/v2/grpc): fix reflection (#23333)
1 parent 8cdae28 commit c79e19d

File tree

6 files changed

+150
-148
lines changed

6 files changed

+150
-148
lines changed

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
4141
Every module contains its own CHANGELOG.md. Please refer to the module you are interested in.
4242

4343
### Features
44+
4445
* (sims) [#23013](https://github.com/cosmos/cosmos-sdk/pull/23013) Integration with app v2
4546
* (baseapp) [#20291](https://github.com/cosmos/cosmos-sdk/pull/20291) Simulate nested messages.
4647
* (client/keys) [#21829](https://github.com/cosmos/cosmos-sdk/pull/21829) Add support for importing hex key using standard input.
@@ -62,9 +63,9 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i
6263
* (x/params) [#22995](https://github.com/cosmos/cosmos-sdk/pull/22995) Remove `x/params`. Migrate to the new params system introduced in `v0.47` as demonstrated [here](https://github.com/cosmos/cosmos-sdk/blob/main/UPGRADING.md#xparams).
6364
* (testutil) [#22392](https://github.com/cosmos/cosmos-sdk/pull/22392) Remove `testutil/network` package. Use the integration framework or systemtests framework instead.
6465

65-
#### Removal of v1 components
66+
#### Removal of v0 components
6667

67-
This subsection lists the API breaking changes that are [part of the removal of v1 components](https://github.com/cosmos/cosmos-sdk/issues/22904). The v1 components were deprecated in `v0.52` and are now removed.
68+
This subsection lists the API breaking changes that are [part of the removal of v0 components](https://github.com/cosmos/cosmos-sdk/issues/22904). The v0 components were deprecated in `v0.52` and are now removed.
6869

6970
* (simapp) [#23009](https://github.com/cosmos/cosmos-sdk/pull/23009) Simapp has been removed. Check-out Simapp/v2 instead.
7071
* (server) [#23018](https://github.com/cosmos/cosmos-sdk/pull/23018) [#23238](https://github.com/cosmos/cosmos-sdk/pull/23238) The server package has been removed. Use server/v2 instead

server/v2/api/grpc/gogoreflection/serverreflection.go

Lines changed: 49 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ import (
4444
"io"
4545
"reflect"
4646
"sort"
47-
"strings"
4847
"sync"
4948

5049
gogoproto "github.com/cosmos/gogoproto/proto"
@@ -55,6 +54,7 @@ import (
5554
"google.golang.org/grpc/status"
5655
"google.golang.org/protobuf/reflect/protodesc"
5756
"google.golang.org/protobuf/reflect/protoreflect"
57+
"google.golang.org/protobuf/reflect/protoregistry"
5858

5959
"cosmossdk.io/core/log"
6060
)
@@ -63,7 +63,7 @@ type serverReflectionServer struct {
6363
rpb.UnimplementedServerReflectionServer
6464
s *grpc.Server
6565

66-
methods []string
66+
messages []string
6767

6868
initSymbols sync.Once
6969
serviceNames []string
@@ -72,11 +72,11 @@ type serverReflectionServer struct {
7272
}
7373

7474
// Register registers the server reflection service on the given gRPC server.
75-
func Register(s *grpc.Server, methods []string, logger log.Logger) {
75+
func Register(s *grpc.Server, messages []string, logger log.Logger) {
7676
rpb.RegisterServerReflectionServer(s, &serverReflectionServer{
77-
s: s,
78-
methods: methods,
79-
log: logger,
77+
s: s,
78+
messages: messages,
79+
log: logger,
8080
})
8181
}
8282

@@ -91,7 +91,7 @@ type protoMessage interface {
9191
func (s *serverReflectionServer) getSymbols() (svcNames []string, symbolIndex map[string]*dpb.FileDescriptorProto) {
9292
s.initSymbols.Do(func() {
9393
s.symbols = map[string]*dpb.FileDescriptorProto{}
94-
services, fds := s.getServices(s.methods)
94+
services, fds := s.getServices(s.messages)
9595
s.serviceNames = services
9696

9797
processed := map[string]struct{}{}
@@ -458,26 +458,61 @@ func (s *serverReflectionServer) ServerReflectionInfo(stream rpb.ServerReflectio
458458
}
459459

460460
// getServices gets the unique list of services given a list of methods.
461-
func (s *serverReflectionServer) getServices(methods []string) (svcs []string, fds []*dpb.FileDescriptorProto) {
461+
func (s *serverReflectionServer) getServices(messages []string) (svcs []string, fds []*dpb.FileDescriptorProto) {
462462
registry, err := gogoproto.MergedRegistry()
463463
if err != nil {
464464
s.log.Error("unable to load merged registry", "err", err)
465465
return nil, nil
466466
}
467467
seenSvc := map[protoreflect.FullName]struct{}{}
468-
for _, methodName := range methods {
469-
methodName = strings.Join(strings.Split(methodName[1:], "/"), ".")
470-
md, err := registry.FindDescriptorByName(protoreflect.FullName(methodName))
468+
for _, messageName := range messages {
469+
md, err := registry.FindDescriptorByName(protoreflect.FullName(messageName))
471470
if err != nil {
472-
s.log.Error("unable to load method descriptor", "method", methodName, "err", err)
471+
s.log.Error("unable to load message descriptor", "message", messageName, "err", err)
473472
continue
474473
}
475-
svc := md.(protoreflect.MethodDescriptor).Parent()
474+
475+
svc, ok := findServiceForMessage(registry, md.(protoreflect.MessageDescriptor))
476+
if !ok {
477+
// if a service is not found for the message, simply skip
478+
// this is likely the message isn't part of a service and using appmodulev2.Handler instead.
479+
continue
480+
}
481+
476482
if _, seen := seenSvc[svc.FullName()]; !seen {
477483
svcs = append(svcs, string(svc.FullName()))
478484
file := svc.ParentFile()
479485
fds = append(fds, protodesc.ToFileDescriptorProto(file))
480486
}
487+
488+
seenSvc[svc.FullName()] = struct{}{}
481489
}
482-
return
490+
491+
return svcs, fds
492+
}
493+
494+
func findServiceForMessage(registry *protoregistry.Files, messageDesc protoreflect.MessageDescriptor) (protoreflect.ServiceDescriptor, bool) {
495+
var (
496+
service protoreflect.ServiceDescriptor
497+
found bool
498+
)
499+
500+
registry.RangeFiles(func(fileDescriptor protoreflect.FileDescriptor) bool {
501+
for i := 0; i < fileDescriptor.Services().Len(); i++ {
502+
serviceDesc := fileDescriptor.Services().Get(i)
503+
504+
for j := 0; j < serviceDesc.Methods().Len(); j++ {
505+
methodDesc := serviceDesc.Methods().Get(j)
506+
507+
if methodDesc.Input() == messageDesc || methodDesc.Output() == messageDesc {
508+
service = serviceDesc
509+
found = true
510+
return false
511+
}
512+
}
513+
}
514+
return true
515+
})
516+
517+
return service, found
483518
}

tests/integration/runtime/query_test.go

Lines changed: 0 additions & 127 deletions
This file was deleted.

tests/systemtests/go.mod

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ require (
66
cosmossdk.io/math v1.5.0
77
cosmossdk.io/systemtests v1.0.0
88
github.com/cosmos/cosmos-sdk v0.50.11
9+
github.com/fullstorydev/grpcurl v1.9.2
910
)
1011

1112
require (
@@ -26,12 +27,14 @@ require (
2627
github.com/DataDog/zstd v1.5.6 // indirect
2728
github.com/beorn7/perks v1.0.1 // indirect
2829
github.com/bgentry/speakeasy v0.2.0 // indirect
30+
github.com/bufbuild/protocompile v0.10.0 // indirect
2931
github.com/bytedance/sonic v1.12.6 // indirect
3032
github.com/bytedance/sonic/loader v0.2.1 // indirect
3133
github.com/cenkalti/backoff/v4 v4.1.3 // indirect
3234
github.com/cespare/xxhash/v2 v2.3.0 // indirect
3335
github.com/cloudwego/base64x v0.1.4 // indirect
3436
github.com/cloudwego/iasm v0.2.0 // indirect
37+
github.com/cncf/xds/go v0.0.0-20240905190251-b4127c9b8d78 // indirect
3538
github.com/cockroachdb/apd/v3 v3.2.1 // indirect
3639
github.com/cockroachdb/errors v1.11.3 // indirect
3740
github.com/cockroachdb/fifo v0.0.0-20240816210425-c5d0cb0b6fc0 // indirect
@@ -61,6 +64,8 @@ require (
6164
github.com/dustin/go-humanize v1.0.1 // indirect
6265
github.com/dvsekhvalnov/jose2go v1.6.0 // indirect
6366
github.com/emicklei/dot v1.6.2 // indirect
67+
github.com/envoyproxy/go-control-plane v0.13.1 // indirect
68+
github.com/envoyproxy/protoc-gen-validate v1.1.0 // indirect
6469
github.com/fatih/color v1.18.0 // indirect
6570
github.com/felixge/httpsnoop v1.0.4 // indirect
6671
github.com/fsnotify/fsnotify v1.8.0 // indirect
@@ -98,6 +103,7 @@ require (
98103
github.com/iancoleman/strcase v0.3.0 // indirect
99104
github.com/improbable-eng/grpc-web v0.15.0 // indirect
100105
github.com/inconshreveable/mousetrap v1.1.0 // indirect
106+
github.com/jhump/protoreflect v1.16.0
101107
github.com/jmhodges/levigo v1.0.0 // indirect
102108
github.com/klauspost/compress v1.17.11 // indirect
103109
github.com/klauspost/cpuid/v2 v2.2.9 // indirect
@@ -117,6 +123,7 @@ require (
117123
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
118124
github.com/petermattis/goid v0.0.0-20240813172612-4fcff4a6cae7 // indirect
119125
github.com/pkg/errors v0.9.1 // indirect
126+
github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10 // indirect
120127
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
121128
github.com/prometheus/client_golang v1.20.5 // indirect
122129
github.com/prometheus/client_model v0.6.1 // indirect
@@ -161,7 +168,7 @@ require (
161168
google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de // indirect
162169
google.golang.org/genproto/googleapis/api v0.0.0-20241015192408-796eee8c2d53 // indirect
163170
google.golang.org/genproto/googleapis/rpc v0.0.0-20250106144421-5f5ef82da422 // indirect
164-
google.golang.org/grpc v1.69.2 // indirect
171+
google.golang.org/grpc v1.69.2
165172
google.golang.org/protobuf v1.36.2 // indirect
166173
gopkg.in/ini.v1 v1.67.0 // indirect
167174
gopkg.in/yaml.v3 v3.0.1 // indirect

tests/systemtests/go.sum

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ github.com/btcsuite/btcd/btcec/v2 v2.3.4 h1:3EJjcN70HCu/mwqlUsGK8GcNVyLVxFDlWurT
8181
github.com/btcsuite/btcd/btcec/v2 v2.3.4/go.mod h1:zYzJ8etWJQIv1Ogk7OzpWjowwOdXY1W/17j2MW85J04=
8282
github.com/btcsuite/btcd/btcutil v1.1.6 h1:zFL2+c3Lb9gEgqKNzowKUPQNb8jV7v5Oaodi/AYFd6c=
8383
github.com/btcsuite/btcd/btcutil v1.1.6/go.mod h1:9dFymx8HpuLqBnsPELrImQeTQfKBQqzqGbbV3jK55aE=
84-
github.com/bufbuild/protocompile v0.6.0 h1:Uu7WiSQ6Yj9DbkdnOe7U4mNKp58y9WDMKDn28/ZlunY=
85-
github.com/bufbuild/protocompile v0.6.0/go.mod h1:YNP35qEYoYGme7QMtz5SBCoN4kL4g12jTtjuzRNdjpE=
84+
github.com/bufbuild/protocompile v0.10.0 h1:+jW/wnLMLxaCEG8AX9lD0bQ5v9h1RUiMKOBOT5ll9dM=
85+
github.com/bufbuild/protocompile v0.10.0/go.mod h1:G9qQIQo0xZ6Uyj6CMNz0saGmx2so+KONo8/KrELABiY=
8686
github.com/bytedance/sonic v1.12.6 h1:/isNmCUF2x3Sh8RAp/4mh4ZGkcFAX/hLrzrK3AvpRzk=
8787
github.com/bytedance/sonic v1.12.6/go.mod h1:B8Gt/XvtZ3Fqj+iSKMypzymZxw/FVwgIGKzMzT9r/rk=
8888
github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU=
@@ -118,6 +118,8 @@ github.com/cncf/xds/go v0.0.0-20210805033703-aa0b78936158/go.mod h1:eXthEFrGJvWH
118118
github.com/cncf/xds/go v0.0.0-20210922020428-25de7278fc84/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
119119
github.com/cncf/xds/go v0.0.0-20211001041855-01bcc9b48dfe/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
120120
github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
121+
github.com/cncf/xds/go v0.0.0-20240905190251-b4127c9b8d78 h1:QVw89YDxXxEe+l8gU8ETbOasdwEV+avkR75ZzsVV9WI=
122+
github.com/cncf/xds/go v0.0.0-20240905190251-b4127c9b8d78/go.mod h1:W+zGtBO5Y1IgJhy4+A9GOqVhqLpfZi+vwmdNXUehLA8=
121123
github.com/cockroachdb/apd/v2 v2.0.2 h1:weh8u7Cneje73dDh+2tEVLUvyBc89iwepWCD8b8034E=
122124
github.com/cockroachdb/apd/v2 v2.0.2/go.mod h1:DDxRlzC2lo3/vSlmSoS7JkqbbrARPuFOGr0B9pvN3Gw=
123125
github.com/cockroachdb/apd/v3 v3.2.1 h1:U+8j7t0axsIgvQUqthuNm82HIrYXodOV2iWLWtEaIwg=
@@ -220,7 +222,11 @@ github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1m
220222
github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk=
221223
github.com/envoyproxy/go-control-plane v0.9.10-0.20210907150352-cf90f659a021/go.mod h1:AFq3mo9L8Lqqiid3OhADV3RfLJnjiw63cSpi+fDTRC0=
222224
github.com/envoyproxy/go-control-plane v0.10.2-0.20220325020618-49ff273808a1/go.mod h1:KJwIaB5Mv44NWtYuAOFCVOjcI94vtpEz2JU/D2v6IjE=
225+
github.com/envoyproxy/go-control-plane v0.13.1 h1:vPfJZCkob6yTMEgS+0TwfTUfbHjfy/6vOJ8hUWX/uXE=
226+
github.com/envoyproxy/go-control-plane v0.13.1/go.mod h1:X45hY0mufo6Fd0KW3rqsGvQMw58jvjymeCzBU3mWyHw=
223227
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
228+
github.com/envoyproxy/protoc-gen-validate v1.1.0 h1:tntQDh69XqOCOZsDz0lVJQez/2L6Uu2PdjCQwWCJ3bM=
229+
github.com/envoyproxy/protoc-gen-validate v1.1.0/go.mod h1:sXRDRVmzEbkM7CVcM06s9shE/m23dg3wzjl0UWqJ2q4=
224230
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
225231
github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=
226232
github.com/fatih/color v1.18.0 h1:S8gINlzdQ840/4pfAwic/ZE0djQEH3wM94VfqLTZcOM=
@@ -239,6 +245,8 @@ github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4
239245
github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU=
240246
github.com/fsnotify/fsnotify v1.8.0 h1:dAwr6QBTBZIkG8roQaJjGof0pp0EeF+tNV7YBP3F/8M=
241247
github.com/fsnotify/fsnotify v1.8.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0=
248+
github.com/fullstorydev/grpcurl v1.9.2 h1:ObqVQTZW7aFnhuqQoppUrvep2duMBanB0UYK2Mm8euo=
249+
github.com/fullstorydev/grpcurl v1.9.2/go.mod h1:jLfcF55HAz6TYIJY9xFFWgsl0D7o2HlxA5Z4lUG0Tdo=
242250
github.com/getsentry/sentry-go v0.30.0 h1:lWUwDnY7sKHaVIoZ9wYqRHJ5iEmoc0pqcRqFkosKzBo=
243251
github.com/getsentry/sentry-go v0.30.0/go.mod h1:WU9B9/1/sHDqeV8T+3VwwbjeR5MSXs/6aqG3mqZrezA=
244252
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
@@ -441,8 +449,8 @@ github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANyt
441449
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
442450
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
443451
github.com/influxdata/influxdb1-client v0.0.0-20191209144304-8bf82d3c094d/go.mod h1:qj24IKcXYK6Iy9ceXlo3Tc+vtHo9lIhSX5JddghvEPo=
444-
github.com/jhump/protoreflect v1.15.3 h1:6SFRuqU45u9hIZPJAoZ8c28T3nK64BNdp9w6jFonzls=
445-
github.com/jhump/protoreflect v1.15.3/go.mod h1:4ORHmSBmlCW8fh3xHmJMGyul1zNqZK4Elxc8qKP+p1k=
452+
github.com/jhump/protoreflect v1.16.0 h1:54fZg+49widqXYQ0b+usAFHbMkBGR4PpXrsHc8+TBDg=
453+
github.com/jhump/protoreflect v1.16.0/go.mod h1:oYPd7nPvcBw/5wlDfm/AVmU9zH9BgqGCI469pGxfj/8=
446454
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
447455
github.com/jmhodges/levigo v1.0.0 h1:q5EC36kV79HWeTBWsod3mG11EgStG3qArTKcvlksN1U=
448456
github.com/jmhodges/levigo v1.0.0/go.mod h1:Q6Qx+uH3RAqyK4rFQroq9RL7mdkABMcfhEI+nNuzMJQ=
@@ -609,6 +617,8 @@ github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE
609617
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
610618
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
611619
github.com/pkg/profile v1.2.1/go.mod h1:hJw3o1OdXxsrSjjVksARp5W95eeEaEfptyVZyv6JUPA=
620+
github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10 h1:GFCKgmp0tecUJ0sJuv4pzYCqS9+RGSn52M3FUwPs+uo=
621+
github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10/go.mod h1:t/avpk3KcrXxUnYOhZhMXJlSEyie6gQbtLq5NM3loB8=
612622
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
613623
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
614624
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=

0 commit comments

Comments
 (0)