@@ -11,7 +11,6 @@ import (
11
11
"encoding/json"
12
12
"errors"
13
13
"fmt"
14
- "maps"
15
14
"net/netip"
16
15
"os"
17
16
"os/exec"
65
64
// TODO(marun) Remove when subnet-evm configures the genesis with this key.
66
65
HardhatKey * secp256k1.PrivateKey
67
66
68
- errInsufficientNodes = errors .New ("at least one node is required" )
67
+ errInsufficientNodes = errors .New ("at least one node is required" )
68
+ errMissingRuntimeConfig = errors .New ("DefaultRuntimeConfig must not be empty" )
69
69
)
70
70
71
71
func init () {
@@ -253,6 +253,11 @@ func (n *Network) EnsureDefaultConfig(log logging.Logger) error {
253
253
}
254
254
}
255
255
256
+ emptyRuntime := NodeRuntimeConfig {}
257
+ if n .DefaultRuntimeConfig == emptyRuntime {
258
+ return errMissingRuntimeConfig
259
+ }
260
+
256
261
return nil
257
262
}
258
263
@@ -471,10 +476,6 @@ func (n *Network) StartNode(ctx context.Context, node *Node) error {
471
476
return err
472
477
}
473
478
474
- if err := n .writeNodeFlags (node ); err != nil {
475
- return fmt .Errorf ("writing node flags: %w" , err )
476
- }
477
-
478
479
if err := node .Start (ctx ); err != nil {
479
480
// Attempt to stop an unhealthy node to provide some assurance to the caller
480
481
// that an error condition will not result in a lingering process.
@@ -762,10 +763,11 @@ func (n *Network) GetNodeURIs() []NodeURI {
762
763
return GetNodeURIs (n .Nodes )
763
764
}
764
765
765
- // Retrieves bootstrap IPs and IDs for all nodes except the skipped one (this supports
766
- // collecting the bootstrap details for restarting a node).
766
+ // Retrieves bootstrap IPs and IDs for all non-ephemeral nodes except the skipped one
767
+ // (this supports collecting the bootstrap details for restarting a node).
768
+ //
767
769
// For consumption outside of avalanchego. Needs to be kept exported.
768
- func (n * Network ) GetBootstrapIPsAndIDs (skippedNode * Node ) ([]string , []string , error ) {
770
+ func (n * Network ) GetBootstrapIPsAndIDs (skippedNode * Node ) ([]string , []string ) {
769
771
bootstrapIPs := []string {}
770
772
bootstrapIDs := []string {}
771
773
for _ , node := range n .Nodes {
@@ -786,7 +788,7 @@ func (n *Network) GetBootstrapIPsAndIDs(skippedNode *Node) ([]string, []string,
786
788
bootstrapIDs = append (bootstrapIDs , node .NodeID .String ())
787
789
}
788
790
789
- return bootstrapIPs , bootstrapIDs , nil
791
+ return bootstrapIPs , bootstrapIDs
790
792
}
791
793
792
794
// GetNetworkID returns the effective ID of the network. If the network
@@ -879,77 +881,6 @@ func (n *Network) GetChainConfigContent() (string, error) {
879
881
return base64 .StdEncoding .EncodeToString (marshaledConfigs ), nil
880
882
}
881
883
882
- // writeNodeFlags determines the set of flags that should be used to
883
- // start the given node and writes them to a file in the node path.
884
- func (n * Network ) writeNodeFlags (node * Node ) error {
885
- flags := maps .Clone (node .Flags )
886
-
887
- // Convert the network id to a string to ensure consistency in JSON round-tripping.
888
- flags .SetDefault (config .NetworkNameKey , strconv .FormatUint (uint64 (n .GetNetworkID ()), 10 ))
889
-
890
- // Set the bootstrap configuration
891
- bootstrapIPs , bootstrapIDs , err := n .GetBootstrapIPsAndIDs (node )
892
- if err != nil {
893
- return fmt .Errorf ("failed to determine bootstrap configuration: %w" , err )
894
- }
895
- flags .SetDefault (config .BootstrapIDsKey , strings .Join (bootstrapIDs , "," ))
896
- flags .SetDefault (config .BootstrapIPsKey , strings .Join (bootstrapIPs , "," ))
897
-
898
- // TODO(marun) Maybe avoid computing content flags for each node start?
899
-
900
- if n .Genesis != nil {
901
- genesisFileContent , err := n .GetGenesisFileContent ()
902
- if err != nil {
903
- return fmt .Errorf ("failed to get genesis file content: %w" , err )
904
- }
905
- flags .SetDefault (config .GenesisFileContentKey , genesisFileContent )
906
-
907
- isSingleNodeNetwork := (len (n .Nodes ) == 1 && len (n .Genesis .InitialStakers ) == 1 )
908
- if isSingleNodeNetwork {
909
- n .log .Info ("defaulting to sybil protection disabled to enable a single-node network to start" )
910
- flags .SetDefault (config .SybilProtectionEnabledKey , "false" )
911
- }
912
- }
913
-
914
- subnetConfigContent , err := n .GetSubnetConfigContent ()
915
- if err != nil {
916
- return fmt .Errorf ("failed to get subnet config content: %w" , err )
917
- }
918
- if len (subnetConfigContent ) > 0 {
919
- flags .SetDefault (config .SubnetConfigContentKey , subnetConfigContent )
920
- }
921
-
922
- chainConfigContent , err := n .GetChainConfigContent ()
923
- if err != nil {
924
- return fmt .Errorf ("failed to get chain config content: %w" , err )
925
- }
926
- if len (chainConfigContent ) > 0 {
927
- flags .SetDefault (config .ChainConfigContentKey , chainConfigContent )
928
- }
929
-
930
- // Only configure the plugin dir with a non-empty value to ensure the use of
931
- // the default value (`[datadir]/plugins`) when no plugin dir is configured.
932
- processConfig := node .getRuntimeConfig ().Process
933
- if processConfig != nil {
934
- if len (processConfig .PluginDir ) > 0 {
935
- // Ensure the plugin directory exists or the node will fail to start
936
- if err := os .MkdirAll (processConfig .PluginDir , perms .ReadWriteExecute ); err != nil {
937
- return fmt .Errorf ("failed to create plugin dir: %w" , err )
938
- }
939
- flags .SetDefault (config .PluginDirKey , processConfig .PluginDir )
940
- }
941
-
942
- flags .SetDefault (config .DataDirKey , node .DataDir )
943
- }
944
-
945
- // Set the network and tmpnet defaults last to ensure they can be overridden
946
- flags .SetDefaults (n .DefaultFlags )
947
- flags .SetDefaults (DefaultTmpnetFlags ())
948
-
949
- // Write the flags to disk
950
- return node .writeFlags (flags )
951
- }
952
-
953
884
// Waits until the provided nodes are healthy.
954
885
func waitForHealthy (ctx context.Context , log logging.Logger , nodes []* Node ) error {
955
886
ticker := time .NewTicker (networkHealthCheckInterval )
0 commit comments