@@ -128,6 +128,8 @@ type Network struct {
128
128
129
129
// Subnets that have been enabled on the network
130
130
Subnets []* Subnet
131
+
132
+ log logging.Logger
131
133
}
132
134
133
135
func NewDefaultNetwork (owner string ) * Network {
@@ -172,8 +174,8 @@ func BootstrapNewNetwork(
172
174
}
173
175
174
176
// Stops the nodes of the network configured in the provided directory.
175
- func StopNetwork (ctx context.Context , dir string ) error {
176
- network , err := ReadNetwork (dir )
177
+ func StopNetwork (ctx context.Context , log logging. Logger , dir string ) error {
178
+ network , err := ReadNetwork (log , dir )
177
179
if err != nil {
178
180
return err
179
181
}
@@ -182,21 +184,22 @@ func StopNetwork(ctx context.Context, dir string) error {
182
184
183
185
// Restarts the nodes of the network configured in the provided directory.
184
186
func RestartNetwork (ctx context.Context , log logging.Logger , dir string ) error {
185
- network , err := ReadNetwork (dir )
187
+ network , err := ReadNetwork (log , dir )
186
188
if err != nil {
187
189
return err
188
190
}
189
- return network .Restart (ctx , log )
191
+ return network .Restart (ctx )
190
192
}
191
193
192
194
// Reads a network from the provided directory.
193
- func ReadNetwork (dir string ) (* Network , error ) {
195
+ func ReadNetwork (log logging. Logger , dir string ) (* Network , error ) {
194
196
canonicalDir , err := toCanonicalDir (dir )
195
197
if err != nil {
196
198
return nil , err
197
199
}
198
200
network := & Network {
199
201
Dir : canonicalDir ,
202
+ log : log ,
200
203
}
201
204
if err := network .Read (); err != nil {
202
205
return nil , fmt .Errorf ("failed to read network: %w" , err )
@@ -213,6 +216,8 @@ func (n *Network) EnsureDefaultConfig(log logging.Logger) error {
213
216
zap .Any ("runtimeConfig" , n .DefaultRuntimeConfig ),
214
217
)
215
218
219
+ n .log = log
220
+
216
221
// A UUID supports centralized metrics collection
217
222
if len (n .UUID ) == 0 {
218
223
n .UUID = uuid .NewString ()
@@ -342,9 +347,8 @@ func (n *Network) StartNodes(ctx context.Context, log logging.Logger, nodesToSta
342
347
// Record the time before nodes are started to ensure visibility of subsequently collected metrics via the emitted link
343
348
startTime := time .Now ()
344
349
345
- // Configure the networking for each node and start
346
350
for _ , node := range nodesToStart {
347
- if err := n .StartNode (ctx , log , node ); err != nil {
351
+ if err := n .StartNode (ctx , node ); err != nil {
348
352
return err
349
353
}
350
354
}
@@ -438,7 +442,7 @@ func (n *Network) Bootstrap(ctx context.Context, log logging.Logger) error {
438
442
439
443
if len (n .Nodes ) == 1 {
440
444
// Ensure the node is restarted to pick up subnet and chain configuration
441
- return n .RestartNode (ctx , log , bootstrapNode )
445
+ return n .RestartNode (ctx , bootstrapNode )
442
446
}
443
447
444
448
// TODO(marun) This last restart of the bootstrap node might be unnecessary if:
@@ -450,7 +454,7 @@ func (n *Network) Bootstrap(ctx context.Context, log logging.Logger) error {
450
454
if err := bootstrapNode .Stop (ctx ); err != nil {
451
455
return fmt .Errorf ("failed to stop node %s: %w" , bootstrapNode .NodeID , err )
452
456
}
453
- if err := n .StartNode (ctx , log , bootstrapNode ); err != nil {
457
+ if err := n .StartNode (ctx , bootstrapNode ); err != nil {
454
458
return fmt .Errorf ("failed to start node %s: %w" , bootstrapNode .NodeID , err )
455
459
}
456
460
@@ -459,19 +463,19 @@ func (n *Network) Bootstrap(ctx context.Context, log logging.Logger) error {
459
463
}
460
464
461
465
// Starts the provided node after configuring it for the network.
462
- func (n * Network ) StartNode (ctx context.Context , log logging. Logger , node * Node ) error {
466
+ func (n * Network ) StartNode (ctx context.Context , node * Node ) error {
463
467
if err := n .EnsureNodeConfig (node ); err != nil {
464
468
return err
465
469
}
466
470
if err := node .Write (); err != nil {
467
471
return err
468
472
}
469
473
470
- if err := n .writeNodeFlags (log , node ); err != nil {
474
+ if err := n .writeNodeFlags (node ); err != nil {
471
475
return fmt .Errorf ("writing node flags: %w" , err )
472
476
}
473
477
474
- if err := node .Start (log ); err != nil {
478
+ if err := node .Start (); err != nil {
475
479
// Attempt to stop an unhealthy node to provide some assurance to the caller
476
480
// that an error condition will not result in a lingering process.
477
481
err = errors .Join (err , node .Stop (ctx ))
@@ -482,7 +486,7 @@ func (n *Network) StartNode(ctx context.Context, log logging.Logger, node *Node)
482
486
}
483
487
484
488
// Restart a single node.
485
- func (n * Network ) RestartNode (ctx context.Context , log logging. Logger , node * Node ) error {
489
+ func (n * Network ) RestartNode (ctx context.Context , node * Node ) error {
486
490
runtimeConfig := node .getRuntimeConfig ()
487
491
if runtimeConfig .Process != nil && runtimeConfig .Process .ReuseDynamicPorts {
488
492
// Attempt to save the API port currently being used so the
@@ -497,10 +501,10 @@ func (n *Network) RestartNode(ctx context.Context, log logging.Logger, node *Nod
497
501
if err := node .Stop (ctx ); err != nil {
498
502
return fmt .Errorf ("failed to stop node %s: %w" , node .NodeID , err )
499
503
}
500
- if err := n .StartNode (ctx , log , node ); err != nil {
504
+ if err := n .StartNode (ctx , node ); err != nil {
501
505
return fmt .Errorf ("failed to start node %s: %w" , node .NodeID , err )
502
506
}
503
- log .Info ("waiting for node to report healthy" ,
507
+ n . log .Info ("waiting for node to report healthy" ,
504
508
zap .Stringer ("nodeID" , node .NodeID ),
505
509
)
506
510
return WaitForHealthy (ctx , node )
@@ -535,11 +539,11 @@ func (n *Network) Stop(ctx context.Context) error {
535
539
return nil
536
540
}
537
541
538
- // Restarts all non-ephemeral nodes in the network.
539
- func (n * Network ) Restart (ctx context.Context , log logging. Logger ) error {
540
- log .Info ("restarting network" )
542
+ // Restarts all nodes in the network.
543
+ func (n * Network ) Restart (ctx context.Context ) error {
544
+ n . log .Info ("restarting network" )
541
545
for _ , node := range n .Nodes {
542
- if err := n .RestartNode (ctx , log , node ); err != nil {
546
+ if err := n .RestartNode (ctx , node ); err != nil {
543
547
return err
544
548
}
545
549
}
@@ -669,7 +673,7 @@ func (n *Network) CreateSubnets(ctx context.Context, log logging.Logger, apiURI
669
673
// Only running nodes should be restarted
670
674
continue
671
675
}
672
- if err := n .RestartNode (ctx , log , node ); err != nil {
676
+ if err := n .RestartNode (ctx , node ); err != nil {
673
677
return err
674
678
}
675
679
}
@@ -737,7 +741,7 @@ func (n *Network) CreateSubnets(ctx context.Context, log logging.Logger, apiURI
737
741
if ! validatorsToRestart .Contains (node .NodeID ) {
738
742
continue
739
743
}
740
- if err := n .RestartNode (ctx , log , node ); err != nil {
744
+ if err := n .RestartNode (ctx , node ); err != nil {
741
745
return err
742
746
}
743
747
}
@@ -877,7 +881,7 @@ func (n *Network) GetChainConfigContent() (string, error) {
877
881
878
882
// writeNodeFlags determines the set of flags that should be used to
879
883
// start the given node and writes them to a file in the node path.
880
- func (n * Network ) writeNodeFlags (log logging. Logger , node * Node ) error {
884
+ func (n * Network ) writeNodeFlags (node * Node ) error {
881
885
flags := maps .Clone (node .Flags )
882
886
883
887
// Convert the network id to a string to ensure consistency in JSON round-tripping.
@@ -902,7 +906,7 @@ func (n *Network) writeNodeFlags(log logging.Logger, node *Node) error {
902
906
903
907
isSingleNodeNetwork := (len (n .Nodes ) == 1 && len (n .Genesis .InitialStakers ) == 1 )
904
908
if isSingleNodeNetwork {
905
- log .Info ("defaulting to sybil protection disabled to enable a single-node network to start" )
909
+ n . log .Info ("defaulting to sybil protection disabled to enable a single-node network to start" )
906
910
flags .SetDefault (config .SybilProtectionEnabledKey , "false" )
907
911
}
908
912
}
0 commit comments