Skip to content

Commit

Permalink
added config file slice support (#5122)
Browse files Browse the repository at this point in the history
* added config file slice support

* ReadMe update
  • Loading branch information
enriavil1 authored Aug 19, 2022
1 parent d794420 commit 18f9313
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 5 deletions.
42 changes: 42 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 19 additions & 5 deletions cmd/erigon/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"fmt"
"os"
"path/filepath"
"reflect"
"strings"

"github.com/ledgerwatch/erigon-lib/common/dbg"
"github.com/ledgerwatch/erigon/cmd/utils"
Expand Down Expand Up @@ -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)
Expand All @@ -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
}
}
}
}
Expand Down

0 comments on commit 18f9313

Please sign in to comment.