Skip to content

Commit

Permalink
fix(cometbft/grpc): gRPC path parsing (#22081)
Browse files Browse the repository at this point in the history
  • Loading branch information
testinginprod authored Oct 3, 2024
1 parent 30003f6 commit e914910
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 2 additions & 0 deletions server/v2/api/grpc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ func makeUnknownServiceHandler(handlers map[string]appmodulev2.Handler, querier
if err != nil {
return fmt.Errorf("failed to get registry: %w", err)
}

method = strings.TrimPrefix(method, "/")
fullName := protoreflect.FullName(strings.ReplaceAll(method, "/", "."))
// get descriptor from the invoke method
desc, err := registry.FindDescriptorByName(fullName)
Expand Down
9 changes: 5 additions & 4 deletions server/v2/cometbft/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,13 @@ func (c *Consensus[T]) maybeRunGRPCQuery(ctx context.Context, req *abci.QueryReq
return nil, false, err
}

path := strings.TrimPrefix(req.Path, "/")
pathFullName := protoreflect.FullName(strings.ReplaceAll(path, "/", "."))

// in order to check if it's a gRPC query we ensure that there's a descriptor
// for the path, if such descriptor exists, and it is a method descriptor
// then we assume this is a gRPC query.
fullName := protoreflect.FullName(strings.ReplaceAll(req.Path, "/", "."))

desc, err := registry.FindDescriptorByName(fullName)
desc, err := registry.FindDescriptorByName(pathFullName)
if err != nil {
return nil, false, err
}
Expand All @@ -262,7 +263,7 @@ func (c *Consensus[T]) maybeRunGRPCQuery(ctx context.Context, req *abci.QueryReq

handler, found := c.queryHandlersMap[string(md.Input().FullName())]
if !found {
return nil, true, fmt.Errorf("no query handler found for %s", fullName)
return nil, true, fmt.Errorf("no query handler found for %s", req.Path)
}
protoRequest := handler.MakeMsg()
err = gogoproto.Unmarshal(req.Data, protoRequest) // TODO: use codec
Expand Down

0 comments on commit e914910

Please sign in to comment.