From 15b285dd0d707bbf941c535698f3b5bc0b3a84cc Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Tue, 10 Nov 2020 14:01:55 +0100 Subject: [PATCH] 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 --- server/start.go | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/server/start.go b/server/start.go index 2a2a1af886ee..b8565a87a350 100644 --- a/server/start.go +++ b/server/start.go @@ -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)