@@ -240,13 +240,6 @@ func (n *Network) EnsureDefaultConfig(log logging.Logger) error {
240
240
n .PrimaryChainConfigs [alias ].SetDefaults (chainConfig )
241
241
}
242
242
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
-
250
243
return nil
251
244
}
252
245
@@ -504,23 +497,22 @@ func (n *Network) RestartNode(ctx context.Context, log logging.Logger, node *Nod
504
497
505
498
// Stops all nodes in the network.
506
499
func (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 {
510
502
return err
511
503
}
512
504
513
505
var errs []error
514
506
515
507
// Initiate stop on all nodes
516
- for _ , node := range nodes {
508
+ for _ , node := range n . Nodes {
517
509
if err := node .InitiateStop (ctx ); err != nil {
518
510
errs = append (errs , fmt .Errorf ("failed to stop node %s: %w" , node .NodeID , err ))
519
511
}
520
512
}
521
513
522
514
// Wait for stop to complete on all nodes
523
- for _ , node := range nodes {
515
+ for _ , node := range n . Nodes {
524
516
if err := node .WaitForStopped (ctx ); err != nil {
525
517
errs = append (errs , fmt .Errorf ("failed to wait for node %s to stop: %w" , node .NodeID , err ))
526
518
}
@@ -554,14 +546,9 @@ func (n *Network) EnsureNodeConfig(node *Node) error {
554
546
return err
555
547
}
556
548
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 ())
565
552
}
566
553
567
554
return nil
@@ -768,16 +755,13 @@ func (n *Network) GetNodeURIs() []NodeURI {
768
755
// collecting the bootstrap details for restarting a node).
769
756
// For consumption outside of avalanchego. Needs to be kept exported.
770
757
func (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
+ }
781
765
if skippedNode != nil && node .NodeID == skippedNode .NodeID {
782
766
continue
783
767
}
@@ -940,12 +924,16 @@ func (n *Network) writeNodeFlags(log logging.Logger, node *Node) error {
940
924
// Only configure the plugin dir with a non-empty value to ensure the use of
941
925
// the default value (`[datadir]/plugins`) when no plugin dir is configured.
942
926
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 )
947
934
}
948
- flags .SetDefault (config .PluginDirKey , processConfig .PluginDir )
935
+
936
+ flags .SetDefault (config .DataDirKey , node .DataDir )
949
937
}
950
938
951
939
// Set the network and tmpnet defaults last to ensure they can be overridden
0 commit comments