Documentation ¶
Index ¶
- Constants
- Variables
- func BootstrapNewNetwork(ctx context.Context, w io.Writer, network *Network, rootNetworkDir string, ...) error
- func DefaultChainConfigs() map[string]FlagsMap
- func DefaultJSONMarshal(v interface{}) ([]byte, error)
- func GetReusableNetworkPathForOwner(owner string) (string, error)
- func NewPrivateKeys(keyCount int) ([]*secp256k1.PrivateKey, error)
- func NewTestGenesis(networkID uint32, nodes []*Node, keysToFund []*secp256k1.PrivateKey) (*genesis.UnparsedConfig, error)
- func NodesToIDs(nodes ...*Node) []ids.NodeID
- func RestartNetwork(ctx context.Context, w io.Writer, dir string) error
- func StopNetwork(ctx context.Context, dir string) error
- func WaitForActiveValidators(ctx context.Context, w io.Writer, pChainClient platformvm.Client, ...) error
- func WaitForHealthy(ctx context.Context, node *Node) error
- type Chain
- type FlagsMap
- type Network
- func (n *Network) Bootstrap(ctx context.Context, w io.Writer) error
- func (n *Network) Create(rootDir string) error
- func (n *Network) CreateSubnets(ctx context.Context, w io.Writer, apiURI string, restartRequired bool) error
- func (n *Network) EnsureDefaultConfig(w io.Writer, avalancheGoPath string, pluginDir string) error
- func (n *Network) EnsureNodeConfig(node *Node) error
- func (n *Network) EnvFileContents() string
- func (n *Network) EnvFilePath() string
- func (n *Network) GetChainConfigDir() string
- func (n *Network) GetNodeURIs() []NodeURI
- func (n *Network) GetSubnet(name string) *Subnet
- func (n *Network) GetSubnetDir() string
- func (n *Network) GetURIForNodeID(nodeID ids.NodeID) (string, error)
- func (n *Network) Read() error
- func (n *Network) Restart(ctx context.Context, w io.Writer) error
- func (n *Network) RestartNode(ctx context.Context, w io.Writer, node *Node) error
- func (n *Network) StartNode(ctx context.Context, w io.Writer, node *Node) error
- func (n *Network) StartNodes(ctx context.Context, w io.Writer, nodesToStart ...*Node) error
- func (n *Network) Stop(ctx context.Context) error
- func (n *Network) TrackedSubnetsForNode(nodeID ids.NodeID) string
- func (n *Network) Write() error
- type Node
- func (n *Node) EnsureBLSSigningKey() error
- func (n *Node) EnsureKeys() error
- func (n *Node) EnsureNodeID() error
- func (n *Node) EnsureStakingKeypair() error
- func (n *Node) GetDataDir() string
- func (n *Node) GetProofOfPossession() (*signer.ProofOfPossession, error)
- func (n *Node) InitiateStop(ctx context.Context) error
- func (n *Node) IsHealthy(ctx context.Context) (bool, error)
- func (n *Node) Read() error
- func (n *Node) SaveAPIPort() error
- func (n *Node) SaveMetricsSnapshot(ctx context.Context) error
- func (n *Node) SetNetworkingConfig(bootstrapIDs []string, bootstrapIPs []string)
- func (n *Node) Start(w io.Writer) error
- func (n *Node) Stop(ctx context.Context) error
- func (n *Node) WaitForStopped(ctx context.Context) error
- func (n *Node) Write() error
- type NodeProcess
- type NodeRuntime
- type NodeRuntimeConfig
- type NodeURI
- type Subnet
- func (s *Subnet) AddValidators(ctx context.Context, w io.Writer, apiURI string, nodes ...*Node) error
- func (s *Subnet) Create(ctx context.Context, uri string) error
- func (s *Subnet) CreateChains(ctx context.Context, w io.Writer, uri string) error
- func (s *Subnet) GetWallet(ctx context.Context, uri string) (primary.Wallet, error)
- func (s *Subnet) HasChainConfig() bool
- func (s *Subnet) Write(subnetDir string, chainDir string) error
- type XChainBalanceMap
Constants ¶
const ( // Interval appropriate for network operations that should be // retried periodically but not too often. DefaultPollingInterval = 500 * time.Millisecond // Validator start time must be a minimum of SyncBound from the // current time for validator addition to succeed, and adding 20 // seconds provides a buffer in case of any delay in processing. DefaultValidatorStartTimeDiff = executor.SyncBound + 20*time.Second DefaultNetworkTimeout = 2 * time.Minute // Minimum required to ensure connectivity-based health checks will pass DefaultNodeCount = 2 // Arbitrary number of pre-funded keys to create by default DefaultPreFundedKeyCount = 50 // A short minimum stake duration enables testing of staking logic. DefaultMinStakeDuration = time.Second )
const ( // Constants defining the names of shell variables whose value can // configure network orchestration. NetworkDirEnvName = "TMPNET_NETWORK_DIR" RootDirEnvName = "TMPNET_ROOT_DIR" // eth address: 0x8db97C7cEcE249c2b98bDC0226Cc4C2A57BF52FC HardHatKeyStr = "56289e99c94b6912bfc12adc093c9b51124f0dc54ac7a766b2bc5ccf558d8027" )
const (
AvalancheGoPathEnvName = "METALGO_PATH"
)
const (
DefaultNodeTickerInterval = 50 * time.Millisecond
)
Variables ¶
var ErrNotRunning = errors.New("not running")
var ( // Key expected to be funded for subnet-evm hardhat testing // TODO(marun) Remove when subnet-evm configures the genesis with this key. HardhatKey *secp256k1.PrivateKey )
Functions ¶
func BootstrapNewNetwork ¶ added in v1.11.9
func DefaultChainConfigs ¶ added in v1.10.18
A set of chain configurations appropriate for testing.
func DefaultJSONMarshal ¶
Marshal to json with default prefix and indent.
func GetReusableNetworkPathForOwner ¶ added in v1.11.9
Retrieves the path to a reusable network path for the given owner.
func NewPrivateKeys ¶ added in v1.10.18
func NewPrivateKeys(keyCount int) ([]*secp256k1.PrivateKey, error)
Helper simplifying creation of a set of private keys
func NewTestGenesis ¶
func NewTestGenesis( networkID uint32, nodes []*Node, keysToFund []*secp256k1.PrivateKey, ) (*genesis.UnparsedConfig, error)
Create a genesis struct valid for bootstrapping a test network. Note that many of the genesis fields (e.g. reward addresses) are randomly generated or hard-coded.
func NodesToIDs ¶ added in v1.11.9
func RestartNetwork ¶ added in v1.10.18
Restarts the nodes of the network configured in the provided directory.
func StopNetwork ¶ added in v1.10.18
Stops the nodes of the network configured in the provided directory.
func WaitForActiveValidators ¶
Types ¶
type Chain ¶ added in v1.10.18
type Chain struct { // Set statically VMID ids.ID Config string Genesis []byte // Set at runtime ChainID ids.ID PreFundedKey *secp256k1.PrivateKey }
func (*Chain) WriteConfig ¶ added in v1.10.18
Write the chain configuration to the specified directory.
type FlagsMap ¶
type FlagsMap map[string]interface{}
Defines a mapping of flag keys to values intended to be supplied to an invocation of an AvalancheGo node.
func DefaultTestFlags ¶ added in v1.11.9
func DefaultTestFlags() FlagsMap
Flags appropriate for networks used for all types of testing.
func DefaultTmpnetFlags ¶ added in v1.11.9
func DefaultTmpnetFlags() FlagsMap
Flags appropriate for tmpnet networks.
func ReadFlagsMap ¶
Utility function simplifying construction of a FlagsMap from a file.
func (FlagsMap) GetBoolVal ¶ added in v1.11.9
GetBoolVal simplifies retrieving a map value as a bool.
func (FlagsMap) GetStringVal ¶
GetStringVal simplifies retrieving a map value as a string.
func (FlagsMap) SetDefaults ¶
SetDefaults ensures the effectiveness of flag overrides by only setting values supplied in the defaults map that are not already explicitly set.
type Network ¶
type Network struct { // Uniquely identifies the temporary network for metrics // collection. Distinct from avalanchego's concept of network ID // since the utility of special network ID values (e.g. to trigger // specific fork behavior in a given network) precludes requiring // unique network ID values across all temporary networks. UUID string // A string identifying the entity that started or maintains this // network. Useful for differentiating between networks when a // given CI job uses multiple networks. Owner string // Path where network configuration and data is stored Dir string // Id of the network. If zero, must be set in Genesis. NetworkID uint32 // Genesis for the network. If nil, NetworkID must be non-zero Genesis *genesis.UnparsedConfig // Configuration for primary network chains (P, X, C) // TODO(marun) Rename to PrimaryChainConfigs ChainConfigs map[string]FlagsMap // Default configuration to use when creating new nodes DefaultFlags FlagsMap DefaultRuntimeConfig NodeRuntimeConfig // Keys pre-funded in the genesis on both the X-Chain and the C-Chain PreFundedKeys []*secp256k1.PrivateKey // Nodes that constitute the network Nodes []*Node // Subnets that have been enabled on the network Subnets []*Subnet }
Collects the configuration for running a temporary avalanchego network
func LocalNetworkOrPanic ¶ added in v1.11.9
func LocalNetworkOrPanic() *Network
func NewDefaultNetwork ¶ added in v1.11.9
func ReadNetwork ¶ added in v1.10.18
Reads a network from the provided directory.
func (*Network) Create ¶ added in v1.10.18
Creates the network on disk, generating its genesis and configuring its nodes in the process.
func (*Network) CreateSubnets ¶ added in v1.10.18
func (n *Network) CreateSubnets(ctx context.Context, w io.Writer, apiURI string, restartRequired bool) error
Ensure that each subnet on the network is created. If restartRequired is false, node restart to pick up configuration changes becomes the responsibility of the caller.
func (*Network) EnsureDefaultConfig ¶ added in v1.10.18
Initializes a new network with default configuration.
func (*Network) EnsureNodeConfig ¶ added in v1.10.18
Ensures the provided node has the configuration it needs to start. If the data dir is not set, it will be defaulted to [nodeParentDir]/[node ID]. For a not-yet-created network, no action will be taken. TODO(marun) Reword or refactor to account for the differing behavior pre- vs post-start
func (*Network) EnvFileContents ¶ added in v1.10.18
func (*Network) EnvFilePath ¶ added in v1.10.18
func (*Network) GetChainConfigDir ¶
func (*Network) GetNodeURIs ¶ added in v1.10.18
func (*Network) GetSubnetDir ¶
func (*Network) GetURIForNodeID ¶ added in v1.10.18
func (*Network) RestartNode ¶ added in v1.11.9
Restart a single node.
func (*Network) StartNode ¶ added in v1.10.18
Starts the provided node after configuring it for the network.
func (*Network) StartNodes ¶ added in v1.11.9
Starts the specified nodes
func (*Network) TrackedSubnetsForNode ¶ added in v1.11.9
TrackedSubnetsForNode returns the subnet IDs for the given node
type Node ¶
type Node struct { // Uniquely identifies the network the node is part of to enable monitoring. NetworkUUID string // Identify the entity associated with this network. This is // intended to be used to label metrics to enable filtering // results for a test run between the primary/shared network used // by the majority of tests and private networks used by // individual tests. NetworkOwner string // Set by EnsureNodeID which is also called when the node is read. NodeID ids.NodeID // Flags that will be supplied to the node at startup Flags FlagsMap // An ephemeral node is not expected to be a persistent member of the network and // should therefore not be used as for bootstrapping purposes. IsEphemeral bool // The configuration used to initialize the node runtime. RuntimeConfig *NodeRuntimeConfig // Runtime state, intended to be set by NodeRuntime URI string StakingAddress string // contains filtered or unexported fields }
Node supports configuring and running a node participating in a temporary network.
func NewEphemeralNode ¶ added in v1.11.9
Initializes an ephemeral node using the provided config flags
func NewNodesOrPanic ¶ added in v1.11.9
Initializes the specified number of nodes.
func (*Node) EnsureBLSSigningKey ¶ added in v1.10.18
Ensures a BLS signing key is generated if not already present.
func (*Node) EnsureKeys ¶ added in v1.10.18
Ensures staking and signing keys are generated if not already present and that the node ID (derived from the staking keypair) is set.
func (*Node) EnsureNodeID ¶ added in v1.10.18
Derives the node ID. Requires that a tls keypair is present.
func (*Node) EnsureStakingKeypair ¶ added in v1.10.18
Ensures a staking keypair is generated if not already present.
func (*Node) GetDataDir ¶ added in v1.11.9
func (*Node) GetProofOfPossession ¶ added in v1.10.18
func (n *Node) GetProofOfPossession() (*signer.ProofOfPossession, error)
Derives the nodes proof-of-possession. Requires the node to have a BLS signing key.
func (*Node) InitiateStop ¶ added in v1.10.18
func (*Node) SaveAPIPort ¶ added in v1.11.3
Saves the currently allocated API port to the node's configuration for use across restarts. Reusing the port ensures consistent labeling of metrics.
func (*Node) SaveMetricsSnapshot ¶ added in v1.10.18
Writes the current state of the metrics endpoint to disk
func (*Node) SetNetworkingConfig ¶ added in v1.10.18
Sets networking configuration for the node. Convenience method for setting networking flags.
func (*Node) WaitForStopped ¶ added in v1.10.18
type NodeProcess ¶ added in v1.10.18
type NodeProcess struct {
// contains filtered or unexported fields
}
Defines local-specific node configuration. Supports setting default and node-specific values.
func (*NodeProcess) InitiateStop ¶ added in v1.10.18
func (p *NodeProcess) InitiateStop() error
Signals the node process to stop.
func (*NodeProcess) IsHealthy ¶ added in v1.10.18
func (p *NodeProcess) IsHealthy(ctx context.Context) (bool, error)
func (*NodeProcess) Start ¶ added in v1.10.18
func (p *NodeProcess) Start(w io.Writer) error
Start waits for the process context to be written which indicates that the node will be accepting connections on its staking port. The network will start faster with this synchronization due to the avoidance of exponential backoff if a node tries to connect to a beacon that is not ready.
func (*NodeProcess) WaitForStopped ¶ added in v1.10.18
func (p *NodeProcess) WaitForStopped(ctx context.Context) error
Waits for the node process to stop.
type NodeRuntime ¶ added in v1.10.18
type NodeRuntime interface { Start(w io.Writer) error InitiateStop() error WaitForStopped(ctx context.Context) error IsHealthy(ctx context.Context) (bool, error) // contains filtered or unexported methods }
NodeRuntime defines the methods required to support running a node.
type NodeRuntimeConfig ¶ added in v1.10.18
type NodeRuntimeConfig struct {
AvalancheGoPath string
}
Configuration required to configure a node runtime.
type Subnet ¶ added in v1.10.18
type Subnet struct { // A unique string that can be used to refer to the subnet across different temporary // networks (since the SubnetID will be different every time the subnet is created) Name string Config FlagsMap // The ID of the transaction that created the subnet SubnetID ids.ID // The private key that owns the subnet OwningKey *secp256k1.PrivateKey // IDs of the nodes responsible for validating the subnet ValidatorIDs []ids.NodeID Chains []*Chain }
func (*Subnet) AddValidators ¶ added in v1.10.18
func (s *Subnet) AddValidators(ctx context.Context, w io.Writer, apiURI string, nodes ...*Node) error
Add validators to the subnet
func (*Subnet) Create ¶ added in v1.10.18
Issues the subnet creation transaction and retains the result. The URI of a node is required to issue the transaction.
func (*Subnet) CreateChains ¶ added in v1.10.18
func (*Subnet) HasChainConfig ¶ added in v1.11.1
HasChainConfig indicates whether at least one of the subnet's chains have explicit configuration. This can be used to determine whether validator restart is required after chain creation to ensure that chains are configured correctly.
type XChainBalanceMap ¶
Helper type to simplify configuring X-Chain genesis balances