From 18f9313c8520e45c2d48af0f8759b74de11e43c3 Mon Sep 17 00:00:00 2001 From: Enrique Jose Avila Asapche Date: Fri, 19 Aug 2022 12:20:51 +0300 Subject: [PATCH] added config file slice support (#5122) * added config file slice support * ReadMe update --- README.md | 42 ++++++++++++++++++++++++++++++++++++++++++ cmd/erigon/main.go | 24 +++++++++++++++++++----- 2 files changed, 61 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index eaaaaf276..4d2ef7c5a 100644 --- a/README.md +++ b/README.md @@ -175,6 +175,48 @@ C:\ProgramData\chocolatey\lib\mingw\tools\install\mingw64\bin **Please also note the default WSL2 environment has its own IP address which does not match the one of the network interface of Windows host: take this into account when configuring NAT for port 30303 on your router.** +### Using TOML or YAML Config Files + +You can set Erigon flags through a YAML or TOML configuration file with the flag `--config`. The flags set in the configuration +file can be overwritten by writing the flags directly on Erigon command line + +## Example + +`./build/bin/erigon --config ./config.yaml --chain=goerli + +Assuming we have `chain : "mainnet" in our configuration file, by adding `--chain=goerli` allows the overwrite of the flag inside +of the yaml configuration file and sets the chain to goerli + +## TOML + +Example of setting up TOML config file + +``` +`datadir = 'your datadir' +port = "1111" +chain = "mainnet" +http = "true" +"private.api.addr"="localhost:9090" + +"http.api" = ["eth","debug","net"] +``` + +## YAML + +Example of setting up a YAML config file + +``` +datadir : 'your datadir' +port : "1111" +chain : "mainnet" +http : "true" +private.api.addr : "localhost:9090" + +http.api : ["eth","debug","net"] +``` + + + ### Beacon Chain (Consensus Layer) Erigon can be used as an Execution Layer (EL) for Consensus Layer clients (CL). Default configuration is OK. CL diff --git a/cmd/erigon/main.go b/cmd/erigon/main.go index 5bba59e11..f66075888 100644 --- a/cmd/erigon/main.go +++ b/cmd/erigon/main.go @@ -5,6 +5,8 @@ import ( "fmt" "os" "path/filepath" + "reflect" + "strings" "github.com/ledgerwatch/erigon-lib/common/dbg" "github.com/ledgerwatch/erigon/cmd/utils" @@ -68,7 +70,7 @@ func runErigon(cliCtx *cli.Context) { func setFlagsFromConfigFile(ctx *cli.Context, filePath string) error { fileExtension := filepath.Ext(filePath) - fileConfig := make(map[string]string) + fileConfig := make(map[string]interface{}) if fileExtension == ".yaml" { yamlFile, err := os.ReadFile(filePath) @@ -91,13 +93,25 @@ func setFlagsFromConfigFile(ctx *cli.Context, filePath string) error { } else { return errors.New("config files only accepted are .yaml and .toml") } - // sets global flags to value in yaml/toml file for key, value := range fileConfig { if !ctx.GlobalIsSet(key) { - err := ctx.GlobalSet(key, value) - if err != nil { - return err + if reflect.ValueOf(value).Kind() == reflect.Slice { + sliceInterface := value.([]interface{}) + s := make([]string, len(sliceInterface)) + for i, v := range sliceInterface { + s[i] = v.(string) + } + fmt.Println(s) + err := ctx.GlobalSet(key, strings.Join(s[:], ",")) + if err != nil { + return err + } + } else { + err := ctx.GlobalSet(key, value.(string)) + if err != nil { + return err + } } } }