Skip to content

Commit

Permalink
feat: Set IP for all clients during init (#268)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wolmin authored Nov 27, 2024
1 parent 57b0262 commit 4260ab7
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 42 deletions.
113 changes: 78 additions & 35 deletions commands/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,69 +96,112 @@ func setIPInConfigs() (err error) {
name string
fileType string
flagsToChange []string
// wrap is an optional func that should edit the ip flag value.
wrap func(string) string
}

prysmFlagsToChange := []string{"p2p-host-ip"}
lighthouseFlagsToChange := []string{"enr-address"}
tekuFlagsToChange := []string{"p2p-advertised-ip"}
natWrap := func(s string) string {
return "extip:" + s
}

gethFlags := []string{"nat"}
erigonFlags := []string{"nat"}
besuFlags := []string{"p2p-host"}
nethermindFlags := []string{"Network.ExternalIp"}
prysmFlags := []string{"p2p-host-ip"}
lighthouseFlags := []string{"enr-address"}
tekuFlags := []string{"p2p-advertised-ip"}
nimbusFlags := []string{"nat"}

configs := []tempConfig{
{
path: "./configs/testnet/prysm",
name: "prysm",
fileType: "yaml",
flagsToChange: prysmFlagsToChange,
path: "./configs/%s/geth",
name: "geth",
fileType: "toml",
flagsToChange: gethFlags,
wrap: natWrap,
},
{
path: "./configs/testnet/lighthouse",
name: "lighthouse",
path: "./configs/%s/erigon",
name: "erigon",
fileType: "toml",
flagsToChange: lighthouseFlagsToChange,
flagsToChange: erigonFlags,
wrap: natWrap,
},
{
path: "./configs/testnet/teku",
name: "teku",
fileType: "yaml",
flagsToChange: tekuFlagsToChange,
path: "./configs/%s/besu",
name: "besu",
fileType: "toml",
flagsToChange: besuFlags,
wrap: nil,
},
{
path: "./configs/%s/nethermind",
name: "nethermind",
fileType: "json",
flagsToChange: nethermindFlags,
wrap: nil,
},
{
path: "./configs/mainnet/prysm",
path: "./configs/%s/prysm",
name: "prysm",
fileType: "yaml",
flagsToChange: prysmFlagsToChange,
flagsToChange: prysmFlags,
wrap: nil,
},
{
path: "./configs/mainnet/lighthouse",
path: "./configs/%s/lighthouse",
name: "lighthouse",
fileType: "toml",
flagsToChange: lighthouseFlagsToChange,
flagsToChange: lighthouseFlags,
wrap: nil,
},
{
path: "./configs/mainnet/teku",
path: "./configs/%s/teku",
name: "teku",
fileType: "yaml",
flagsToChange: tekuFlagsToChange,
flagsToChange: tekuFlags,
wrap: nil,
},
{
path: "./configs/%s/nimbus2",
name: "nimbus",
fileType: "toml",
flagsToChange: nimbusFlags,
wrap: natWrap,
},
}

for _, cfg := range configs {
v := viper.New()
networks := []string{"mainnet", "testnet"}

v.AddConfigPath(cfg.path)
v.SetConfigName(cfg.name)
v.SetConfigType(cfg.fileType)
for _, network := range networks {
for _, cfg := range configs {
cfg.path = fmt.Sprintf(cfg.path, network)

err = v.ReadInConfig()
if err != nil {
return
}
v := viper.New()

for _, flag := range cfg.flagsToChange {
v.Set(flag, ip)
}
v.AddConfigPath(cfg.path)
v.SetConfigName(cfg.name)
v.SetConfigType(cfg.fileType)

err = v.WriteConfig()
if err != nil {
return
err = v.ReadInConfig()
if err != nil {
return
}

cfgIp := ip
if cfg.wrap != nil {
cfgIp = cfg.wrap(cfgIp)
}

for _, flag := range cfg.flagsToChange {
v.Set(flag, cfgIp)
}

err = v.WriteConfig()
if err != nil {
return
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions commands/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func updateValues(ctx *cli.Context, config networkConfig) (err error) {
// genesisJson = config.configPath + "/" + genesisJsonPath
gethTomlPath = config.configPath + "/" + configs.GethTomlPath
erigonTomlPath = config.configPath + "/" + configs.ErigonTomlPath
nethermindCfgPath = config.configPath + "/" + configs.NethermindCfgPath
nethermindJsonPath = config.configPath + "/" + configs.NethermindJsonPath
besuTomlPath = config.configPath + "/" + configs.BesuTomlPath
prysmYamlPath = config.configPath + "/" + configs.PrysmYamlPath
lighthouseTomlPath = config.configPath + "/" + configs.LighthouseTomlPath
Expand Down Expand Up @@ -130,7 +130,7 @@ func updateValues(ctx *cli.Context, config networkConfig) (err error) {
flags.ValidatorKeysFlag: config.keysPath,
flags.GethConfigFileFlag: gethTomlPath,
flags.ErigonConfigFileFlag: erigonTomlPath,
flags.NethermindConfigFileFlag: nethermindCfgPath,
flags.NethermindConfigFileFlag: nethermindJsonPath,
flags.BesuConfigFileFlag: besuTomlPath,
flags.PrysmConfigFileFlag: prysmYamlPath,
flags.LighthouseConfigFileFlag: lighthouseTomlPath,
Expand Down
4 changes: 2 additions & 2 deletions dependencies/configs/nethermind.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ var NethermindConfigDependencies = map[string]ClientConfigDependency{
nethermindMainnetConfigName: &clientConfig{
url: "https://raw.githubusercontent.com/lukso-network/network-configs/main/mainnet/nethermind/nethermind.cfg",
name: nethermindMainnetConfigName,
filePath: MainnetConfig + "/" + NethermindCfgPath,
filePath: MainnetConfig + "/" + NethermindJsonPath,
},
nethermindTestnetConfigName: &clientConfig{
url: "https://raw.githubusercontent.com/lukso-network/network-configs/main/testnet/nethermind/nethermind.cfg",
name: nethermindTestnetConfigName,
filePath: TestnetConfig + "/" + NethermindCfgPath,
filePath: TestnetConfig + "/" + NethermindJsonPath,
},
}
2 changes: 1 addition & 1 deletion dependencies/configs/shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ const (
DepositContractBlockPath = "shared/deposit_contract_block.txt"
GethTomlPath = "geth/geth.toml"
ErigonTomlPath = "erigon/erigon.toml"
NethermindCfgPath = "nethermind/nethermind.cfg"
NethermindJsonPath = "nethermind/nethermind.json"
BesuTomlPath = "besu/besu.toml"
PrysmYamlPath = "prysm/prysm.yaml"
ValidatorYamlPath = "prysm/validator.yaml"
Expand Down
4 changes: 2 additions & 2 deletions flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,8 @@ var (
NethermindStartFlags = []cli.Flag{
&cli.StringFlag{
Name: NethermindConfigFileFlag,
Usage: "Path to nethermind.cfg config file",
Value: configs.MainnetConfig + "/" + configs.NethermindCfgPath,
Usage: "Path to nethermind.json config file",
Value: configs.MainnetConfig + "/" + configs.NethermindJsonPath,
},
&cli.StringFlag{
Name: NethermindDatadirFlag,
Expand Down

0 comments on commit 4260ab7

Please sign in to comment.