@@ -240,13 +240,6 @@ func (n *Network) EnsureDefaultConfig(log logging.Logger) error {
240240 n .PrimaryChainConfigs [alias ].SetDefaults (chainConfig )
241241 }
242242
243- // Ensure nodes are configured
244- for i := range n .Nodes {
245- if err := n .EnsureNodeConfig (n .Nodes [i ]); err != nil {
246- return err
247- }
248- }
249-
250243 return nil
251244}
252245
@@ -504,23 +497,22 @@ func (n *Network) RestartNode(ctx context.Context, log logging.Logger, node *Nod
504497
505498// Stops all nodes in the network.
506499func (n * Network ) Stop (ctx context.Context ) error {
507- // Target all nodes, including the ephemeral ones
508- nodes , err := ReadNodes (n , true /* includeEphemeral */ )
509- if err != nil {
500+ // Ensure the node state is up-to-date
501+ if err := n .readNodes (); err != nil {
510502 return err
511503 }
512504
513505 var errs []error
514506
515507 // Initiate stop on all nodes
516- for _ , node := range nodes {
508+ for _ , node := range n . Nodes {
517509 if err := node .InitiateStop (ctx ); err != nil {
518510 errs = append (errs , fmt .Errorf ("failed to stop node %s: %w" , node .NodeID , err ))
519511 }
520512 }
521513
522514 // Wait for stop to complete on all nodes
523- for _ , node := range nodes {
515+ for _ , node := range n . Nodes {
524516 if err := node .WaitForStopped (ctx ); err != nil {
525517 errs = append (errs , fmt .Errorf ("failed to wait for node %s to stop: %w" , node .NodeID , err ))
526518 }
@@ -554,14 +546,9 @@ func (n *Network) EnsureNodeConfig(node *Node) error {
554546 return err
555547 }
556548
557- if len (n .Dir ) > 0 {
558- // Ensure the node's data dir is configured
559- dataDir := node .GetDataDir ()
560- if len (dataDir ) == 0 {
561- // NodeID will have been set by EnsureKeys
562- dataDir = filepath .Join (n .Dir , node .NodeID .String ())
563- node .Flags [config .DataDirKey ] = dataDir
564- }
549+ // Ensure a data directory if not already set
550+ if len (node .DataDir ) == 0 {
551+ node .DataDir = filepath .Join (n .Dir , node .NodeID .String ())
565552 }
566553
567554 return nil
@@ -768,16 +755,13 @@ func (n *Network) GetNodeURIs() []NodeURI {
768755// collecting the bootstrap details for restarting a node).
769756// For consumption outside of avalanchego. Needs to be kept exported.
770757func (n * Network ) GetBootstrapIPsAndIDs (skippedNode * Node ) ([]string , []string , error ) {
771- // Collect staking addresses of non-ephemeral nodes for use in bootstrapping a node
772- nodes , err := ReadNodes (n , false /* includeEphemeral */ )
773- if err != nil {
774- return nil , nil , fmt .Errorf ("failed to read network's nodes: %w" , err )
775- }
776- var (
777- bootstrapIPs = make ([]string , 0 , len (nodes ))
778- bootstrapIDs = make ([]string , 0 , len (nodes ))
779- )
780- for _ , node := range nodes {
758+ bootstrapIPs := []string {}
759+ bootstrapIDs := []string {}
760+ for _ , node := range n .Nodes {
761+ if node .IsEphemeral {
762+ // Ephemeral nodes are not guaranteed to stay running
763+ continue
764+ }
781765 if skippedNode != nil && node .NodeID == skippedNode .NodeID {
782766 continue
783767 }
@@ -940,12 +924,16 @@ func (n *Network) writeNodeFlags(log logging.Logger, node *Node) error {
940924 // Only configure the plugin dir with a non-empty value to ensure the use of
941925 // the default value (`[datadir]/plugins`) when no plugin dir is configured.
942926 processConfig := node .getRuntimeConfig ().Process
943- if processConfig != nil && len (processConfig .PluginDir ) > 0 {
944- // Ensure the plugin directory exists or the node will fail to start
945- if err := os .MkdirAll (processConfig .PluginDir , perms .ReadWriteExecute ); err != nil {
946- return fmt .Errorf ("failed to create plugin dir: %w" , err )
927+ if processConfig != nil {
928+ if len (processConfig .PluginDir ) > 0 {
929+ // Ensure the plugin directory exists or the node will fail to start
930+ if err := os .MkdirAll (processConfig .PluginDir , perms .ReadWriteExecute ); err != nil {
931+ return fmt .Errorf ("failed to create plugin dir: %w" , err )
932+ }
933+ flags .SetDefault (config .PluginDirKey , processConfig .PluginDir )
947934 }
948- flags .SetDefault (config .PluginDirKey , processConfig .PluginDir )
935+
936+ flags .SetDefault (config .DataDirKey , node .DataDir )
949937 }
950938
951939 // Set the network and tmpnet defaults last to ensure they can be overridden
0 commit comments