Add gRPC server & reflection (#6463)
* Add gRPC proxy * Make GRPC disabled by default * WIP on integration tests * WIP on integration tests * Start setting up in process tests * Start setting up in process tests * Make it compile * Add start server to network util * Add Println * Use go routine * Fix scopelint * Move to proxy_test * Add response type cache * Remove proxy * Tweaks * Use channel to handle error * Use error chan * Update server/start.go Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com> * Use %w * Add sdk.Context * Add comments * Fix lint * Add header and tests * Address comments * Factorize some code * Fix lint * Add height and prove in req metadata * Add reflection test * Fix lint * Put grpc test in server/grpc * Update baseapp/grpcserver.go * Update baseapp/grpcserver.go * Remove proof header Co-authored-by: Amaury Martiny <amaury.martiny@protonmail.com> Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com> Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com> Co-authored-by: SaReN <sahithnarahari@gmail.com>
This commit is contained in:
co-authored by
Federico Kunze
Amaury Martiny
Alexander Bezobchuk
SaReN
parent
20488b4f8e
commit
e9534b0935
@@ -24,6 +24,7 @@ import (
|
||||
"github.com/tendermint/tendermint/node"
|
||||
tmclient "github.com/tendermint/tendermint/rpc/client"
|
||||
dbm "github.com/tendermint/tm-db"
|
||||
"google.golang.org/grpc"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/baseapp"
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
@@ -33,6 +34,7 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/server"
|
||||
"github.com/cosmos/cosmos-sdk/server/api"
|
||||
srvconfig "github.com/cosmos/cosmos-sdk/server/config"
|
||||
servertypes "github.com/cosmos/cosmos-sdk/server/types"
|
||||
"github.com/cosmos/cosmos-sdk/simapp"
|
||||
storetypes "github.com/cosmos/cosmos-sdk/store/types"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
@@ -47,9 +49,9 @@ var lock = new(sync.Mutex)
|
||||
|
||||
// AppConstructor defines a function which accepts a network configuration and
|
||||
// creates an ABCI Application to provide to Tendermint.
|
||||
type AppConstructor = func(val Validator) server.Application
|
||||
type AppConstructor = func(val Validator) servertypes.Application
|
||||
|
||||
func NewSimApp(val Validator) server.Application {
|
||||
func NewSimApp(val Validator) servertypes.Application {
|
||||
return simapp.NewSimApp(
|
||||
val.Ctx.Logger, dbm.NewMemDB(), nil, true, make(map[int64]bool), val.Ctx.Config.RootDir, 0,
|
||||
baseapp.SetPruning(storetypes.NewPruningOptionsFromString(val.AppConfig.Pruning)),
|
||||
@@ -120,7 +122,7 @@ type (
|
||||
BaseDir string
|
||||
Validators []*Validator
|
||||
|
||||
config Config
|
||||
Config Config
|
||||
}
|
||||
|
||||
// Validator defines an in-process Tendermint validator node. Through this object,
|
||||
@@ -143,6 +145,7 @@ type (
|
||||
|
||||
tmNode *node.Node
|
||||
api *api.Server
|
||||
grpc *grpc.Server
|
||||
}
|
||||
)
|
||||
|
||||
@@ -159,7 +162,7 @@ func New(t *testing.T, cfg Config) *Network {
|
||||
T: t,
|
||||
BaseDir: baseDir,
|
||||
Validators: make([]*Validator, cfg.NumValidators),
|
||||
config: cfg,
|
||||
Config: cfg,
|
||||
}
|
||||
|
||||
t.Log("preparing test network...")
|
||||
@@ -205,6 +208,11 @@ func New(t *testing.T, cfg Config) *Network {
|
||||
rpcAddr, _, err := server.FreeTCPAddr()
|
||||
require.NoError(t, err)
|
||||
tmCfg.RPC.ListenAddress = rpcAddr
|
||||
|
||||
_, grpcPort, err := server.FreeTCPAddr()
|
||||
require.NoError(t, err)
|
||||
appCfg.GRPC.Address = fmt.Sprintf("0.0.0.0:%s", grpcPort)
|
||||
appCfg.GRPC.Enable = true
|
||||
}
|
||||
|
||||
logger := log.NewNopLogger()
|
||||
@@ -431,7 +439,7 @@ func (n *Network) Cleanup() {
|
||||
}
|
||||
}
|
||||
|
||||
if n.config.CleanupDir {
|
||||
if n.Config.CleanupDir {
|
||||
_ = os.RemoveAll(n.BaseDir)
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ import (
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
"github.com/cosmos/cosmos-sdk/server/api"
|
||||
servergrpc "github.com/cosmos/cosmos-sdk/server/grpc"
|
||||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/genutil"
|
||||
@@ -82,6 +83,15 @@ func startInProcess(cfg Config, val *Validator) error {
|
||||
val.api = apiSrv
|
||||
}
|
||||
|
||||
if val.AppConfig.GRPC.Enable {
|
||||
grpcSrv, err := servergrpc.StartGRPCServer(app, val.AppConfig.GRPC.Address)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
val.grpc = grpcSrv
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user