From b08cb44353eb2055dcd914e30243d1caf9f4805f Mon Sep 17 00:00:00 2001
From: Alex Sharov <AskAlexSharov@gmail.com>
Date: Tue, 22 Feb 2022 16:23:54 +0700
Subject: [PATCH] embed rpcdaemon: enable it only by --http flag (#3574)

---
 cmd/rpcdaemon/cli/httpcfg/http_cfg.go |  1 +
 eth/backend.go                        | 40 ++++++++++++++-------------
 turbo/cli/flags.go                    |  1 +
 3 files changed, 23 insertions(+), 19 deletions(-)

diff --git a/cmd/rpcdaemon/cli/httpcfg/http_cfg.go b/cmd/rpcdaemon/cli/httpcfg/http_cfg.go
index 32d9dec7e7..80b417325d 100644
--- a/cmd/rpcdaemon/cli/httpcfg/http_cfg.go
+++ b/cmd/rpcdaemon/cli/httpcfg/http_cfg.go
@@ -6,6 +6,7 @@ import (
 )
 
 type HttpCfg struct {
+	Enabled                 bool
 	PrivateApiAddr          string
 	SingleNodeMode          bool // Erigon's database can be read by separated processes on same machine - in read-only mode - with full support of transactions. It will share same "OS PageCache" with Erigon process.
 	Datadir                 string
diff --git a/eth/backend.go b/eth/backend.go
index 5d36937f24..5c81738974 100644
--- a/eth/backend.go
+++ b/eth/backend.go
@@ -533,27 +533,29 @@ func New(stack *node.Node, config *ethconfig.Config, txpoolCfg txpool2.Config, l
 
 	// start HTTP API
 	httpRpcCfg := stack.Config().Http
-	ethRpcClient, txPoolRpcClient, miningRpcClient, starkNetRpcClient, stateCache, ff, err := cli.EmbeddedServices(
-		ctx, chainKv, httpRpcCfg.StateCache, blockReader,
-		ethBackendRPC,
-		backend.txPool2GrpcServer,
-		miningRPC,
-	)
-	if err != nil {
-		return nil, err
-	}
+	if httpRpcCfg.Enabled {
+		ethRpcClient, txPoolRpcClient, miningRpcClient, starkNetRpcClient, stateCache, ff, err := cli.EmbeddedServices(
+			ctx, chainKv, httpRpcCfg.StateCache, blockReader,
+			ethBackendRPC,
+			backend.txPool2GrpcServer,
+			miningRPC,
+		)
+		if err != nil {
+			return nil, err
+		}
 
-	var borDb kv.RoDB
-	if casted, ok := backend.engine.(*bor.Bor); ok {
-		borDb = casted.DB
-	}
-	apiList := commands.APIList(chainKv, borDb, ethRpcClient, txPoolRpcClient, miningRpcClient, starkNetRpcClient, ff, stateCache, blockReader, httpRpcCfg)
-	go func() {
-		if err := cli.StartRpcServer(ctx, httpRpcCfg, apiList); err != nil {
-			log.Error(err.Error())
-			return
+		var borDb kv.RoDB
+		if casted, ok := backend.engine.(*bor.Bor); ok {
+			borDb = casted.DB
 		}
-	}()
+		apiList := commands.APIList(chainKv, borDb, ethRpcClient, txPoolRpcClient, miningRpcClient, starkNetRpcClient, ff, stateCache, blockReader, httpRpcCfg)
+		go func() {
+			if err := cli.StartRpcServer(ctx, httpRpcCfg, apiList); err != nil {
+				log.Error(err.Error())
+				return
+			}
+		}()
+	}
 
 	// Register the backend on the node
 	stack.RegisterAPIs(backend.APIs())
diff --git a/turbo/cli/flags.go b/turbo/cli/flags.go
index 69f6e71f9a..c4a11e9a69 100644
--- a/turbo/cli/flags.go
+++ b/turbo/cli/flags.go
@@ -286,6 +286,7 @@ func ApplyFlagsForNodeConfig(ctx *cli.Context, cfg *node.Config) {
 
 func setEmbeddedRpcDaemon(ctx *cli.Context, cfg *node.Config) {
 	c := &httpcfg.HttpCfg{
+		Enabled:   ctx.GlobalBool(utils.HTTPEnabledFlag.Name),
 		Datadir:   cfg.DataDir,
 		Chaindata: filepath.Join(cfg.DataDir, "chaindata"),
 
-- 
GitLab