Skip to content

Commit 18f9313

Browse files
authored
added config file slice support (#5122)
* added config file slice support * ReadMe update
1 parent d794420 commit 18f9313

File tree

2 files changed

+61
-5
lines changed

2 files changed

+61
-5
lines changed

README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,48 @@ C:\ProgramData\chocolatey\lib\mingw\tools\install\mingw64\bin
175175
**Please also note the default WSL2 environment has its own IP address which does not match the one of the network
176176
interface of Windows host: take this into account when configuring NAT for port 30303 on your router.**
177177

178+
### Using TOML or YAML Config Files
179+
180+
You can set Erigon flags through a YAML or TOML configuration file with the flag `--config`. The flags set in the configuration
181+
file can be overwritten by writing the flags directly on Erigon command line
182+
183+
## Example
184+
185+
`./build/bin/erigon --config ./config.yaml --chain=goerli
186+
187+
Assuming we have `chain : "mainnet" in our configuration file, by adding `--chain=goerli` allows the overwrite of the flag inside
188+
of the yaml configuration file and sets the chain to goerli
189+
190+
## TOML
191+
192+
Example of setting up TOML config file
193+
194+
```
195+
`datadir = 'your datadir'
196+
port = "1111"
197+
chain = "mainnet"
198+
http = "true"
199+
"private.api.addr"="localhost:9090"
200+
201+
"http.api" = ["eth","debug","net"]
202+
```
203+
204+
## YAML
205+
206+
Example of setting up a YAML config file
207+
208+
```
209+
datadir : 'your datadir'
210+
port : "1111"
211+
chain : "mainnet"
212+
http : "true"
213+
private.api.addr : "localhost:9090"
214+
215+
http.api : ["eth","debug","net"]
216+
```
217+
218+
219+
178220
### Beacon Chain (Consensus Layer)
179221

180222
Erigon can be used as an Execution Layer (EL) for Consensus Layer clients (CL). Default configuration is OK. CL

cmd/erigon/main.go

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
"fmt"
66
"os"
77
"path/filepath"
8+
"reflect"
9+
"strings"
810

911
"github.com/ledgerwatch/erigon-lib/common/dbg"
1012
"github.com/ledgerwatch/erigon/cmd/utils"
@@ -68,7 +70,7 @@ func runErigon(cliCtx *cli.Context) {
6870
func setFlagsFromConfigFile(ctx *cli.Context, filePath string) error {
6971
fileExtension := filepath.Ext(filePath)
7072

71-
fileConfig := make(map[string]string)
73+
fileConfig := make(map[string]interface{})
7274

7375
if fileExtension == ".yaml" {
7476
yamlFile, err := os.ReadFile(filePath)
@@ -91,13 +93,25 @@ func setFlagsFromConfigFile(ctx *cli.Context, filePath string) error {
9193
} else {
9294
return errors.New("config files only accepted are .yaml and .toml")
9395
}
94-
9596
// sets global flags to value in yaml/toml file
9697
for key, value := range fileConfig {
9798
if !ctx.GlobalIsSet(key) {
98-
err := ctx.GlobalSet(key, value)
99-
if err != nil {
100-
return err
99+
if reflect.ValueOf(value).Kind() == reflect.Slice {
100+
sliceInterface := value.([]interface{})
101+
s := make([]string, len(sliceInterface))
102+
for i, v := range sliceInterface {
103+
s[i] = v.(string)
104+
}
105+
fmt.Println(s)
106+
err := ctx.GlobalSet(key, strings.Join(s[:], ","))
107+
if err != nil {
108+
return err
109+
}
110+
} else {
111+
err := ctx.GlobalSet(key, value.(string))
112+
if err != nil {
113+
return err
114+
}
101115
}
102116
}
103117
}

0 commit comments

Comments
 (0)