Skip to content

Commit

Permalink
[tmpnet] Add Network.GetNetworkID() to get ID of a running network (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
marun committed Aug 8, 2024
1 parent 0e79ad8 commit 910ef21
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions tests/fixture/tmpnet/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ type Network struct {
// Path where network configuration and data is stored
Dir string

// Id of the network. If zero, must be set in Genesis.
// Id of the network. If zero, must be set in Genesis. Consider
// using the GetNetworkID method if needing to retrieve the ID of
// a running network.
NetworkID uint32

// Configuration common across nodes
Expand Down Expand Up @@ -562,10 +564,7 @@ func (n *Network) EnsureNodeConfig(node *Node) error {
node.NetworkOwner = n.Owner

// Set the network name if available
networkID := n.NetworkID
if networkID == 0 && n.Genesis != nil && n.Genesis.NetworkID > 0 {
networkID = n.Genesis.NetworkID
}
networkID := n.GetNetworkID()
if networkID > 0 {
// Convert the network id to a string to ensure consistency in JSON round-tripping.
flags[config.NetworkNameKey] = strconv.FormatUint(uint64(networkID), 10)
Expand Down Expand Up @@ -845,6 +844,18 @@ func (n *Network) getBootstrapIPsAndIDs(skippedNode *Node) ([]string, []string,
return bootstrapIPs, bootstrapIDs, nil
}

// GetNetworkID returns the effective ID of the network. If the network
// defines a genesis, the network ID in the genesis will be returned. If a
// genesis is not present (i.e. a network with a genesis included in the
// avalanchego binary - mainnet, testnet and local), the value of the
// NetworkID field will be returned
func (n *Network) GetNetworkID() uint32 {
if n.Genesis != nil && n.Genesis.NetworkID > 0 {
return n.Genesis.NetworkID
}
return n.NetworkID
}

// Waits until the provided nodes are healthy.
func waitForHealthy(ctx context.Context, w io.Writer, nodes []*Node) error {
ticker := time.NewTicker(networkHealthCheckInterval)
Expand Down

0 comments on commit 910ef21

Please sign in to comment.