Help us shape the future of Go! Take the 2026 Go Developer Survey

network

package
v1.19.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 11, 2026 License: BSD-3-Clause Imports: 17 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUndefined    = errors.New("undefined network")
	ErrStopped      = errors.New("network stopped")
	ErrNodeNotFound = errors.New("node not found in network")
)

Functions

func LoadCanonicalGenesis

func LoadCanonicalGenesis(networkID uint32) (map[string]interface{}, error)

LoadCanonicalGenesis loads canonical genesis for mainnet/testnet/devnet WITHOUT modifying configs. This preserves the exact cChainGenesis to ensure correct genesis hash computation. For custom/local networks, falls back to LoadLocalGenesis behavior.

func LoadGenesisForNetwork

func LoadGenesisForNetwork(networkID uint32) ([]byte, error)

LoadGenesisForNetwork loads genesis config from standard paths based on network ID. For mainnet (1), testnet (2), and devnet (3), it loads from luxfi/genesis configs. For other network IDs, it falls back to local genesis.

func LoadLocalGenesis

func LoadLocalGenesis() (map[string]interface{}, error)

LoadLocalGenesis loads the embedded local/dev genesis from disk. Returns map[string]interface{} for legacy compatibility.

IMPORTANT: This function is for LOCAL/DEV networks only. For canonical networks (mainnet/testnet/devnet), use the genesis configs from luxfi/genesis/configs package via local.NewCanonicalXxxConfig().

The embedded genesis.json MUST have cChainGenesis as a JSON string (not object). This function does NOT modify cChainGenesis - it preserves it exactly as embedded.

func LoadMainnetGenesis

func LoadMainnetGenesis() ([]byte, error)

LoadMainnetGenesis loads the canonical mainnet genesis configuration.

func LoadTestnetGenesis

func LoadTestnetGenesis() ([]byte, error)

LoadTestnetGenesis loads the canonical testnet genesis configuration.

func NewGenesis

func NewGenesis(
	networkID uint32,
	xChainBalances []AddrAndBalance,
	cChainBalances []AddrAndBalance,
	genesisVdrs []ids.NodeID,
) ([]byte, error)

NewGenesis returns a genesis JSON where: The nodes in [genesisVdrs] are validators. The C-Chain and X-Chain balances are given by [cChainBalances] and [xChainBalances]. Note that many of the genesis fields (i.e. reward addresses) are randomly generated or hard-coded.

Types

type AddrAndBalance

type AddrAndBalance struct {
	Addr    ids.ShortID
	Balance *big.Int
}

AddrAndBalance holds both an address and its balance

type ChainSpec

type ChainSpec struct {
	VMName             string
	Genesis            []byte
	ChainID            *string
	ParticipantsSpec   *ParticipantsSpec
	ChainConfig        []byte
	NetworkUpgrade     []byte
	Alias              string
	PerNodeChainConfig map[string][]byte
	BlockchainName     string // Unique name for the blockchain (defaults to VMName if empty)
}

type Config

type Config struct {
	// Must not be empty
	Genesis string `json:"genesis"`
	// May have length 0
	// (i.e. network may have no nodes on creation.)
	NodeConfigs []node.Config `json:"nodeConfigs"`
	// Flags that will be passed to each node in this network.
	// It can be empty.
	// Config flags may also be passed in a node's config struct
	// or config file.
	// The precedence of flags handling is, from highest to lowest:
	// 1. Flags defined in a node's node.Config
	// 2. Flags defined in a network's network.Config
	// 3. Flags defined in a node's config file
	// For example, if a network.Config has flag W set to X,
	// and a node within that network has flag W set to Y,
	// and the node's config file has flag W set to Z,
	// then the node will be started with flag W set to Y.
	Flags map[string]interface{} `json:"flags"`
	// Binary path to use per default, if not specified in node config
	BinaryPath string `json:"binaryPath"`
	// Chain config files to use per default, if not specified in node config
	ChainConfigFiles map[string]string `json:"chainConfigFiles"`
	// Genesis config files for EVM chains (per blockchain ID)
	GenesisConfigFiles map[string]string `json:"genesisConfigFiles"`
	// Upgrade config files to use per default, if not specified in node config
	UpgradeConfigFiles map[string]string `json:"upgradeConfigFiles"`
	// P-Chain config files to use per default, if not specified in node config
	PChainConfigFiles map[string]string `json:"pChainConfigFiles"`
}

