From 6b64a1b9941f7fc0edadb36daabdd529e49e8cd9 Mon Sep 17 00:00:00 2001 From: RubyEDE Date: Thu, 3 Jul 2025 17:26:57 +0300 Subject: [PATCH] cmd/blsync: use default JWT secret path when datadir is specified Implements the TODO to automatically use jwtsecret file from the specified datadir when --blsync.jwtsecret is not explicitly provided. This matches the behavior of the main geth command and improves UX by reducing required command line arguments. --- cmd/blsync/main.go | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/cmd/blsync/main.go b/cmd/blsync/main.go index 39a9407304..5cb9fa5da1 100644 --- a/cmd/blsync/main.go +++ b/cmd/blsync/main.go @@ -20,6 +20,7 @@ import ( "context" "fmt" "os" + "path/filepath" "slices" "github.com/ethereum/go-ethereum/beacon/blsync" @@ -51,6 +52,7 @@ func main() { utils.HoodiFlag, utils.BlsyncApiFlag, utils.BlsyncJWTSecretFlag, + utils.DataDirFlag, }, debug.Flags, ) @@ -87,11 +89,20 @@ func makeRPCClient(ctx *cli.Context) *rpc.Client { log.Warn("No engine API target specified, performing a dry run") return nil } - if !ctx.IsSet(utils.BlsyncJWTSecretFlag.Name) { - utils.Fatalf("JWT secret parameter missing") //TODO use default if datadir is specified + + engineApiUrl := ctx.String(utils.BlsyncApiFlag.Name) + var jwtFileName string + + if ctx.IsSet(utils.BlsyncJWTSecretFlag.Name) { + jwtFileName = ctx.String(utils.BlsyncJWTSecretFlag.Name) + } else if ctx.IsSet(utils.DataDirFlag.Name) { + // Use default JWT secret path in the specified datadir + datadir := ctx.String(utils.DataDirFlag.Name) + jwtFileName = filepath.Join(datadir, "jwtsecret") + } else { + utils.Fatalf("JWT secret parameter missing and no datadir specified. Use --blsync.jwtsecret or --datadir") } - engineApiUrl, jwtFileName := ctx.String(utils.BlsyncApiFlag.Name), ctx.String(utils.BlsyncJWTSecretFlag.Name) var jwtSecret [32]byte if jwt, err := node.ObtainJWTSecret(jwtFileName); err == nil { copy(jwtSecret[:], jwt)