Skip to content

Commit

Permalink
further cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
arturrez committed Sep 30, 2024
1 parent 67c1128 commit 22b9fbf
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 39 deletions.
12 changes: 6 additions & 6 deletions cmd/control/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,19 +283,19 @@ func newStartCommand() *cobra.Command {
&genesisPath,
"genesis-path",
"",
"[optional] custom network genesis path",
"[optional] genesis path",
)
cmd.PersistentFlags().StringSliceVar(
&bootstrapNodeIDs,
"bootstrap-node-ids",
[]string{},
"[optional] custom network bootstrap node ids (comma-separated)",
"[optional] bootstrap node ids (comma-separated)",
)
cmd.PersistentFlags().StringSliceVar(
&bootstrapNodeIPPortPairs,
"bootstrap-node-ip-ports",
[]string{},
"[optional] custom network bootstrap node ip:ports (comma-separated)",
"[optional] bootstrap node ip:ports (comma-separated)",
)
cmd.PersistentFlags().StringVar(
&walletPrivateKey,
Expand Down Expand Up @@ -326,14 +326,14 @@ func setNetworkOptions(opts *[]client.OpOption) error {
if genesisPath != "" {
// make sure provided genesis path exists
if _, err := os.Stat(genesisPath); err != nil {
return fmt.Errorf("custom network genesis path doesn't exist: %w", err)
return fmt.Errorf("genesis path doesn't exist: %w", err)
}
ux.Print(log, logging.Yellow.Wrap("custom network genesis path provided: %s"), genesisPath)
ux.Print(log, logging.Yellow.Wrap("genesis path provided: %s"), genesisPath)
*opts = append(*opts, client.WithGenesisPath(genesisPath))

genesisBytes, err := os.ReadFile(genesisPath)
if err != nil {
return fmt.Errorf("failed to read custom network genesis: %w", err)
return fmt.Errorf("failed to read genesis: %w", err)
}
networkID, err = utils.NetworkIDFromGenesis(genesisBytes)
if err != nil {
Expand Down
10 changes: 6 additions & 4 deletions local/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ func NewNetwork(
redirectStdout,
redirectStderr,
walletPrivateKey,
utils.BeaconMapToSet(networkConfig.BeaconConfig),
networkConfig.BeaconConfig,
)
if err != nil {
return net, err
Expand Down Expand Up @@ -258,7 +258,6 @@ func newNetwork(
subnetID2ElasticSubnetID: map[ids.ID]ids.ID{},
blockchainAliases: map[string][]string{},
walletPrivateKey: walletPrivateKey,
genesisPath: genesisPath,
}
return net, nil
}
Expand Down Expand Up @@ -299,7 +298,6 @@ func NewDefaultNetwork(
redirectStdout,
redirectStderr,
"",
"",
)
}

Expand Down Expand Up @@ -395,6 +393,10 @@ func NewDefaultConfigNNodes(
if int(numNodes) == 1 && !utils.IsPublicNetwork(networkID) && len(beaconConfig) == 0 {
flags[config.SybilProtectionEnabledKey] = false
}
beaconSet, err := utils.BeaconMapToSet(beaconConfig)
if err != nil {
return network.Config{}, err
}
cfg := network.Config{
NetworkID: networkID,
Flags: flags,
Expand All @@ -403,7 +405,7 @@ func NewDefaultConfigNNodes(
ChainConfigFiles: map[string]string{},
UpgradeConfigFiles: map[string]string{},
SubnetConfigFiles: map[string]string{},
BeaconConfig: beaconConfig,
BeaconConfig: beaconSet,
}
if len(upgradePath) != 0 {
upgrade, err := os.ReadFile(upgradePath)
Expand Down
17 changes: 0 additions & 17 deletions local/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ func TestNewNetworkEmpty(t *testing.T) {
false,
false,
"",
"",
beacon.NewSet(),
)
require.NoError(err)
Expand Down Expand Up @@ -224,7 +223,6 @@ func TestNewNetworkOneNode(t *testing.T) {
false,
false,
"",
"",
beacon.NewSet(),
)
require.NoError(err)
Expand Down Expand Up @@ -258,7 +256,6 @@ func TestNewNetworkFailToStartNode(t *testing.T) {
false,
false,
"",
"",
beacon.NewSet(),
)
require.NoError(err)
Expand Down Expand Up @@ -507,7 +504,6 @@ func TestWrongNetworkConfigs(t *testing.T) {
false,
false,
"",
"",
beacon.NewSet(),
)
require.NoError(err)
Expand All @@ -534,7 +530,6 @@ func TestUnhealthyNetwork(t *testing.T) {
false,
false,
"",
"",
beacon.NewSet(),
)
require.NoError(err)
Expand Down Expand Up @@ -562,7 +557,6 @@ func TestGeneratedNodesNames(t *testing.T) {
false,
false,
"",
"",
beacon.NewSet(),
)
require.NoError(err)
Expand Down Expand Up @@ -596,7 +590,6 @@ func TestGenerateDefaultNetwork(t *testing.T) {
false,
false,
"",
"",
beacon.NewSet(),
)
require.NoError(err)
Expand Down Expand Up @@ -659,7 +652,6 @@ func TestNetworkFromConfig(t *testing.T) {
false,
false,
"",
"",
beacon.NewSet(),
)
require.NoError(err)
Expand Down Expand Up @@ -696,7 +688,6 @@ func TestNetworkNodeOps(t *testing.T) {
false,
false,
"",
"",
beacon.NewSet(),
)
require.NoError(err)
Expand Down Expand Up @@ -747,7 +738,6 @@ func TestNodeNotFound(t *testing.T) {
false,
false,
"",
"",
beacon.NewSet(),
)
require.NoError(err)
Expand Down Expand Up @@ -793,7 +783,6 @@ func TestStoppedNetwork(t *testing.T) {
false,
false,
"",
"",
beacon.NewSet(),
)
require.NoError(err)
Expand Down Expand Up @@ -839,7 +828,6 @@ func TestGetAllNodes(t *testing.T) {
false,
false,
"",
"",
beacon.NewSet(),
)
require.NoError(err)
Expand Down Expand Up @@ -897,7 +885,6 @@ func TestFlags(t *testing.T) {
false,
false,
"",
"",
beacon.NewSet(),
)
require.NoError(err)
Expand Down Expand Up @@ -932,7 +919,6 @@ func TestFlags(t *testing.T) {
false,
false,
"",
"",
beacon.NewSet(),
)
require.NoError(err)
Expand Down Expand Up @@ -966,7 +952,6 @@ func TestFlags(t *testing.T) {
false,
false,
"",
"",
beacon.NewSet(),
)
require.NoError(err)
Expand Down Expand Up @@ -1419,7 +1404,6 @@ func TestRemoveBeacon(t *testing.T) {
false,
false,
"",
"",
beacon.NewSet(),
)
require.NoError(err)
Expand Down Expand Up @@ -1483,7 +1467,6 @@ func TestHealthyDuringNetworkStop(t *testing.T) {
false,
false,
"",
"",
beacon.NewSet(),
)
require.NoError(err)
Expand Down
7 changes: 5 additions & 2 deletions local/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ func NewNetworkFromSnapshot(
}
rootDir = getSnapshotDir(snapshotsDir, snapshotName)
}
beaconSet, err := utils.BeaconMapToSet(beaconConfig)
if err != nil {
return nil, err
}
net, err := newNetwork(
log,
api.NewAPIClient,
Expand All @@ -101,8 +105,7 @@ func NewNetworkFromSnapshot(
redirectStdout,
redirectStderr,
walletPrivateKey,
genesisPath,
utils.BeaconMapToSet(beaconConfig),
beaconSet,
)
if err != nil {
return net, err
Expand Down
6 changes: 3 additions & 3 deletions rpcpb/rpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions rpcpb/rpc.proto
Original file line number Diff line number Diff line change
Expand Up @@ -368,10 +368,10 @@ message StartRequest {
// wallet private key
string wallet_private_key = 16;

// custom network genesis path
// genesis path
string genesis_path = 17;

// custom network bootstrap data
// bootstrap data
repeated string bootstrap_node_ids = 18;
repeated string bootstrap_ip_port_pairs = 19;

Expand Down Expand Up @@ -692,7 +692,7 @@ message LoadSnapshotRequest {
optional string log_root_dir = 11;
// wallet private key
string wallet_private_key = 12;
// custom network bootstrap data
// bootstrap data
repeated string bootstrap_node_ids = 13;
repeated string bootstrap_ip_port_pairs = 14;

Expand Down
1 change: 1 addition & 0 deletions server/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,7 @@ func (lc *localNetwork) LoadSnapshot(snapshotName string, inPlace bool) error {
lc.options.redirectNodesOutput,
inPlace,
lc.options.walletPrivateKey,
lc.options.beaconConfig,
)
if err != nil {
return err
Expand Down
8 changes: 4 additions & 4 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,10 +332,10 @@ func (s *server) Start(_ context.Context, req *rpcpb.StartRequest) (*rpcpb.Start
RootDataDir: rootDataDir,
}
beaconConfig := map[ids.NodeID]netip.AddrPort{}
for index, id := range req.CustomNetworkBootstrapNodeIds {
addrPort, err := netip.ParseAddrPort(req.CustomNetworkBootstrapIpPortPairs[index])
for index, id := range req.BootstrapNodeIds {
addrPort, err := netip.ParseAddrPort(req.BootstrapIpPortPairs[index])
if err != nil {
return nil, fmt.Errorf("failed to parse IP:port pair %s: %w", req.CustomNetworkBootstrapIpPortPairs[index], err)
return nil, fmt.Errorf("failed to parse IP:port pair %s: %w", req.BootstrapIpPortPairs[index], err)
}
nodeID, err := ids.NodeIDFromString(id)
if err != nil {
Expand All @@ -362,7 +362,7 @@ func (s *server) Start(_ context.Context, req *rpcpb.StartRequest) (*rpcpb.Start
reassignPortsIfUsed: req.GetReassignPortsIfUsed(),
dynamicPorts: req.GetDynamicPorts(),
snapshotsDir: s.cfg.SnapshotsDir,
genesisPath: req.CustomNetworkGenesisPath,
genesisPath: req.GenesisPath,
beaconConfig: beaconConfig,
upgradePath: req.UpgradePath,
})
Expand Down

0 comments on commit 22b9fbf

Please sign in to comment.