feat!: support custom r/w gRPC options (#11889)
This commit is contained in:
+24
-7
@@ -2,13 +2,13 @@ package grpc
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
"net"
|
||||
"time"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/server/config"
|
||||
"github.com/cosmos/cosmos-sdk/server/grpc/gogoreflection"
|
||||
reflection "github.com/cosmos/cosmos-sdk/server/grpc/reflection/v2alpha1"
|
||||
"github.com/cosmos/cosmos-sdk/server/types"
|
||||
@@ -16,14 +16,27 @@ import (
|
||||
)
|
||||
|
||||
// StartGRPCServer starts a gRPC server on the given address.
|
||||
func StartGRPCServer(clientCtx client.Context, app types.Application, address string) (*grpc.Server, error) {
|
||||
func StartGRPCServer(clientCtx client.Context, app types.Application, cfg config.GRPCConfig) (*grpc.Server, error) {
|
||||
maxSendMsgSize := cfg.MaxSendMsgSize
|
||||
if maxSendMsgSize == 0 {
|
||||
maxSendMsgSize = config.DefaultGRPCMaxSendMsgSize
|
||||
}
|
||||
|
||||
maxRecvMsgSize := cfg.MaxRecvMsgSize
|
||||
if maxRecvMsgSize == 0 {
|
||||
maxRecvMsgSize = config.DefaultGRPCMaxRecvMsgSize
|
||||
}
|
||||
|
||||
grpcSrv := grpc.NewServer(
|
||||
grpc.ForceServerCodec(codec.NewProtoCodec(clientCtx.InterfaceRegistry).GRPCCodec()),
|
||||
grpc.MaxSendMsgSize(maxSendMsgSize),
|
||||
grpc.MaxRecvMsgSize(maxRecvMsgSize),
|
||||
)
|
||||
|
||||
app.RegisterGRPCServer(grpcSrv)
|
||||
// reflection allows consumers to build dynamic clients that can write
|
||||
// to any cosmos-sdk application without relying on application packages at compile time
|
||||
|
||||
// Reflection allows consumers to build dynamic clients that can write to any
|
||||
// Cosmos SDK application without relying on application packages at compile
|
||||
// time.
|
||||
err := reflection.Register(grpcSrv, reflection.Config{
|
||||
SigningModes: func() map[string]int32 {
|
||||
modes := make(map[string]int32, len(clientCtx.TxConfig.SignModeHandler().Modes()))
|
||||
@@ -39,10 +52,12 @@ func StartGRPCServer(clientCtx client.Context, app types.Application, address st
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Reflection allows external clients to see what services and methods
|
||||
// the gRPC server exposes.
|
||||
gogoreflection.Register(grpcSrv)
|
||||
listener, err := net.Listen("tcp", address)
|
||||
|
||||
listener, err := net.Listen("tcp", cfg.Address)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -58,7 +73,9 @@ func StartGRPCServer(clientCtx client.Context, app types.Application, address st
|
||||
select {
|
||||
case err := <-errCh:
|
||||
return nil, err
|
||||
case <-time.After(types.ServerStartTime): // assume server started successfully
|
||||
|
||||
case <-time.After(types.ServerStartTime):
|
||||
// assume server started successfully
|
||||
return grpcSrv, nil
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user