@@ -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
}
@@ -544,8 +536,7 @@ func (n *Network) Restart(ctx context.Context, log logging.Logger) error {
544
536
}
545
537
546
538
// Ensures the provided node has the configuration it needs to start. If the data dir is not
547
- // set, it will be defaulted to [nodeParentDir]/[node ID]. For a not-yet-created network,
548
- // no action will be taken.
539
+ // set, it will be defaulted to [nodeParentDir]/[node ID].
549
540
func (n * Network ) EnsureNodeConfig (node * Node ) error {
550
541
// Ensure the node has access to network configuration
551
542
node .network = n
@@ -554,14 +545,9 @@ func (n *Network) EnsureNodeConfig(node *Node) error {
554
545
return err
555
546
}
556
547
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
- }
548
+ // Ensure a data directory if not already set
549
+ if len (node .DataDir ) == 0 {
550
+ node .DataDir = filepath .Join (n .Dir , node .NodeID .String ())
565
551
}
566
552
567
553
return nil
@@ -768,16 +754,13 @@ func (n *Network) GetNodeURIs() []NodeURI {
768
754
// collecting the bootstrap details for restarting a node).
769
755
// For consumption outside of avalanchego. Needs to be kept exported.
770
756
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 {
757
+ bootstrapIPs := []string {}
758
+ bootstrapIDs := []string {}
759
+ for _ , node := range n .Nodes {
760
+ if node .IsEphemeral {
761
+ // Ephemeral nodes are not guaranteed to stay running
762
+ continue
763
+ }
781
764
if skippedNode != nil && node .NodeID == skippedNode .NodeID {
782
765
continue
783
766
}
@@ -940,12 +923,16 @@ func (n *Network) writeNodeFlags(log logging.Logger, node *Node) error {
940
923
// Only configure the plugin dir with a non-empty value to ensure the use of
941
924
// the default value (`[datadir]/plugins`) when no plugin dir is configured.
942
925
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 )
926
+ if processConfig != nil {
927
+ if len (processConfig .PluginDir ) > 0 {
928
+ // Ensure the plugin directory exists or the node will fail to start
929
+ if err := os .MkdirAll (processConfig .PluginDir , perms .ReadWriteExecute ); err != nil {
930
+ return fmt .Errorf ("failed to create plugin dir: %w" , err )
931
+ }
932
+ flags .SetDefault (config .PluginDirKey , processConfig .PluginDir )
947
933
}
948
- flags .SetDefault (config .PluginDirKey , processConfig .PluginDir )
934
+
935
+ flags .SetDefault (config .DataDirKey , node .DataDir )
949
936
}
950
937
951
938
// Set the network and tmpnet defaults last to ensure they can be overridden
0 commit comments