builder

package
v1.12.14 Latest Latest
Warning

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

Go to latest
Published: May 23, 2026 License: BSD-3-Clause Imports: 26 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: {"protocol"}, // upstream constant still PlatformVMID; alias is "protocol"
    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 are the default aliases for the P-Chain — the
	// protocol chain that holds the validator set, chain registry,
	// and ordering. Served by ProtocolVM (formerly PlatformVM).
	PChainAliases = []string{"P", "protocol"}
	// XChainAliases are the default aliases for the X-Chain
	XChainAliases = []string{"X", "xvm"}
	// CChainAliases are the default aliases for the C-Chain
	CChainAliases = []string{"C", "evm"}
	// DChainAliases are the default aliases for the D-Chain (DEX)
	DChainAliases = []string{"D", "dex", "dexvm"}
	// QChainAliases are the default aliases for the Q-Chain (Quantum)
	QChainAliases = []string{"Q", "quantum", "quantumvm"}
	// AChainAliases are the default aliases for the A-Chain (AI)
	AChainAliases = []string{"A", "ai", "aivm"}
	// BChainAliases are the default aliases for the B-Chain (Bridge)
	BChainAliases = []string{"B", "bridge", "bridgevm"}
	// TChainAliases are the default aliases for the T-Chain (Threshold-FHE).
	// "F" / "fhe" alias the threshold-FHE chain since this is the
	// encrypted-compute chain in conceptual letter-chain taxonomy
	// (LP-134 / "F-Chain" in user-facing docs). The on-disk shard
	// stays tchain.json — letter is decomplected from product name.
	TChainAliases = []string{"T", "threshold", "thresholdvm", "F", "fhe", "fhevm"}
	// ZChainAliases are the default aliases for the Z-Chain (ZK)
	ZChainAliases = []string{"Z", "zk", "zkvm"}
	// GChainAliases are the default aliases for the G-Chain (Graph)
	GChainAliases = []string{"G", "graph", "graphvm"}
	// KChainAliases are the default aliases for the K-Chain (KMS / MPC).
	// "M" / "mpc" alias the KMS chain since this is the MPC-topology
	// chain in conceptual letter-chain taxonomy (LP-134 / "M-Chain"
	// in user-facing docs). The on-disk shard stays kchain.json.
	KChainAliases = []string{"K", "kms", "kmsvm", "M", "mpc", "mpcvm"}

	// VMAliases are the default aliases for VMs
	VMAliases = map[ids.ID][]string{
		constants.PlatformVMID:  {"protocol"},
		constants.XVMID:         {"xvm"},
		constants.EVMID:         {"evm"},
		constants.DexVMID:       {"dexvm", "dex"},
		constants.QuantumVMID:   {"quantumvm", "quantum"},
		constants.AIVMID:        {"aivm", "ai"},
		constants.BridgeVMID:    {"bridgevm", "bridge"},
		constants.ThresholdVMID: {"thresholdvm", "threshold"},
		constants.ZKVMID:        {"zkvm", "zk"},
		constants.GraphVMID:     {"graphvm", "graph"},
		constants.KeyVMID:       {"kmsvm", "kms"},
		secp256k1fx.ID:          {"secp256k1fx"},
		nftfx.ID:                {"nftfx"},
		propertyfx.ID:           {"propertyfx"},
	}
)
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

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 ForDevMode

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. The shard is a small JSON asset descriptor:

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

When present, the builder constructs an XVM genesis whose primary asset is that descriptor (with initial holders sourced from config.Allocations) and emits a CreateChainTx for the X-Chain. xAssetID returned to the caller is the X-Chain primary asset ID (sha256 over xvmGenesisBytes) — the same ID P-Chain stake UTXOs are denominated in.

When absent, no XVM genesis is built, no X-Chain CreateChainTx is emitted, and xAssetID is returned as ids.Empty. The primary network then has no native UTXO asset: validator stakes denominated against ids.Empty have no on-chain asset backing, which is the permissioned-set semantics used by L1s whose value capture lives on an L2 chain (Liquid EVM etc.) with its own asset model. Minting a real primary-network asset requires X — there is no other genesis site for it.

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, allowCustomGenesis bool) ([]byte, ids.ID, error)

FromFile loads genesis config from file and builds genesis bytes

func FromFlag

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

FromFlag parses base64-encoded genesis content and builds genesis bytes

func GetConfig

func GetConfig(networkID uint32) *genesiscfg.Config

GetConfig returns the genesis config for the given network ID

func VMGenesis

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

VMGenesis returns the genesis tx for a specific VM

func XAssetID

func XAssetID(xvmGenesisBytes []byte) (ids.ID, error)

XAssetID returns the LUX asset ID from XVM genesis bytes

Types

type Bootstrapper

type Bootstrapper struct {
	ID ids.NodeID
	IP netip.AddrPort
}

Bootstrapper represents a network bootstrap node with parsed types

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

func SampleBootstrappers

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

SampleBootstrappers returns a random sample of bootstrappers for the network

type DevModeConfig

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