Skip to content

Commit

Permalink
Fix creation of local RPC node in clientCtx (#7840)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
amaury1093 and Alessio Treglia authored Nov 10, 2020
1 parent fe8a891 commit 15b285d
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions server/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand Down

0 comments on commit 15b285d

Please sign in to comment.