Skip to content

Commit

Permalink
tmpnet: Retain IDs of validating nodes with subnets
Browse files Browse the repository at this point in the history
  • Loading branch information
marun committed Jan 4, 2024
1 parent 2dca1dc commit 2731409
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
20 changes: 13 additions & 7 deletions tests/fixture/e2e/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,21 @@ func NewTestEnvironment(flagVars *FlagVars, desiredNetwork *tmpnet.Network) *Tes
require.NoError(network.CreateSubnets(DefaultContext(), ginkgo.GinkgoWriter))

// Wait for chains to have bootstrapped on all nodes
nodeURIs := network.GetNodeURIs()
Eventually(func() bool {
for _, subnet := range network.Subnets {
for _, node := range network.Nodes {
infoClient := info.NewClient(node.URI)
for _, chain := range subnet.Chains {
isBootstrapped, err := infoClient.IsBootstrapped(DefaultContext(), chain.ChainID.String())
// Ignore errors since a chain id that is not yet known will result in a recoverable error.
if err != nil || !isBootstrapped {
return false
for _, validatorID := range subnet.ValidatorIDs {
for _, nodeURI := range nodeURIs {
if validatorID == nodeURI.NodeID {
infoClient := info.NewClient(nodeURI.URI)
for _, chain := range subnet.Chains {
isBootstrapped, err := infoClient.IsBootstrapped(DefaultContext(), chain.ChainID.String())
// Ignore errors since a chain id that is not yet known will result in a recoverable error.
if err != nil || !isBootstrapped {
return false
}
}
break
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/fixture/tmpnet/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ func (n *Network) CreateSubnets(ctx context.Context, w io.Writer) error {
// Wait for nodes to become subnet validators
pChainClient := platformvm.NewClient(n.Nodes[0].URI)
for _, subnet := range createdSubnets {
if err := waitForActiveValidators(ctx, w, pChainClient, subnet, n.Nodes); err != nil {
if err := waitForActiveValidators(ctx, w, pChainClient, subnet); err != nil {
return err
}

Expand Down
10 changes: 7 additions & 3 deletions tests/fixture/tmpnet/subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ type Subnet struct {
// The private key that owns the subnet
OwningKey *secp256k1.PrivateKey

// IDs of the nodes responsible for validating the subnet
ValidatorIDs []ids.NodeID

Chains []*Chain
}

Expand Down Expand Up @@ -188,6 +191,8 @@ func (s *Subnet) AddValidators(ctx context.Context, nodes []*Node) error {
if err != nil {
return err
}

s.ValidatorIDs = append(s.ValidatorIDs, node.NodeID)
}

return nil
Expand Down Expand Up @@ -236,7 +241,6 @@ func waitForActiveValidators(
w io.Writer,
pChainClient platformvm.Client,
subnet *Subnet,
nodes []*Node,
) error {
ticker := time.NewTicker(DefaultPollingInterval)
defer ticker.Stop()
Expand All @@ -258,8 +262,8 @@ func waitForActiveValidators(
validatorSet.Add(validator.NodeID)
}
allActive := true
for _, node := range nodes {
if !validatorSet.Contains(node.NodeID) {
for _, validatorID := range subnet.ValidatorIDs {
if !validatorSet.Contains(validatorID) {
allActive = false
}
}
Expand Down

0 comments on commit 2731409

Please sign in to comment.