Fix creation of local RPC node in clientCtx (#7840)

* server: only register the Tx service if the API or gRPC are enabled

Only registers the Tx service on an app, if either API or gRPC are enabled.
This is because, enabling the service starts a local Tendermint node, which
is unnecessary and expensive, if neither of those operations are explicitly
enabled.

* Fix lint

Co-authored-by: Alessio Treglia <alessio@tendermint.com>
This commit is contained in:
Amaury Martiny 2020-11-10 14:01:55 +01:00 committed by GitHub
parent fe8a891f11
commit 15b285dd0d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 5 deletions

View File

@ -252,12 +252,20 @@ func startInProcess(ctx *Context, clientCtx client.Context, appCreator types.App
}
ctx.Logger.Debug("Initialization: tmNode started")
// Add the tx service to the gRPC router.
app.RegisterTxService(clientCtx)
config := config.GetConfig(ctx.Viper)
// 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 tendermint RPC client.
if config.API.Enable || config.GRPC.Enable {
clientCtx = clientCtx.
WithClient(local.New(tmNode))
app.RegisterTxService(clientCtx)
}
var apiSrv *api.Server
config := config.GetConfig(ctx.Viper)
if config.API.Enable {
genDoc, err := genDocProvider()
if err != nil {
@ -266,8 +274,7 @@ func startInProcess(ctx *Context, clientCtx client.Context, appCreator types.App
clientCtx := clientCtx.
WithHomeDir(home).
WithChainID(genDoc.ChainID).
WithClient(local.New(tmNode))
WithChainID(genDoc.ChainID)
apiSrv = api.New(clientCtx, ctx.Logger.With("module", "api-server"))
app.RegisterAPIRoutes(apiSrv, config.API)