Skip to content

Commit 28c3f67

Browse files
committed
tmpnet: Ensure restart after chain creation (#2675)
1 parent 1f29ab5 commit 28c3f67

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

tests/fixture/tmpnet/network.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ func (n *Network) CreateSubnets(ctx context.Context, w io.Writer) error {
562562
return err
563563
}
564564

565-
// Reconfigure nodes for the new subnets and their chains
565+
// Reconfigure nodes for the new subnets
566566
if _, err := fmt.Fprintf(w, "Configured nodes to track new subnet(s). Restart is required.\n"); err != nil {
567567
return err
568568
}
@@ -571,8 +571,8 @@ func (n *Network) CreateSubnets(ctx context.Context, w io.Writer) error {
571571
return err
572572
}
573573
}
574-
575574
// Restart nodes to allow new configuration to take effect
575+
// TODO(marun) Only restart the validator nodes of newly-created subnets
576576
if err := n.Restart(ctx, w); err != nil {
577577
return err
578578
}
@@ -589,6 +589,7 @@ func (n *Network) CreateSubnets(ctx context.Context, w io.Writer) error {
589589

590590
// Wait for nodes to become subnet validators
591591
pChainClient := platformvm.NewClient(n.Nodes[0].URI)
592+
restartRequired := false
592593
for _, subnet := range createdSubnets {
593594
if err := waitForActiveValidators(ctx, w, pChainClient, subnet); err != nil {
594595
return err
@@ -606,9 +607,22 @@ func (n *Network) CreateSubnets(ctx context.Context, w io.Writer) error {
606607
if _, err := fmt.Fprintf(w, " wrote chain configuration for subnet %q\n", subnet.Name); err != nil {
607608
return err
608609
}
610+
611+
// If one or more of the subnets chains have explicit configuration, the
612+
// subnet's validator nodes will need to be restarted for those nodes to read
613+
// the newly written chain configuration and apply it to the chain(s).
614+
if subnet.HasChainConfig() {
615+
restartRequired = true
616+
}
609617
}
610618

611-
return nil
619+
if !restartRequired {
620+
return nil
621+
}
622+
623+
// Restart nodes to allow configuration for the new chains to take effect
624+
// TODO(marun) Only restart the validator nodes of subnets that have chains that need configuring
625+
return n.Restart(ctx, w)
612626
}
613627

614628
func (n *Network) GetURIForNodeID(nodeID ids.NodeID) (string, error) {

tests/fixture/tmpnet/subnet.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,19 @@ func (s *Subnet) Write(subnetDir string, chainDir string) error {
243243
return nil
244244
}
245245

246+
// HasChainConfig indicates whether at least one of the subnet's
247+
// chains have explicit configuration. This can be used to determine
248+
// whether validator restart is required after chain creation to
249+
// ensure that chains are configured correctly.
250+
func (s *Subnet) HasChainConfig() bool {
251+
for _, chain := range s.Chains {
252+
if len(chain.Config) > 0 {
253+
return true
254+
}
255+
}
256+
return false
257+
}
258+
246259
func waitForActiveValidators(
247260
ctx context.Context,
248261
w io.Writer,

0 commit comments

Comments
 (0)