Skip to content

Commit

Permalink
feat: gRPC query for operator and chain configuration (backport #426) (
Browse files Browse the repository at this point in the history
…#427)

Co-authored-by: Roman <roman@osmosis.team>
  • Loading branch information
mergify[bot] and p0mvn authored Mar 25, 2023
1 parent f94c709 commit 8ee894c
Show file tree
Hide file tree
Showing 9 changed files with 845 additions and 5 deletions.
533 changes: 533 additions & 0 deletions client/grpc/node/query.pb.go

Large diffs are not rendered by default.

148 changes: 148 additions & 0 deletions client/grpc/node/query.pb.gw.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 42 additions & 0 deletions client/grpc/node/service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package node

import (
context "context"

gogogrpc "github.com/gogo/protobuf/grpc"
"github.com/grpc-ecosystem/grpc-gateway/runtime"

"github.com/cosmos/cosmos-sdk/client"
sdk "github.com/cosmos/cosmos-sdk/types"
)

// RegisterNodeService registers the node gRPC service on the provided gRPC router.
func RegisterNodeService(clientCtx client.Context, server gogogrpc.Server) {
RegisterServiceServer(server, NewQueryServer(clientCtx))
}

// RegisterGRPCGatewayRoutes mounts the node gRPC service's GRPC-gateway routes
// on the given mux object.
func RegisterGRPCGatewayRoutes(clientConn gogogrpc.ClientConn, mux *runtime.ServeMux) {
_ = RegisterServiceHandlerClient(context.Background(), mux, NewServiceClient(clientConn))
}

var _ ServiceServer = queryServer{}

type queryServer struct {
clientCtx client.Context
}

func NewQueryServer(clientCtx client.Context) ServiceServer {
return queryServer{
clientCtx: clientCtx,
}
}

func (s queryServer) Config(ctx context.Context, _ *ConfigRequest) (*ConfigResponse, error) {
sdkCtx := sdk.UnwrapSDKContext(ctx)

return &ConfigResponse{
MinimumGasPrice: sdkCtx.MinGasPrices().String(),
}, nil
}
23 changes: 23 additions & 0 deletions client/grpc/node/service_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package node

import (
"context"
"testing"

"github.com/stretchr/testify/require"

"github.com/cosmos/cosmos-sdk/client"
sdk "github.com/cosmos/cosmos-sdk/types"
)

func TestServiceServer_Config(t *testing.T) {
svr := NewQueryServer(client.Context{})

ctx := sdk.Context{}.WithContext(context.Background()).WithMinGasPrices(sdk.NewDecCoins(sdk.NewInt64DecCoin("stake", 15)))
goCtx := sdk.WrapSDKContext(ctx)

resp, err := svr.Config(goCtx, &ConfigRequest{})
require.NoError(t, err)
require.NotNil(t, resp)
require.Equal(t, ctx.MinGasPrices().String(), resp.MinimumGasPrice)
}
57 changes: 57 additions & 0 deletions docs/core/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,12 @@
- [Pair](#cosmos.base.kv.v1beta1.Pair)
- [Pairs](#cosmos.base.kv.v1beta1.Pairs)

- [cosmos/base/node/v1beta1/query.proto](#cosmos/base/node/v1beta1/query.proto)
- [ConfigRequest](#cosmos.base.node.v1beta1.ConfigRequest)
- [ConfigResponse](#cosmos.base.node.v1beta1.ConfigResponse)

- [Service](#cosmos.base.node.v1beta1.Service)

- [cosmos/base/reflection/v1beta1/reflection.proto](#cosmos/base/reflection/v1beta1/reflection.proto)
- [ListAllInterfacesRequest](#cosmos.base.reflection.v1beta1.ListAllInterfacesRequest)
- [ListAllInterfacesResponse](#cosmos.base.reflection.v1beta1.ListAllInterfacesResponse)
Expand Down Expand Up @@ -2322,6 +2328,57 @@ Pairs defines a repeated slice of Pair objects.



<a name="cosmos/base/node/v1beta1/query.proto"></a>
<p align="right"><a href="#top">Top</a></p>

## cosmos/base/node/v1beta1/query.proto



<a name="cosmos.base.node.v1beta1.ConfigRequest"></a>

### ConfigRequest
ConfigRequest defines the request structure for the Config gRPC query.






<a name="cosmos.base.node.v1beta1.ConfigResponse"></a>

### ConfigResponse
ConfigResponse defines the response structure for the Config gRPC query.


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `minimum_gas_price` | [string](#string) | | |





<!-- end messages -->

<!-- end enums -->

<!-- end HasExtensions -->


<a name="cosmos.base.node.v1beta1.Service"></a>

### Service
Service defines the gRPC querier service for node related queries.

| Method Name | Request Type | Response Type | Description | HTTP Verb | Endpoint |
| ----------- | ------------ | ------------- | ------------| ------- | -------- |
| `Config` | [ConfigRequest](#cosmos.base.node.v1beta1.ConfigRequest) | [ConfigResponse](#cosmos.base.node.v1beta1.ConfigResponse) | Config queries for the operator configuration. | GET|/cosmos/base/node/v1beta1/config|

<!-- end services -->



<a name="cosmos/base/reflection/v1beta1/reflection.proto"></a>
<p align="right"><a href="#top">Top</a></p>

Expand Down
22 changes: 22 additions & 0 deletions proto/cosmos/base/node/v1beta1/query.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
syntax = "proto3";
package cosmos.base.node.v1beta1;

import "google/api/annotations.proto";

option go_package = "github.com/cosmos/cosmos-sdk/client/grpc/node";

// Service defines the gRPC querier service for node related queries.
service Service {
// Config queries for the operator configuration.
rpc Config(ConfigRequest) returns (ConfigResponse) {
option (google.api.http).get = "/cosmos/base/node/v1beta1/config";
}
}

// ConfigRequest defines the request structure for the Config gRPC query.
message ConfigRequest {}

// ConfigResponse defines the response structure for the Config gRPC query.
message ConfigResponse {
string minimum_gas_price = 1;
}
4 changes: 4 additions & 0 deletions server/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,10 @@ func startInProcess(ctx *Context, clientCtx client.Context, appCreator types.App

app.RegisterTxService(clientCtx)
app.RegisterTendermintService(clientCtx)

if a, ok := app.(types.ApplicationQueryService); ok {
a.RegisterNodeService(clientCtx)
}
}

if config.GRPC.Concurrency {
Expand Down
14 changes: 12 additions & 2 deletions server/types/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,20 @@ type (

// RegisterTxService registers the gRPC Query service for tx (such as tx
// simulation, fetching txs by hash...).
RegisterTxService(clientCtx client.Context)
RegisterTxService(client.Context)

// RegisterTendermintService registers the gRPC Query service for tendermint queries.
RegisterTendermintService(clientCtx client.Context)
RegisterTendermintService(client.Context)
}

// ApplicationQueryService defines an extension of the Application interface
// that facilitates gRPC query Services.
//
// NOTE: This interfaces exists only in the v0.46.x line to ensure the existing
// Application interface does not introduce API breaking changes.
ApplicationQueryService interface {
// RegisterNodeService registers the node gRPC Query service.
RegisterNodeService(client.Context)
}

// AppCreator is a function that allows us to lazily initialize an
Expand Down
7 changes: 4 additions & 3 deletions testutil/network/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,12 @@ func startInProcess(cfg Config, val *Validator) error {
val.ClientCtx = val.ClientCtx.
WithClient(val.RPCClient)

// Add the tx service in the gRPC router.
app.RegisterTxService(val.ClientCtx)

// Add the tendermint queries service in the gRPC router.
app.RegisterTendermintService(val.ClientCtx)

if a, ok := app.(srvtypes.ApplicationQueryService); ok {
a.RegisterNodeService(val.ClientCtx)
}
}

if val.APIAddress != "" {
Expand Down

0 comments on commit 8ee894c

Please sign in to comment.