From 22b9fbf59e5cb47b14e20e31884296fd4f9c8415 Mon Sep 17 00:00:00 2001 From: Artur Reznikov Date: Mon, 30 Sep 2024 13:13:04 -0700 Subject: [PATCH] further cleanup --- cmd/control/control.go | 12 ++++++------ local/network.go | 10 ++++++---- local/network_test.go | 17 ----------------- local/snapshot.go | 7 +++++-- rpcpb/rpc.pb.go | 6 +++--- rpcpb/rpc.proto | 6 +++--- server/network.go | 1 + server/server.go | 8 ++++---- 8 files changed, 28 insertions(+), 39 deletions(-) diff --git a/cmd/control/control.go b/cmd/control/control.go index 1b90789c..a0c32a66 100644 --- a/cmd/control/control.go +++ b/cmd/control/control.go @@ -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, @@ -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 { diff --git a/local/network.go b/local/network.go index 5ddb16f5..3324b31e 100644 --- a/local/network.go +++ b/local/network.go @@ -192,7 +192,7 @@ func NewNetwork( redirectStdout, redirectStderr, walletPrivateKey, - utils.BeaconMapToSet(networkConfig.BeaconConfig), + networkConfig.BeaconConfig, ) if err != nil { return net, err @@ -258,7 +258,6 @@ func newNetwork( subnetID2ElasticSubnetID: map[ids.ID]ids.ID{}, blockchainAliases: map[string][]string{}, walletPrivateKey: walletPrivateKey, - genesisPath: genesisPath, } return net, nil } @@ -299,7 +298,6 @@ func NewDefaultNetwork( redirectStdout, redirectStderr, "", - "", ) } @@ -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, @@ -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) diff --git a/local/network_test.go b/local/network_test.go index 70da22e6..8bfcc36e 100644 --- a/local/network_test.go +++ b/local/network_test.go @@ -155,7 +155,6 @@ func TestNewNetworkEmpty(t *testing.T) { false, false, "", - "", beacon.NewSet(), ) require.NoError(err) @@ -224,7 +223,6 @@ func TestNewNetworkOneNode(t *testing.T) { false, false, "", - "", beacon.NewSet(), ) require.NoError(err) @@ -258,7 +256,6 @@ func TestNewNetworkFailToStartNode(t *testing.T) { false, false, "", - "", beacon.NewSet(), ) require.NoError(err) @@ -507,7 +504,6 @@ func TestWrongNetworkConfigs(t *testing.T) { false, false, "", - "", beacon.NewSet(), ) require.NoError(err) @@ -534,7 +530,6 @@ func TestUnhealthyNetwork(t *testing.T) { false, false, "", - "", beacon.NewSet(), ) require.NoError(err) @@ -562,7 +557,6 @@ func TestGeneratedNodesNames(t *testing.T) { false, false, "", - "", beacon.NewSet(), ) require.NoError(err) @@ -596,7 +590,6 @@ func TestGenerateDefaultNetwork(t *testing.T) { false, false, "", - "", beacon.NewSet(), ) require.NoError(err) @@ -659,7 +652,6 @@ func TestNetworkFromConfig(t *testing.T) { false, false, "", - "", beacon.NewSet(), ) require.NoError(err) @@ -696,7 +688,6 @@ func TestNetworkNodeOps(t *testing.T) { false, false, "", - "", beacon.NewSet(), ) require.NoError(err) @@ -747,7 +738,6 @@ func TestNodeNotFound(t *testing.T) { false, false, "", - "", beacon.NewSet(), ) require.NoError(err) @@ -793,7 +783,6 @@ func TestStoppedNetwork(t *testing.T) { false, false, "", - "", beacon.NewSet(), ) require.NoError(err) @@ -839,7 +828,6 @@ func TestGetAllNodes(t *testing.T) { false, false, "", - "", beacon.NewSet(), ) require.NoError(err) @@ -897,7 +885,6 @@ func TestFlags(t *testing.T) { false, false, "", - "", beacon.NewSet(), ) require.NoError(err) @@ -932,7 +919,6 @@ func TestFlags(t *testing.T) { false, false, "", - "", beacon.NewSet(), ) require.NoError(err) @@ -966,7 +952,6 @@ func TestFlags(t *testing.T) { false, false, "", - "", beacon.NewSet(), ) require.NoError(err) @@ -1419,7 +1404,6 @@ func TestRemoveBeacon(t *testing.T) { false, false, "", - "", beacon.NewSet(), ) require.NoError(err) @@ -1483,7 +1467,6 @@ func TestHealthyDuringNetworkStop(t *testing.T) { false, false, "", - "", beacon.NewSet(), ) require.NoError(err) diff --git a/local/snapshot.go b/local/snapshot.go index 64d80b78..c4c72765 100644 --- a/local/snapshot.go +++ b/local/snapshot.go @@ -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, @@ -101,8 +105,7 @@ func NewNetworkFromSnapshot( redirectStdout, redirectStderr, walletPrivateKey, - genesisPath, - utils.BeaconMapToSet(beaconConfig), + beaconSet, ) if err != nil { return net, err diff --git a/rpcpb/rpc.pb.go b/rpcpb/rpc.pb.go index d2c132e8..358d1c54 100644 --- a/rpcpb/rpc.pb.go +++ b/rpcpb/rpc.pb.go @@ -695,9 +695,9 @@ type StartRequest struct { LogRootDir *string `protobuf:"bytes,15,opt,name=log_root_dir,json=logRootDir,proto3,oneof" json:"log_root_dir,omitempty"` // wallet private key WalletPrivateKey string `protobuf:"bytes,16,opt,name=wallet_private_key,json=walletPrivateKey,proto3" json:"wallet_private_key,omitempty"` - // custom network genesis path + // genesis path GenesisPath string `protobuf:"bytes,17,opt,name=genesis_path,json=genesisPath,proto3" json:"genesis_path,omitempty"` - // custom network bootstrap data + // bootstrap data BootstrapNodeIds []string `protobuf:"bytes,18,rep,name=bootstrap_node_ids,json=bootstrapNodeIds,proto3" json:"bootstrap_node_ids,omitempty"` BootstrapIpPortPairs []string `protobuf:"bytes,19,rep,name=bootstrap_ip_port_pairs,json=bootstrapIpPortPairs,proto3" json:"bootstrap_ip_port_pairs,omitempty"` // upgrade path @@ -3690,7 +3690,7 @@ type LoadSnapshotRequest struct { LogRootDir *string `protobuf:"bytes,11,opt,name=log_root_dir,json=logRootDir,proto3,oneof" json:"log_root_dir,omitempty"` // wallet private key WalletPrivateKey string `protobuf:"bytes,12,opt,name=wallet_private_key,json=walletPrivateKey,proto3" json:"wallet_private_key,omitempty"` - // custom network bootstrap data + // bootstrap data BootstrapNodeIds []string `protobuf:"bytes,13,rep,name=bootstrap_node_ids,json=bootstrapNodeIds,proto3" json:"bootstrap_node_ids,omitempty"` BootstrapIpPortPairs []string `protobuf:"bytes,14,rep,name=bootstrap_ip_port_pairs,json=bootstrapIpPortPairs,proto3" json:"bootstrap_ip_port_pairs,omitempty"` } diff --git a/rpcpb/rpc.proto b/rpcpb/rpc.proto index bceab542..f6d0b383 100644 --- a/rpcpb/rpc.proto +++ b/rpcpb/rpc.proto @@ -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; @@ -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; diff --git a/server/network.go b/server/network.go index 95567e9e..52de8492 100644 --- a/server/network.go +++ b/server/network.go @@ -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 diff --git a/server/server.go b/server/server.go index b274f640..6d77bf51 100644 --- a/server/server.go +++ b/server/server.go @@ -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 { @@ -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, })