@@ -239,13 +239,6 @@ func (n *Network) EnsureDefaultConfig(log logging.Logger) error {
239
239
n .PrimaryChainConfigs [alias ].SetDefaults (chainConfig )
240
240
}
241
241
242
- // Ensure nodes are configured
243
- for i := range n .Nodes {
244
- if err := n .EnsureNodeConfig (n .Nodes [i ]); err != nil {
245
- return err
246
- }
247
- }
248
-
249
242
return nil
250
243
}
251
244
@@ -503,23 +496,22 @@ func (n *Network) RestartNode(ctx context.Context, log logging.Logger, node *Nod
503
496
504
497
// Stops all nodes in the network.
505
498
func (n * Network ) Stop (ctx context.Context ) error {
506
- // Target all nodes, including the ephemeral ones
507
- nodes , err := ReadNodes (n , true /* includeEphemeral */ )
508
- if err != nil {
499
+ // Ensure the node state is up-to-date
500
+ if err := n .readNodes (); err != nil {
509
501
return err
510
502
}
511
503
512
504
var errs []error
513
505
514
506
// Initiate stop on all nodes
515
- for _ , node := range nodes {
507
+ for _ , node := range n . Nodes {
516
508
if err := node .InitiateStop (ctx ); err != nil {
517
509
errs = append (errs , fmt .Errorf ("failed to stop node %s: %w" , node .NodeID , err ))
518
510
}
519
511
}
520
512
521
513
// Wait for stop to complete on all nodes
522
- for _ , node := range nodes {
514
+ for _ , node := range n . Nodes {
523
515
if err := node .WaitForStopped (ctx ); err != nil {
524
516
errs = append (errs , fmt .Errorf ("failed to wait for node %s to stop: %w" , node .NodeID , err ))
525
517
}
@@ -543,8 +535,7 @@ func (n *Network) Restart(ctx context.Context, log logging.Logger) error {
543
535
}
544
536
545
537
// Ensures the provided node has the configuration it needs to start. If the data dir is not
546
- // set, it will be defaulted to [nodeParentDir]/[node ID]. For a not-yet-created network,
547
- // no action will be taken.
538
+ // set, it will be defaulted to [nodeParentDir]/[node ID].
548
539
func (n * Network ) EnsureNodeConfig (node * Node ) error {
549
540
// Ensure the node has access to network configuration
550
541
node .network = n
@@ -553,14 +544,9 @@ func (n *Network) EnsureNodeConfig(node *Node) error {
553
544
return err
554
545
}
555
546
556
- if len (n .Dir ) > 0 {
557
- // Ensure the node's data dir is configured
558
- dataDir := node .GetDataDir ()
559
- if len (dataDir ) == 0 {
560
- // NodeID will have been set by EnsureKeys
561
- dataDir = filepath .Join (n .Dir , node .NodeID .String ())
562
- node .Flags [config .DataDirKey ] = dataDir
563
- }
547
+ // Ensure a data directory if not already set
548
+ if len (node .DataDir ) == 0 {
549
+ node .DataDir = filepath .Join (n .Dir , node .NodeID .String ())
564
550
}
565
551
566
552
return nil
@@ -767,16 +753,13 @@ func (n *Network) GetNodeURIs() []NodeURI {
767
753
// collecting the bootstrap details for restarting a node).
768
754
// For consumption outside of avalanchego. Needs to be kept exported.
769
755
func (n * Network ) GetBootstrapIPsAndIDs (skippedNode * Node ) ([]string , []string , error ) {
770
- // Collect staking addresses of non-ephemeral nodes for use in bootstrapping a node
771
- nodes , err := ReadNodes (n , false /* includeEphemeral */ )
772
- if err != nil {
773
- return nil , nil , fmt .Errorf ("failed to read network's nodes: %w" , err )
774
- }
775
- var (
776
- bootstrapIPs = make ([]string , 0 , len (nodes ))
777
- bootstrapIDs = make ([]string , 0 , len (nodes ))
778
- )
779
- for _ , node := range nodes {
756
+ bootstrapIPs := []string {}
757
+ bootstrapIDs := []string {}
758
+ for _ , node := range n .Nodes {
759
+ if node .IsEphemeral {
760
+ // Ephemeral nodes are not guaranteed to stay running
761
+ continue
762
+ }
780
763
if skippedNode != nil && node .NodeID == skippedNode .NodeID {
781
764
continue
782
765
}
@@ -934,12 +917,16 @@ func (n *Network) writeNodeFlags(log logging.Logger, node *Node) error {
934
917
// Only configure the plugin dir with a non-empty value to ensure the use of
935
918
// the default value (`[datadir]/plugins`) when no plugin dir is configured.
936
919
processConfig := node .getRuntimeConfig ().Process
937
- if processConfig != nil && len (processConfig .PluginDir ) > 0 {
938
- // Ensure the plugin directory exists or the node will fail to start
939
- if err := os .MkdirAll (processConfig .PluginDir , perms .ReadWriteExecute ); err != nil {
940
- return fmt .Errorf ("failed to create plugin dir: %w" , err )
920
+ if processConfig != nil {
921
+ if len (processConfig .PluginDir ) > 0 {
922
+ // Ensure the plugin directory exists or the node will fail to start
923
+ if err := os .MkdirAll (processConfig .PluginDir , perms .ReadWriteExecute ); err != nil {
924
+ return fmt .Errorf ("failed to create plugin dir: %w" , err )
925
+ }
926
+ flags .SetDefault (config .PluginDirKey , processConfig .PluginDir )
941
927
}
942
- flags .SetDefault (config .PluginDirKey , processConfig .PluginDir )
928
+
929
+ flags .SetDefault (config .DataDirKey , node .DataDir )
943
930
}
944
931
945
932
// Set the network and tmpnet defaults last to ensure they can be overridden
0 commit comments