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:
parent
fe8a891f11
commit
15b285dd0d
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue