From f4bf94f78ad6088964b32874b274ee6743fceb8e Mon Sep 17 00:00:00 2001
From: Giulio rebuffo <giulio.rebuffo@gmail.com>
Date: Thu, 24 Mar 2022 03:10:29 +0100
Subject: [PATCH] Fixed Erigon README for Authentication API and jwt.hex
 generates in Datadir (#3757)

* added datadir jwt

* fixed readme
---
 README.md          | 8 ++++++++
 cmd/utils/flags.go | 4 ++--
 turbo/cli/flags.go | 6 +++++-
 3 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/README.md b/README.md
index 1a680b5631..65e7c7e342 100644
--- a/README.md
+++ b/README.md
@@ -157,6 +157,14 @@ Once the JSON-RPC daemon is running, all you need to do is point your beacon cha
 where `<ip address>` is either localhost or the IP address of the device running the JSON-RPC daemon.
 
 Erigon has been tested with Lighthouse however all other clients that support JSON-RPC should also work.
+
+### Authentication API
+
+In order to establish a secure connection beetwen the Consensus Layer and the Execution Layer, a JWT secret key is automatically generated.
+
+The JWT secret key will be present in the datadir by default under the name of `jwt.hex` and its path can be specified with the flag `--authrpc.jwtsecret`.
+
+This piece of info needs to be specified in the Consensus Layer as well in order to establish connection successfully. More information can be found [here](https://github.com/ethereum/execution-apis/blob/main/src/engine/authentication.md)
     
 ### Multiple Instances / One Machine
 
diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go
index 662ea391d1..ac1b974728 100644
--- a/cmd/utils/flags.go
+++ b/cmd/utils/flags.go
@@ -331,8 +331,8 @@ var (
 
 	JWTSecretPath = cli.StringFlag{
 		Name:  "authrpc.jwtsecret",
-		Usage: "Token to ensure safe connection between CL and EL",
-		Value: "jwt.hex",
+		Usage: "Path to the token that ensures safe connection between CL and EL",
+		Value: "",
 	}
 
 	HttpCompressionFlag = cli.BoolFlag{
diff --git a/turbo/cli/flags.go b/turbo/cli/flags.go
index 1d3b8e6cea..9c5823aaa0 100644
--- a/turbo/cli/flags.go
+++ b/turbo/cli/flags.go
@@ -285,6 +285,10 @@ func ApplyFlagsForNodeConfig(ctx *cli.Context, cfg *node.Config) {
 }
 
 func setEmbeddedRpcDaemon(ctx *cli.Context, cfg *node.Config) {
+	jwtSecretPath := ctx.GlobalString(utils.JWTSecretPath.Name)
+	if jwtSecretPath == "" {
+		jwtSecretPath = cfg.DataDir + "/jwt.hex"
+	}
 	c := &httpcfg.HttpCfg{
 		Enabled:   ctx.GlobalBool(utils.HTTPEnabledFlag.Name),
 		DataDir:   cfg.DataDir,
@@ -298,7 +302,7 @@ func setEmbeddedRpcDaemon(ctx *cli.Context, cfg *node.Config) {
 		HttpPort:                ctx.GlobalInt(utils.HTTPPortFlag.Name),
 		EngineHTTPListenAddress: ctx.GlobalString(utils.EngineAddr.Name),
 		EnginePort:              ctx.GlobalInt(utils.EnginePort.Name),
-		JWTSecretPath:           ctx.GlobalString(utils.JWTSecretPath.Name),
+		JWTSecretPath:           jwtSecretPath,
 		HttpCORSDomain:          strings.Split(ctx.GlobalString(utils.HTTPCORSDomainFlag.Name), ","),
 		HttpVirtualHost:         strings.Split(ctx.GlobalString(utils.HTTPVirtualHostsFlag.Name), ","),
 		API:                     strings.Split(ctx.GlobalString(utils.HTTPApiFlag.Name), ","),
-- 
GitLab