Skip to content

Commit

Permalink
start adding subnet configs fields
Browse files Browse the repository at this point in the history
  • Loading branch information
felipemadero committed Nov 11, 2022
1 parent 35d6940 commit eca37c4
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
17 changes: 17 additions & 0 deletions local/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,23 @@ func writeFiles(genesis []byte, nodeRootDir string, nodeConfig *node.Config) ([]
}
}
}
if nodeConfig.SubnetConfigFiles != nil {
subnetConfigDir := filepath.Join(nodeRootDir, subnetConfigSubDir)
flags = append(flags, fmt.Sprintf("--%s=%s", config.ChainConfigDirKey, chainConfigDir))

for chainAlias, chainConfigFile := range nodeConfig.ChainConfigFiles {
chainConfigPath := filepath.Join(chainConfigDir, chainAlias, configFileName)
if err := createFileAndWrite(chainConfigPath, []byte(chainConfigFile)); err != nil {
return nil, fmt.Errorf("couldn't write file at %q: %w", chainConfigPath, err)
}
}
for chainAlias, chainUpgradeFile := range nodeConfig.UpgradeConfigFiles {
chainUpgradePath := filepath.Join(chainConfigDir, chainAlias, upgradeConfigFileName)
if err := createFileAndWrite(chainUpgradePath, []byte(chainUpgradeFile)); err != nil {
return nil, fmt.Errorf("couldn't write file at %q: %w", chainUpgradePath, err)
}
}
}
return flags, nil
}

Expand Down
20 changes: 18 additions & 2 deletions local/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ var (
config.BootstrapIPsKey: {},
config.BootstrapIDsKey: {},
}
chainConfigSubDir = "chainConfigs"
chainConfigSubDir = "chainConfigs"
subnetConfigSubDir = "subnetConfigs"

snapshotsRelPath = filepath.Join(".avalanche-network-runner", "snapshots")

Expand Down Expand Up @@ -100,6 +101,8 @@ type localNetwork struct {
chainConfigFiles map[string]string
// upgrade config files to use per default
upgradeConfigFiles map[string]string
// subnet config files to use per default
subnetConfigFiles map[string]string
// if true, for ports given in conf that are already taken, assign new random ones
reassignPortsIfUsed bool
}
Expand Down Expand Up @@ -415,6 +418,7 @@ func (ln *localNetwork) loadConfig(ctx context.Context, networkConfig network.Co
ln.binaryPath = networkConfig.BinaryPath
ln.chainConfigFiles = networkConfig.ChainConfigFiles
ln.upgradeConfigFiles = networkConfig.UpgradeConfigFiles
ln.subnetConfigFiles = networkConfig.SubnetConfigFiles

// Sort node configs so beacons start first
var nodeConfigs []node.Config
Expand Down Expand Up @@ -482,6 +486,12 @@ func (ln *localNetwork) addNode(nodeConfig node.Config) (node.Node, error) {
nodeConfig.UpgradeConfigFiles[k] = v
}
}
for k, v := range ln.subnetConfigFiles {
_, ok := nodeConfig.SubnetConfigFiles[k]
if !ok {
nodeConfig.SubnetConfigFiles[k] = v
}
}
addNetworkFlags(ln.log, ln.flags, nodeConfig.Flags)

// it shouldn't happen that just one is empty, most probably both,
Expand Down Expand Up @@ -758,11 +768,12 @@ func (ln *localNetwork) RestartNode(
whitelistedSubnets string,
chainConfigs map[string]string,
upgradeConfigs map[string]string,
subnetConfigs map[string]string,
) error {
ln.lock.Lock()
defer ln.lock.Unlock()

return ln.restartNode(ctx, nodeName, binaryPath, whitelistedSubnets, chainConfigs, upgradeConfigs)
return ln.restartNode(ctx, nodeName, binaryPath, whitelistedSubnets, chainConfigs, upgradeConfigs, subnetConfigs)
}

func (ln *localNetwork) restartNode(
Expand All @@ -772,6 +783,7 @@ func (ln *localNetwork) restartNode(
whitelistedSubnets string,
chainConfigs map[string]string,
upgradeConfigs map[string]string,
subnetConfigs map[string]string,
) error {
node, ok := ln.nodes[nodeName]
if !ok {
Expand Down Expand Up @@ -801,6 +813,10 @@ func (ln *localNetwork) restartNode(
for k, v := range upgradeConfigs {
nodeConfig.UpgradeConfigFiles[k] = v
}
// apply subnet configs
for k, v := range subnetConfigs {
nodeConfig.SubnetConfigFiles[k] = v
}

if err := ln.removeNode(ctx, nodeName); err != nil {
return err
Expand Down
2 changes: 2 additions & 0 deletions network/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ type Config struct {
ChainConfigFiles map[string]string `json:"chainConfigFiles"`
// May be nil.
UpgradeConfigFiles map[string]string `json:"upgradeConfigFiles"`
// May be nil.
SubnetConfigFiles map[string]string `json:"subnetConfigFiles"`
// Flags can hold additional flags for the node.
// It can be empty.
// The precedence of flags handling is:
Expand Down

0 comments on commit eca37c4

Please sign in to comment.