Skip to content

Commit

Permalink
all except blockchain
Browse files Browse the repository at this point in the history
  • Loading branch information
felipemadero committed Nov 11, 2022
1 parent fe60657 commit 2dfb55f
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 1 deletion.
3 changes: 3 additions & 0 deletions local/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,9 @@ func (ln *localNetwork) addNode(nodeConfig node.Config) (node.Node, error) {
if nodeConfig.UpgradeConfigFiles == nil {
nodeConfig.UpgradeConfigFiles = map[string]string{}
}
if nodeConfig.SubnetConfigFiles == nil {
nodeConfig.SubnetConfigFiles = map[string]string{}
}

// load node defaults
if nodeConfig.BinaryPath == "" {
Expand Down
20 changes: 19 additions & 1 deletion local/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func NewNetworkFromSnapshot(
buildDir string,
chainConfigs map[string]string,
upgradeConfigs map[string]string,
subnetConfigs map[string]string,
flags map[string]interface{},
reassignPortsIfUsed bool,
) (network.Network, error) {
Expand All @@ -48,7 +49,16 @@ func NewNetworkFromSnapshot(
if err != nil {
return net, err
}
err = net.loadSnapshot(context.Background(), snapshotName, binaryPath, buildDir, chainConfigs, upgradeConfigs, flags)
err = net.loadSnapshot(
context.Background(),
snapshotName,
binaryPath,
buildDir,
chainConfigs,
upgradeConfigs,
subnetConfigs,
flags,
)
return net, err
}

Expand Down Expand Up @@ -137,6 +147,7 @@ func (ln *localNetwork) SaveSnapshot(ctx context.Context, snapshotName string) (
BinaryPath: ln.binaryPath,
ChainConfigFiles: ln.chainConfigFiles,
UpgradeConfigFiles: ln.upgradeConfigFiles,
SubnetConfigFiles: ln.subnetConfigFiles,
}

for _, nodeConfig := range nodesConfig {
Expand All @@ -162,6 +173,7 @@ func (ln *localNetwork) loadSnapshot(
buildDir string,
chainConfigs map[string]string,
upgradeConfigs map[string]string,
subnetConfigs map[string]string,
flags map[string]interface{},
) error {
ln.lock.Lock()
Expand Down Expand Up @@ -221,12 +233,18 @@ func (ln *localNetwork) loadSnapshot(
if networkConfig.NodeConfigs[i].UpgradeConfigFiles == nil {
networkConfig.NodeConfigs[i].UpgradeConfigFiles = map[string]string{}
}
if networkConfig.NodeConfigs[i].SubnetConfigFiles == nil {
networkConfig.NodeConfigs[i].SubnetConfigFiles = map[string]string{}
}
for k, v := range chainConfigs {
networkConfig.NodeConfigs[i].ChainConfigFiles[k] = v
}
for k, v := range upgradeConfigs {
networkConfig.NodeConfigs[i].UpgradeConfigFiles[k] = v
}
for k, v := range subnetConfigs {
networkConfig.NodeConfigs[i].SubnetConfigFiles[k] = v
}
}
return ln.loadConfig(ctx, networkConfig)
}
Expand Down
1 change: 1 addition & 0 deletions network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type BlockchainSpec struct {
SubnetId *string
ChainConfig []byte
NetworkUpgrade []byte
SubnetConfig []byte
}

// Network is an abstraction of an Avalanche network
Expand Down
6 changes: 6 additions & 0 deletions server/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ type localNetworkOptions struct {
chainConfigs map[string]string
// upgrade configs to be added to the network, besides the ones in default config, or saved snapshot
upgradeConfigs map[string]string
// subnet configs to be added to the network, besides the ones in default config, or saved snapshot
subnetConfigs map[string]string

// to block racey restart while installing custom chains
restartMu *sync.RWMutex
Expand Down Expand Up @@ -154,6 +156,9 @@ func (lc *localNetwork) createConfig() error {
for k, v := range lc.options.upgradeConfigs {
cfg.NodeConfigs[i].UpgradeConfigFiles[k] = v
}
for k, v := range lc.options.subnetConfigs {
cfg.NodeConfigs[i].SubnetConfigFiles[k] = v
}

if cfg.NodeConfigs[i].Flags == nil {
cfg.NodeConfigs[i].Flags = map[string]interface{}{}
Expand Down Expand Up @@ -377,6 +382,7 @@ func (lc *localNetwork) loadSnapshot(
buildDir,
lc.options.chainConfigs,
lc.options.upgradeConfigs,
lc.options.subnetConfigs,
globalNodeConfig,
lc.options.reassignPortsIfUsed,
)
Expand Down
11 changes: 11 additions & 0 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ func (s *server) Start(ctx context.Context, req *rpcpb.StartRequest) (*rpcpb.Sta
customNodeConfigs: customNodeConfigs,
chainConfigs: req.ChainConfigs,
upgradeConfigs: req.UpgradeConfigs,
subnetConfigs: req.SubnetConfigs,
logLevel: s.cfg.LogLevel,
reassignPortsIfUsed: req.GetReassignPortsIfUsed(),
dynamicPorts: req.GetDynamicPorts(),
Expand Down Expand Up @@ -452,11 +453,19 @@ func getNetworkBlockchainSpec(
return network.BlockchainSpec{}, err
}
}
var subnetConfigBytes []byte
if spec.SubnetConfig != "" {
subnetConfigBytes, err = os.ReadFile(spec.SubnetConfig)
if err != nil {
return network.BlockchainSpec{}, err
}
}
return network.BlockchainSpec{
VmName: vmName,
Genesis: genesisBytes,
ChainConfig: chainConfigBytes,
NetworkUpgrade: networkUpgradeBytes,
SubnetConfig: subnetConfigBytes,
SubnetId: spec.SubnetId,
}, nil
}
Expand Down Expand Up @@ -749,6 +758,7 @@ func (s *server) AddNode(ctx context.Context, req *rpcpb.AddNodeRequest) (*rpcpb
RedirectStderr: s.cfg.RedirectNodesOutput,
ChainConfigFiles: req.ChainConfigs,
UpgradeConfigFiles: req.UpgradeConfigs,
SubnetConfigFiles: req.SubnetConfigs,
}

if _, err := s.network.nw.AddNode(nodeConfig); err != nil {
Expand Down Expand Up @@ -961,6 +971,7 @@ func (s *server) LoadSnapshot(ctx context.Context, req *rpcpb.LoadSnapshotReques
rootDataDir: rootDataDir,
chainConfigs: req.ChainConfigs,
upgradeConfigs: req.UpgradeConfigs,
subnetConfigs: req.SubnetConfigs,
globalNodeConfig: req.GetGlobalNodeConfig(),
logLevel: s.cfg.LogLevel,
reassignPortsIfUsed: req.GetReassignPortsIfUsed(),
Expand Down

0 comments on commit 2dfb55f

Please sign in to comment.