builder

package
v1.27.14 Latest Latest
Warning

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

Go to latest
Published: May 24, 2026 License: BSD-3-Clause Imports: 31 Imported by: 0

README

Genesis Builder

This package provides genesis building functionality for Lux networks. It depends on node types and is responsible for converting genesis configuration into actual genesis bytes.

Architecture

The genesis builder bridges the gap between the decoupled github.com/luxfi/genesis package (which provides JSON-based configuration) and the node's internal types:

github.com/luxfi/genesis          →  github.com/luxfi/node/genesis/builder
(JSON config, no node deps)           (Type conversion, genesis building)

Types

StakingConfig
type StakingConfig struct {
    UptimeRequirement float64
    MinValidatorStake uint64
    MaxValidatorStake uint64
    MinDelegatorStake uint64
    MinDelegationFee  uint32
    MinStakeDuration  time.Duration  // Converted from uint64 seconds
    MaxStakeDuration  time.Duration  // Converted from uint64 seconds
    RewardConfig      reward.Config  // Uses platformvm/reward.Config

    // BLS key information for genesis replay
    NodeID               string
    BLSPublicKey         []byte
    BLSProofOfPossession []byte
}
TxFeeConfig
type TxFeeConfig struct {
    TxFee              uint64
    CreateAssetTxFee   uint64
    DynamicFeeConfig   gas.Config  // From vms/components/gas
    ValidatorFeeConfig fee.Config  // From vms/platformvm/validators/fee
}
Bootstrapper
type Bootstrapper struct {
    ID ids.NodeID      // Parsed from string
    IP netip.AddrPort  // Parsed from string
}

Functions

Configuration Retrieval
// Get staking config with time.Duration types
func GetStakingConfig(networkID uint32) StakingConfig

// Get tx fee config with gas.Config and fee.Config
func GetTxFeeConfig(networkID uint32) TxFeeConfig

// Get parsed bootstrappers
func GetBootstrappers(networkID uint32) ([]Bootstrapper, error)

// Sample random bootstrappers
func SampleBootstrappers(networkID uint32, count int) ([]Bootstrapper, error)

// Get genesis config (delegates to genesis package)
func GetConfig(networkID uint32) *genesiscfg.Config
Genesis Building
// Build genesis bytes from config
func FromConfig(config *genesiscfg.Config) ([]byte, ids.ID, error)

// Build genesis from file
func FromFile(networkID uint32, filepath string, stakingCfg *StakingConfig) ([]byte, ids.ID, error)

// Build genesis from base64 content
func FromFlag(networkID uint32, genesisContent string, stakingCfg *StakingConfig) ([]byte, ids.ID, error)

// Build genesis for database replay mode
func FromDatabase(networkID uint32, dbPath string, dbType string, stakingCfg *StakingConfig) ([]byte, ids.ID, error)
Helpers
// Get VM genesis transaction
func VMGenesis(genesisBytes []byte, vmID ids.ID) (*pchaintxs.Tx, error)

// Get chain and API aliases
func Aliases(genesisBytes []byte) (map[string][]string, map[ids.ID][]string, error)

// Get LUX asset ID from XVM genesis
func XAssetID(xvmGenesisBytes []byte) (ids.ID, error)

Default Fee Configurations

The package provides default fee configurations for each network:

// Dynamic fee configs
var MainnetDynamicFeeConfig gas.Config
var TestnetDynamicFeeConfig gas.Config
var LocalDynamicFeeConfig   gas.Config

// Validator fee configs
var MainnetValidatorFeeConfig fee.Config
var TestnetValidatorFeeConfig fee.Config
var LocalValidatorFeeConfig   fee.Config

VM Aliases

var VMAliases = map[ids.ID][]string{
    constants.PlatformVMID: {"platform"},
    constants.XVMID:        {"xvm"},
    constants.EVMID:        {"evm"},
    secp256k1fx.ID:         {"secp256k1fx"},
    nftfx.ID:               {"nftfx"},
    propertyfx.ID:          {"propertyfx"},
}

