Skip to content

Commit

Permalink
fix some logic
Browse files Browse the repository at this point in the history
  • Loading branch information
felipemadero committed Nov 11, 2022
1 parent eca37c4 commit fe60657
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 32 deletions.
2 changes: 1 addition & 1 deletion local/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ func (ln *localNetwork) restartNodesWithWhitelistedSubnets(
delete(nodeConfig.Flags, config.WhitelistedSubnetsKey)

ln.log.Info("removing and adding back the node for whitelisted subnets", zap.String("node-name", nodeName))
if err := ln.restartNode(ctx, nodeName, "", "", nil, nil); err != nil {
if err := ln.restartNode(ctx, nodeName, "", "", nil, nil, nil); err != nil {
return err
}

Expand Down
57 changes: 28 additions & 29 deletions local/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,38 +55,37 @@ func writeFiles(genesis []byte, nodeRootDir string, nodeConfig *node.Config) ([]
return nil, fmt.Errorf("couldn't write file at %q: %w", f.path, err)
}
}
if nodeConfig.ChainConfigFiles != nil || nodeConfig.UpgradeConfigFiles != nil {
// only one flag and multiple files
chainConfigDir := filepath.Join(nodeRootDir, chainConfigSubDir)
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)
}
// chain configs dir
chainConfigDir := filepath.Join(nodeRootDir, chainConfigSubDir)
if err := os.MkdirAll(chainConfigDir, 0o750); err != nil {
return nil, err
}
flags = append(flags, fmt.Sprintf("--%s=%s", config.ChainConfigDirKey, chainConfigDir))
// subnet configs dir
subnetConfigDir := filepath.Join(nodeRootDir, subnetConfigSubDir)
if err := os.MkdirAll(subnetConfigDir, 0o750); err != nil {
return nil, err
}
flags = append(flags, fmt.Sprintf("--%s=%s", config.SubnetConfigDirKey, subnetConfigDir))
// chain configs
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)
}
}
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)
}
// network upgrades
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)
}
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)
}
}
// subnet configs
for subnetID, subnetConfigFile := range nodeConfig.SubnetConfigFiles {
subnetConfigPath := filepath.Join(subnetConfigDir, subnetID+".json")
if err := createFileAndWrite(subnetConfigPath, []byte(subnetConfigFile)); err != nil {
return nil, fmt.Errorf("couldn't write file at %q: %w", subnetConfigPath, err)
}
}
return flags, nil
Expand Down
2 changes: 2 additions & 0 deletions network/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ type Config struct {
ChainConfigFiles map[string]string `json:"chainConfigFiles"`
// Upgrade config files to use per default, if not specified in node config
UpgradeConfigFiles map[string]string `json:"upgradeConfigFiles"`
// Subnet config files to use per default, if not specified in node config
SubnetConfigFiles map[string]string `json:"subnetConfigFiles"`
}

// Validate returns an error if this config is invalid
Expand Down
5 changes: 3 additions & 2 deletions network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ type Network interface {
// Get name of available snapshots
GetSnapshotNames() ([]string, error)
// Restart a given node using the same config, optionally changing binary path,
// whitelisted subnets, a map of chain configs, and a map of upgrade configs
RestartNode(context.Context, string, string, string, map[string]string, map[string]string) error
// whitelisted subnets, a map of chain configs, a map of upgrade configs, and
// a map of subnet configs
RestartNode(context.Context, string, string, string, map[string]string, map[string]string, map[string]string) error
// Create the specified blockchains
CreateBlockchains(context.Context, []BlockchainSpec) error
// Create the given numbers of subnets
Expand Down
1 change: 1 addition & 0 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,7 @@ func (s *server) RestartNode(ctx context.Context, req *rpcpb.RestartNodeRequest)
req.GetWhitelistedSubnets(),
req.GetChainConfigs(),
req.GetUpgradeConfigs(),
req.GetSubnetConfigs(),
); err != nil {
return nil, err
}
Expand Down

0 comments on commit fe60657

Please sign in to comment.