feat(server): start grpc server and register services in standalone mode (#18110)

Co-authored-by: Marko <marko@baricevic.me>
This commit is contained in:
Philip Offtermatt
2023-10-18 10:32:53 +00:00
committed by GitHub
co-authored by Marko
parent 50f936f60e
commit 31f5bc07e9
3 changed files with 44 additions and 2 deletions
+36 -2
View File
@@ -16,6 +16,7 @@ import (
"github.com/cometbft/cometbft/p2p"
pvm "github.com/cometbft/cometbft/privval"
"github.com/cometbft/cometbft/proxy"
rpchttp "github.com/cometbft/cometbft/rpc/client/http"
"github.com/cometbft/cometbft/rpc/client/local"
cmttypes "github.com/cometbft/cometbft/types"
dbm "github.com/cosmos/cosmos-db"
@@ -258,12 +259,12 @@ func start(svrCtx *Context, clientCtx client.Context, appCreator types.AppCreato
emitServerInfoMetrics()
if !withCmt {
return startStandAlone(svrCtx, app, opts)
return startStandAlone(svrCtx, svrCfg, clientCtx, app, metrics, opts)
}
return startInProcess(svrCtx, svrCfg, clientCtx, app, metrics, opts)
}
func startStandAlone(svrCtx *Context, app types.Application, opts StartCmdOptions) error {
func startStandAlone(svrCtx *Context, svrCfg serverconfig.Config, clientCtx client.Context, app types.Application, metrics *telemetry.Metrics, opts StartCmdOptions) error {
addr := svrCtx.Viper.GetString(flagAddress)
transport := svrCtx.Viper.GetString(flagTransport)
@@ -277,6 +278,39 @@ func startStandAlone(svrCtx *Context, app types.Application, opts StartCmdOption
g, ctx := getCtx(svrCtx, false)
// Add the tx service to the gRPC router. We only need to register this
// service if API or gRPC is enabled, and avoid doing so in the general
// case, because it spawns a new local CometBFT RPC client.
if svrCfg.API.Enable || svrCfg.GRPC.Enable {
// create tendermint client
// assumes the rpc listen address is where tendermint has its rpc server
rpcclient, err := rpchttp.New(svrCtx.Config.RPC.ListenAddress, "/websocket")
if err != nil {
return err
}
// re-assign for making the client available below
// do not use := to avoid shadowing clientCtx
clientCtx = clientCtx.WithClient(rpcclient)
// use the provided clientCtx to register the services
app.RegisterTxService(clientCtx)
app.RegisterTendermintService(clientCtx)
app.RegisterNodeService(clientCtx, svrCfg)
}
grpcSrv, clientCtx, err := startGrpcServer(ctx, g, svrCfg.GRPC, clientCtx, svrCtx, app)
if err != nil {
return err
}
cmtCfg := svrCtx.Config
home := cmtCfg.RootDir
err = startAPIServer(ctx, g, cmtCfg, svrCfg, clientCtx, svrCtx, app, home, grpcSrv, metrics)
if err != nil {
return err
}
g.Go(func() error {
if err := svr.Start(); err != nil {
svrCtx.Logger.Error("failed to start out-of-process ABCI server", "err", err)