Usage Example

package main

import (
    "github.com/luxfi/node/genesis/builder"
    "github.com/luxfi/constants"
)

func main() {
    // Get network configuration
    stakingCfg := builder.GetStakingConfig(constants.MainnetID)
    txFeeCfg := builder.GetTxFeeConfig(constants.MainnetID)

    // Get bootstrappers
    bootstrappers, err := builder.SampleBootstrappers(constants.MainnetID, 5)
    if err != nil {
        panic(err)
    }

    // Build genesis bytes
    config := builder.GetConfig(constants.MainnetID)
    genesisBytes, xAssetID, err := builder.FromConfig(config)
    if err != nil {
        panic(err)
    }

    // Get chain aliases
    apiAliases, chainAliases, err := builder.Aliases(genesisBytes)
    if err != nil {
        panic(err)
    }
}

Migration from genesis package

If you were using github.com/luxfi/genesis v1.2.x for building genesis bytes, migrate to this package:

Old (genesis v1.2.x) New (builder)
genesis.FromConfig(...) builder.FromConfig(...)
genesis.FromFile(...) builder.FromFile(...)
genesis.FromFlag(...) builder.FromFlag(...)
genesis.VMGenesis(...) builder.VMGenesis(...)
genesis.Aliases(...) builder.Aliases(...)
genesis.VMAliases builder.VMAliases
genesis.GetStakingConfig(...) builder.GetStakingConfig(...)
genesis.GetTxFeeConfig(...) builder.GetTxFeeConfig(...)

For JSON-based configuration only (without building), continue using github.com/luxfi/genesis v1.3.x.

License

Copyright (C) 2019-2025, Lux Industries, Inc. All rights reserved. See the file LICENSE for licensing terms.

Documentation

Overview

Package builder provides genesis byte generation for Lux networks. This package depends on node types and is responsible for building the actual genesis state from genesis config.

Index

Constants

This section is empty.

Variables

View Source
var (
	PChainAliases = AliasesFor("P")
	XChainAliases = AliasesFor("X")
	CChainAliases = AliasesFor("C")
	DChainAliases = AliasesFor("D")
	QChainAliases = AliasesFor("Q")
	AChainAliases = AliasesFor("A")
	BChainAliases = AliasesFor("B")
	TChainAliases = AliasesFor("T")
	ZChainAliases = AliasesFor("Z")
	GChainAliases = AliasesFor("G")
	KChainAliases = AliasesFor("K")

	// Network-specific genesis messages (Latin for mainnet, descriptive for others)
	// Mainnet: "Lux et Libertas" - Light and Liberty
	MainnetChainGenesis = `{"version":1,"message":"Lux et Libertas"}`
	// Testnet: "Per Aspera ad Astra" - Through hardships to the stars
	TestnetChainGenesis = `{"version":1,"message":"Per Aspera ad Astra"}`
	// Devnet: "In Silico Veritas" - Truth in silicon
	DevnetChainGenesis = `{"version":1,"message":"In Silico Veritas"}`
	// Local/Custom: "Carpe Diem" - Seize the day
	LocalChainGenesis = `{"version":1,"message":"Carpe Diem"}`

	// VMAliases is the default (VMID -> aliases) map for the node's VM
	// manager. Chain entries are derived from Registry; fx entries are
	// the static feature-extension aliases (secp256k1fx, nftfx, ...).
	VMAliases = VMAliasesMap()
)

Chain alias vars are derived from the single source of truth (Registry in registry.go). Rebranding a chain — adding/removing aliases or renaming the letter — edits one row in Registry; these vars and the VMAliases map re-derive at package init.

View Source
var (
	MainnetDynamicFeeConfig = gas.Config{
		Weights: gas.Dimensions{
			gas.Bandwidth: 1,
			gas.DBRead:    1,
			gas.DBWrite:   1,
			gas.Compute:   1,
		},
		MaxCapacity:              1_000_000,
		MaxPerSecond:             100_000,
		TargetPerSecond:          50_000,
		MinPrice:                 1,
		ExcessConversionConstant: 5_000,
	}

	TestnetDynamicFeeConfig = gas.Config{
		Weights: gas.Dimensions{
			gas.Bandwidth: 1,
			gas.DBRead:    1,
			gas.DBWrite:   1,
			gas.Compute:   1,
		},
		MaxCapacity:              1_000_000,
		MaxPerSecond:             100_000,
		TargetPerSecond:          50_000,
		MinPrice:                 1,
		ExcessConversionConstant: 5_000,
	}

	LocalDynamicFeeConfig = gas.Config{
		Weights: gas.Dimensions{
			gas.Bandwidth: 1,
			gas.DBRead:    1,
			gas.DBWrite:   1,
			gas.Compute:   1,
		},
		MaxCapacity:              1_000_000,
		MaxPerSecond:             100_000,
		TargetPerSecond:          50_000,
		MinPrice:                 1,
		ExcessConversionConstant: 5_000,
	}

	MainnetValidatorFeeConfig = fee.Config{
		Capacity:                 20_000,
		Target:                   10_000,
		MinPrice:                 512,
		ExcessConversionConstant: 1_587,
	}

	TestnetValidatorFeeConfig = fee.Config{
		Capacity:                 20_000,
		Target:                   10_000,
		MinPrice:                 512,
		ExcessConversionConstant: 1_587,
	}

	LocalValidatorFeeConfig = fee.Config{
		Capacity:                 20_000,
		Target:                   10_000,
		MinPrice:                 512,
		ExcessConversionConstant: 1_587,
	}
)

Default dynamic fee parameters

View Source
var Registry = []ChainSpec{
	{Letter: "P", VMID: constants.PlatformVMID, Aliases: []string{"platform"}, Name: "P-Chain"},
	{Letter: "X", VMID: constants.XVMID, Aliases: []string{"xvm"}, Name: "X-Chain"},
	{Letter: "C", VMID: constants.EVMID, Aliases: []string{"evm"}, Name: "C-Chain"},
	{Letter: "D", VMID: constants.DexVMID, Aliases: []string{"dex", "dexvm"}, Name: "D-Chain"},
	{Letter: "Q", VMID: constants.QuantumVMID, Aliases: []string{"quantum", "quantumvm", "pq"}, Name: "Q-Chain"},
	{Letter: "A", VMID: constants.AIVMID, Aliases: []string{"attest", "ai", "aivm"}, Name: "A-Chain"},
	{Letter: "B", VMID: constants.BridgeVMID, Aliases: []string{"bridge", "bridgevm"}, Name: "B-Chain"},
	{Letter: "T", VMID: constants.ThresholdVMID, Aliases: []string{"threshold", "thresholdvm", "mpc"}, Name: "T-Chain"},
	{Letter: "Z", VMID: constants.ZKVMID, Aliases: []string{"zk", "zkvm"}, Name: "Z-Chain"},
	{Letter: "G", VMID: constants.GraphVMID, Aliases: []string{"graph", "graphvm", "dgraph"}, Name: "G-Chain"},
	{Letter: "K", VMID: constants.KeyVMID, Aliases: []string{"key", "keyvm"}, Name: "K-Chain"},
}

Registry is the canonical list of primary-network chains.

Order is fixed and matches the optIn order in FromConfig — reordering shifts the P-Chain genesis byte layout for chains that share a presence/absence shape, so this slice is append-only.

P-Chain is implicit (the platform genesis itself); listed here so the alias machinery has a row for it, but FromConfig does not iterate this slice to emit CreateChainTx for P.

Functions

func Aliases

func Aliases(genesisBytes []byte) (map[string][]string, map[ids.ID][]string, error)

Aliases returns the default aliases for chains and APIs

func AliasesFor added in v1.27.14

func AliasesFor(letter string) []string

AliasesFor returns the full chain alias list for a chain by letter. The letter itself is prepended, e.g. AliasesFor("D") -> ["D", "dex", "dexvm"]. Returns nil for unknown letters.

func ForDevMode added in v1.22.67

func ForDevMode(cfg DevModeConfig, stakingCfg *StakingConfig) ([]byte, ids.ID, error)

ForDevMode creates a genesis configuration suitable for single-node development mode. It creates a single validator with far-future stake time and funds the treasury address.

func FromConfig

func FromConfig(config *genesiscfg.Config) ([]byte, ids.ID, error)

FromConfig builds genesis bytes from a config.

X-Chain is opt-in via config.XChainGenesis (a small JSON descriptor like

{"symbol":"LUX","name":"Lux","denomination":9}

). When set, the builder constructs an XVM genesis whose primary asset is that descriptor (initial holders sourced from config.Allocations) and emits an X-Chain entry in the primary-network CreateChainTx set. When empty, no XVM genesis is built and X-Chain is omitted from the chain set — the path used by P-only L2s whose value capture lives on a downstream EVM (Liquid EVM etc.).

The LUX asset ID returned is always the network-wide constant (constants.UTXO_ASSET_ID), independent of whether X-Chain is baked. This is what decouples the asset from any specific chain's genesis bytes — P-Chain stake/UTXO references stay byte-stable across both shapes of primary network.

func FromDatabase

func FromDatabase(networkID uint32, dbPath string, dbType string, stakingCfg *StakingConfig) ([]byte, ids.ID, error)

FromDatabase returns genesis data for database replay mode

func FromFile

func FromFile(networkID uint32, filepath string, stakingCfg *StakingConfig) ([]byte, ids.ID, error)

FromFile loads genesis config from file and builds genesis bytes. Caller owns the choice — if a genesis file is set, we use it. No "is this networkID standard?" guard, no allow-flag. Operator-owned chainset.

func FromFlag

func FromFlag(networkID uint32, genesisContent string, stakingCfg *StakingConfig) ([]byte, ids.ID, error)

FromFlag parses base64-encoded genesis content and builds genesis bytes. Same contract as FromFile — caller owns the override.

func GetConfig

func GetConfig(networkID uint32) *genesiscfg.Config

GetConfig returns the genesis config for the given network ID

func VMAliasesMap added in v1.27.14

func VMAliasesMap() map[ids.ID][]string

VMAliasesMap returns the union of chain VM aliases (from Registry) and the static fx VM aliases (from fxVMAliases). This is the map the node's VM manager consumes via builder.VMAliases.

The values are fresh slice copies so callers cannot mutate Registry rows through the returned map.

func VMGenesis

func VMGenesis(genesisBytes []byte, vmID ids.ID) (*pchaintxs.Tx, error)

VMGenesis returns the genesis tx for a specific VM

func XAssetIDFromGenesisBytes added in v1.27.14

func XAssetIDFromGenesisBytes(genesisBytes []byte) (ids.ID, bool, error)

XAssetIDFromGenesisBytes returns the X-Chain native asset ID encoded in a platform-genesis blob. It parses the platform genesis, finds the X-Chain CreateChainTx (vmID == constants.XVMID), then decodes that chain's embedded XVM genesis bytes to recover the runtime asset ID (the same value vm.initGenesis assigns to the first GenesisAsset).

Returns (ids.Empty, false, nil) when the platform genesis contains no X-Chain (P-only mode) — callers fall back to whatever default they prefer (e.g. constants.UTXOAssetIDFor(networkID)).

Returns a non-nil error when the platform genesis is unparseable or the X-Chain genesis bytes embedded inside it are malformed; both are unrecoverable on a primary-network bootstrap.

Used by config.getGenesisData when it loads genesis via the cached / raw paths that skip FromConfig — those paths historically returned constants.UTXOAssetIDFor(networkID), but on sovereign L1s that value disagrees with what's actually in the genesis bytes. Wiring this helper through getGenesisData means the node always reports the genesis-derived asset ID via platform.getStakingAssetID regardless of which load path was taken.

Types

type Bootstrapper

type Bootstrapper struct {
	ID       ids.NodeID
	Endpoint endpoints.Endpoint
}

Bootstrapper represents a network bootstrap node with parsed types. Supports both IP addresses and hostnames for the endpoint.

func GetBootstrappers

func GetBootstrappers(networkID uint32) ([]Bootstrapper, error)

GetBootstrappers returns parsed bootstrappers for the network

func ParseBootstrapper

func ParseBootstrapper(b genesiscfg.Bootstrapper) (Bootstrapper, error)

ParseBootstrapper converts a genesis config bootstrapper to a parsed Bootstrapper. The IP field can be either an IP:port (e.g., "1.2.3.4:9631") or a hostname:port (e.g., "luxd-0.luxd-headless.lux-mainnet.svc.cluster.local:9631").

func SampleBootstrappers

func SampleBootstrappers(networkID uint32, count int) ([]Bootstrapper, error)

SampleBootstrappers returns a random sample of bootstrappers for the network

func (Bootstrapper) IP

IP returns the IP address if this is an IP-based endpoint. For hostname endpoints, this returns an invalid AddrPort. Deprecated: Use Endpoint directly for new code.

type ChainSpec added in v1.27.14

type ChainSpec struct {
	// Letter is the canonical single-character chain code ("P", "X", ...).
	// Used as the first element of the chain alias list and as the
	// bech32 chain prefix.
	Letter string

	// VMID is the VM that runs this chain. The (VMID -> aliases) map
	// VMAliasesMap() is derived from Registry by collecting Aliases
	// for each ChainSpec.
	VMID ids.ID

	// Aliases are the non-letter aliases for this chain. The full
	// chain alias list returned by AliasesFor is [Letter] ++ Aliases.
	// These are also the VM aliases registered with the alias manager.
	Aliases []string

	// Name is the human-readable chain name ("P-Chain", "C-Chain", ...).
	// Embedded into the primary-network CreateChainTx.
	Name string
}

ChainSpec is one row in the primary-network chain registry.

Registry is the single source of truth for: canonical letter, VMID, bech32 chain prefix used in addresses, alias list, and the human-readable name. Rebranding or renaming a chain edits one row; the prior switch-ladders in Aliases() and var blocks of {P,X,C,...}ChainAliases re-derive from this table.

type DevModeConfig added in v1.22.67

type DevModeConfig struct {
	NodeID        ids.NodeID  // The validator node ID
	BLSPublicKey  string      // BLS public key hex
	BLSPopProof   string      // BLS proof of possession hex
	RewardAddress ids.ShortID // Reward/allocation address
	CChainGenesis string      // C-Chain genesis JSON
	StartTime     uint64      // Genesis start time (if 0, uses time.Now())
}

DevModeConfig holds configuration for dev mode genesis

type StakingConfig

type StakingConfig struct {
	UptimeRequirement float64
	MinValidatorStake uint64
	MaxValidatorStake uint64
	MinDelegatorStake uint64
	MinDelegationFee  uint32
	MinStakeDuration  time.Duration
	MaxStakeDuration  time.Duration
	RewardConfig      reward.Config

	// BLS key information for genesis replay
	NodeID               string `json:"nodeID"`
	BLSPublicKey         []byte `json:"blsPublicKey"`
	BLSProofOfPossession []byte `json:"blsProofOfPossession"`
}

StakingConfig is the staking configuration with time.Duration types

func GetStakingConfig

func GetStakingConfig(networkID uint32) StakingConfig

GetStakingConfig returns the staking config with time.Duration types

type TxFeeConfig

type TxFeeConfig struct {
	TxFee              uint64     `json:"txFee"`
	CreateAssetTxFee   uint64     `json:"createAssetTxFee"`
	DynamicFeeConfig   gas.Config `json:"dynamicFeeConfig"`
	ValidatorFeeConfig fee.Config `json:"validatorFeeConfig"`
}

TxFeeConfig contains transaction fee configuration This includes the basic fee config from genesis plus dynamic/validator fees

func GetTxFeeConfig

func GetTxFeeConfig(networkID uint32) TxFeeConfig

GetTxFeeConfig returns the tx fee config

Jump to

Keyboard shortcuts

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