Files
genesis/builder
Hanzo AI 8da1cca53b genesis/builder: ZAP-native genesis codec (Wave 2G-Genesis)
Migrates pvmGenesisCodec() and newXVMParserCodecs() off the legacy
linearcodec big-endian wire format onto the ZAP-native zapcodec
little-endian wire format. Aligned with LP-023 ZAP-native activation
(proto/zap_native: ZAPActivationUnix=0 — "ZAP mandatory from genesis"),
forward-only.

Wire-format verdict: BREAK.

ZAP-native bytes are NOT byte-equivalent to legacy linearcodec bytes —
endianness flips for every uint16/uint32/uint64/string-length prefix.
The canonical signature (PVM Genesis with Timestamp=0x0102030405060708,
InitialSupply=0x1112131415161718, Message="z"):

  legacy linearcodec (BE): ... 01 02 03 04 05 06 07 08  11 12 13 14 15 16 17 18 ...
  ZAP-native zapcodec (LE): ... 08 07 06 05 04 03 02 01  18 17 16 15 14 13 12 11 ...

No coordinated network upgrade needed: this is the first ZAP-native
genesis tag, and no production validator was running legacy linearcodec
in the post-LP-023 fleet. Mainnet/testnet/devnet/localnet all bootstrap
ZAP-only from genesis.

Code changes:

  - builder.go:
      Drop github.com/luxfi/codec + .../linearcodec direct imports.
      Drop math.MaxInt32 inline construction.
      pvmGenesisCodec()    calls newZapCodecPVMGenesis(CodecVersion)
                           + pchainblock.RegisterTypes(cm).
      newXVMParserCodecs() calls newZapCodecXVMParser(CodecVersion).
      Mirrors sdk/wallet/chain/p/pcodecs.NewPVMGenesisCodec and
      sdk/wallet/chain/x/constants.go::newXVMParserCodecs which already
      moved to proto/zap_codec in Wave 2G-Wallet.

  - zap_codec.go (new):
      Staging shim mirroring proto/zap_codec's public surface
      (NewPVMGenesis, NewXVMParser, Manager.{Marshal,Unmarshal,Size,
      RegisterType,SkipRegistrations}). When Wave 2G-Wallet lands and
      tags github.com/luxfi/proto/zap_codec, this file deletes and the
      two helpers in builder.go swap to that import — mechanical, no
      behavioural change because both shim and target wrap the same
      zapcodec.Codec backend.

  - wire_test.go (new):
      TestWire_PVMGenesisRoundtrip      — bytes-out, parse-back, re-marshal stable
      TestWire_PVMGenesisVersion        — LE codec-version prefix
      TestWire_PVMGenesisDeterministic  — same Config → same bytes + UTXOAssetID
      TestWire_XVMGenesisRoundtrip      — XVM ParserCodecs construction smoke
      TestWire_XVMGenesisDeterministic  — UTXOAssetID stability across builds
      TestWire_HexSignature_PVMGenesis  — mainnet 32-byte prefix tripwire
      TestWire_FormatBreak_Documented   — pinned hex wire-format signature

  - go.mod:
      luxfi/codec  v1.1.4 (indirect) → v1.1.5 (direct: zapcodec backend)
      luxfi/accel  v1.1.4 (indirect) → v1.1.8 (transitive)

Constraint-compliance:

  - NO github.com/luxfi/codec imports in builder.go (verified by grep).
  - NO snow/avalanche/subnet naming.
  - All builder tests pass (go test ./...).
  - All parent genesis + cmd modules build clean.
  - Race detector clean.

TODO (wave-2g-wallet): once luxfi/proto tags include the zap_codec
subpackage, swap zap_codec.go's shim for the canonical
github.com/luxfi/proto/zap_codec import in builder.go and delete the
shim file.
2026-06-06 04:58:12 -07:00
..

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.