Config that defines a network when it is created.

func (*Config) Validate

func (c *Config) Validate() error

Validate returns an error if this config is invalid

type ElasticChainSpec

type ElasticChainSpec struct {
	ChainID                  *string
	AssetName                string
	AssetSymbol              string
	InitialSupply            uint64
	MaxSupply                uint64
	MinConsumptionRate       uint64
	MaxConsumptionRate       uint64
	MinValidatorStake        uint64
	MaxValidatorStake        uint64
	MinStakeDuration         time.Duration
	MaxStakeDuration         time.Duration
	MinDelegationFee         uint32
	MinDelegatorStake        uint64
	MaxValidatorWeightFactor byte
	UptimeRequirement        uint32
}

type Network

type Network interface {
	// Returns nil if all the nodes in the network are healthy.
	// A stopped network is considered unhealthy.
	// Timeout is given by the context parameter.
	Healthy(context.Context) error
	// Stop all the nodes.
	// Returns ErrStopped if Stop() was previously called.
	Stop(context.Context) error
	// Start a new node with the given config.
	// Returns ErrStopped if Stop() was previously called.
	AddNode(node.Config) (node.Node, error)
	// Stop the node with this name.
	// Returns ErrStopped if Stop() was previously called.
	RemoveNode(ctx context.Context, name string) error
	// Pause the node with this name.
	// Returns ErrStopped if Stop() was previously called.
	PauseNode(ctx context.Context, name string) error
	// Resume the node with this name.
	// Returns ErrStopped if Stop() was previously called.
	ResumeNode(ctx context.Context, name string) error
	// Return the node with this name.
	// Returns ErrStopped if Stop() was previously called.
	GetNode(name string) (node.Node, error)
	// Return all the nodes in this network.
	// Node name --> Node.
	// Returns ErrStopped if Stop() was previously called.
	GetAllNodes() (map[string]node.Node, error)
	// Returns the names of all nodes in this network.
	// Returns ErrStopped if Stop() was previously called.
	GetNodeNames() ([]string, error)
	// Save network snapshot
	// Network is stopped in order to do a safe preservation
	// Returns the full local path to the snapshot dir
	SaveSnapshot(context.Context, string) (string, error)
	// SaveHotSnapshot saves a snapshot without stopping the network
	// Uses CoW on APFS (macOS) for instant snapshots
	// WARNING: May have minor inconsistencies if writes occur during copy
	SaveHotSnapshot(context.Context, string) (string, error)
	// Remove network snapshot
	RemoveSnapshot(string) error
	// Get name of available snapshots
	GetSnapshotNames() ([]string, error)
	// Restart a given node using the same config, optionally changing binary path, plugin dir,
	// track chains, a map of chain configs, a map of upgrade configs, and
	// a map of chain configs
	RestartNode(context.Context, string, string, string, string, map[string]string, map[string]string, map[string]string) error
	// Create the specified chains
	CreateChains(context.Context, []ChainSpec) ([]ids.ID, error)
	// Create chain participant groups (validators)
	CreateParticipantGroups(context.Context, []ParticipantsSpec) ([]ids.ID, error)
	// Transform chain into elastic chain
	TransformChain(context.Context, []ElasticChainSpec) ([]ids.ID, []ids.ID, error)
	// Add a validator into an elastic chain
	AddPermissionlessValidators(context.Context, []PermissionlessValidatorSpec) error
	// Remove a validator from a chain
	RemoveChainValidators(context.Context, []RemoveChainValidatorSpec) error
	// Get the elastic chain tx id for the given chain id
	GetElasticChainID(context.Context, ids.ID) (ids.ID, error)
}

Network is an abstraction of an Lux network

type ParticipantsSpec

type ParticipantsSpec struct {
	Participants []string
	ChainConfig  []byte
}

type PermissionlessValidatorSpec

type PermissionlessValidatorSpec struct {
	ChainID       string
	AssetID       string
	NodeName      string
	StakedAmount  uint64
	StartTime     time.Time
	StakeDuration time.Duration
}

type RemoveChainValidatorSpec

type RemoveChainValidatorSpec struct {
	NodeNames []string
	ChainID   string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL