Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chain config per node #374

Merged
merged 16 commits into from
Dec 20, 2022
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 10 additions & 39 deletions local/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func (ln *localNetwork) installCustomChains(
if err != nil {
return nil, err
}
blockchainFilesCreated, err := ln.createBlockchainConfigFiles(chainSpecs, blockchainTxs, ln.log)
blockchainFilesCreated, err := ln.setBlockchainConfigFiles(chainSpecs, blockchainTxs, ln.log)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -741,7 +741,7 @@ func createBlockchainTxs(
return blockchainTxs, nil
}

func (ln *localNetwork) createBlockchainConfigFiles(
func (ln *localNetwork) setBlockchainConfigFiles(
chainSpecs []network.BlockchainSpec,
blockchainTxs []*txs.Tx,
log logging.Logger,
Expand All @@ -751,56 +751,27 @@ func (ln *localNetwork) createBlockchainConfigFiles(
log.Info(logging.Green.Wrap("creating config files for each custom chain"))
for i, chainSpec := range chainSpecs {
chainAlias := blockchainTxs[i].ID().String()

// create config, network upgrade and subnet config files
if chainSpec.ChainConfig != nil {
// update config info. set defaults and node specifics
if chainSpec.ChainConfig != nil || len(chainSpec.PerNodeChainConfig) != 0 {
created = true
ln.chainConfigFiles[chainAlias] = string(chainSpec.ChainConfig)
for nodeName := range ln.nodes {
nodeRootDir := getNodeDir(ln.rootDir, nodeName)
chainConfigDir := filepath.Join(nodeRootDir, chainConfigSubDir)
chainConfigPath := filepath.Join(chainConfigDir, chainAlias, configFileName)
if err := createFileAndWrite(chainConfigPath, chainSpec.ChainConfig); err != nil {
return false, fmt.Errorf("couldn't write chain config file at %q: %w", chainConfigPath, err)
if cfg, ok := chainSpec.PerNodeChainConfig[nodeName]; ok {
ln.nodes[nodeName].config.ChainConfigFiles[chainAlias] = string(cfg)
} else {
delete(ln.nodes[nodeName].config.ChainConfigFiles, chainAlias)
}
}
}
if chainSpec.NetworkUpgrade != nil {
created = true
for nodeName := range ln.nodes {
felipemadero marked this conversation as resolved.
Show resolved Hide resolved
nodeRootDir := getNodeDir(ln.rootDir, nodeName)
chainConfigDir := filepath.Join(nodeRootDir, chainConfigSubDir)
chainUpgradePath := filepath.Join(chainConfigDir, chainAlias, upgradeConfigFileName)
if err := createFileAndWrite(chainUpgradePath, chainSpec.NetworkUpgrade); err != nil {
return false, fmt.Errorf("couldn't write network upgrade file at %q: %w", chainUpgradePath, err)
}
}
}
if chainSpec.SubnetConfig != nil {
created = true
for nodeName := range ln.nodes {
nodeRootDir := getNodeDir(ln.rootDir, nodeName)
subnetConfigDir := filepath.Join(nodeRootDir, subnetConfigSubDir)
subnetConfigPath := filepath.Join(subnetConfigDir, *chainSpec.SubnetId+".json")
if err := createFileAndWrite(subnetConfigPath, chainSpec.SubnetConfig); err != nil {
return false, fmt.Errorf("couldn't write chain config file at %q: %w", subnetConfigPath, err)
}
}
}
// update config info for snapshopt/restart purposes
// put into defaults and reset node specifics
if chainSpec.ChainConfig != nil {
ln.chainConfigFiles[chainAlias] = string(chainSpec.ChainConfig)
for nodeName := range ln.nodes {
delete(ln.nodes[nodeName].config.ChainConfigFiles, chainAlias)
}
}
if chainSpec.NetworkUpgrade != nil {
ln.upgradeConfigFiles[chainAlias] = string(chainSpec.NetworkUpgrade)
for nodeName := range ln.nodes {
delete(ln.nodes[nodeName].config.UpgradeConfigFiles, chainAlias)
}
}
if chainSpec.SubnetConfig != nil {
created = true
ln.subnetConfigFiles[*chainSpec.SubnetId] = string(chainSpec.SubnetConfig)
for nodeName := range ln.nodes {
delete(ln.nodes[nodeName].config.SubnetConfigFiles, *chainSpec.SubnetId)
Expand Down
13 changes: 7 additions & 6 deletions network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ var (
)

type BlockchainSpec struct {
VmName string
Genesis []byte
SubnetId *string
ChainConfig []byte
NetworkUpgrade []byte
SubnetConfig []byte
VmName string
Genesis []byte
SubnetId *string
ChainConfig []byte
NetworkUpgrade []byte
SubnetConfig []byte
PerNodeChainConfig map[string][]byte
}

// Network is an abstraction of an Avalanche network
Expand Down
Loading