env: drop LUX_ prefix from env vars (noise) (#1)

Renames LUX_-prefixed env vars to canonical, non-noisy forms:

- LUX_MNEMONIC          dropped from getMnemonicEnv() lookup chain.
                         Priority is now MNEMONIC > LIGHT_MNEMONIC.
                         All callers, doc comments, and test
                         t.Setenv("LUX_MNEMONIC", "") clears removed.
- LUX_NETWORK_ID        -> NETWORK_ID
- LUX_GENESIS_DIR       -> GENESIS_DIR
- LUX_KEYS_DIR          -> KEYS_DIR  (doc fix; code already used KEYS_DIR)
- LUX_BOOTSTRAPPERS_FILE-> BOOTSTRAPPERS_FILE
- LUX_PCHAIN_ALLOCS     -> PCHAIN_ALLOCS
- LUX_PCHAIN_ALLOCS_FILE-> PCHAIN_ALLOCS_FILE

Doc string mentions of past-but-still-supported `LUX_X` env var names
("set MNEMONIC or LUX_MNEMONIC env var") are also dropped — the env
var is just MNEMONIC now.

LUX_DISABLE_CCHAIN / LUX_CCHAIN_GENESIS_FILE history left in LLM.md
(historical changelog table) and chain_shards_test.go (comment
explicitly documenting the data-driven replacement contract). These
are documenting past behavior, per task convention for historical
references.

BREAKING: external callers/operators must update env var names. Per
CLAUDE.md no-backwards-compatibility rule, the old forms are removed.
This commit is contained in:
Hanzo Dev
2026-05-15 16:10:32 -07:00
committed by GitHub
parent 9561b05f84
commit 25610026e3
9 changed files with 33 additions and 42 deletions
+3 -3
View File
@@ -10,16 +10,16 @@ import (
)
func main() {
// Priority: MNEMONIC > LUX_MNEMONIC > LIGHT_MNEMONIC
// Priority: MNEMONIC > LIGHT_MNEMONIC
mnemonic := ""
for _, env := range []string{"MNEMONIC", "LUX_MNEMONIC", "LIGHT_MNEMONIC"} {
for _, env := range []string{"MNEMONIC", "LIGHT_MNEMONIC"} {
if v := os.Getenv(env); v != "" {
mnemonic = v
break
}
}
if mnemonic == "" {
fmt.Println("mnemonic not set (set LIGHT_MNEMONIC, MNEMONIC, or LUX_MNEMONIC)")
fmt.Println("mnemonic not set (set MNEMONIC or LIGHT_MNEMONIC)")
os.Exit(1)
}
+1 -1
View File
@@ -129,7 +129,7 @@ func main() {
fmt.Fprintln(os.Stderr, "usage: derive100 <hrp> <rpc> <mnemonic-env>")
fmt.Fprintln(os.Stderr, " hrp: test|lux|dev|local")
fmt.Fprintln(os.Stderr, " rpc: http://24.199.71.151:9650")
fmt.Fprintln(os.Stderr, " mnemonic-env: LUX_MNEMONIC|LIGHT_MNEMONIC")
fmt.Fprintln(os.Stderr, " mnemonic-env: MNEMONIC|LIGHT_MNEMONIC")
os.Exit(1)
}
hrp := os.Args[1]
+2 -2
View File
@@ -117,8 +117,8 @@ Environment Variables:
KEYS_DIR Directory containing node keys
MNEMONIC BIP39 mnemonic for key derivation
PRIVATE_KEY Single private key (hex)
LUX_GENESIS_DIR Directory containing genesis component files
LUX_NETWORK_ID Network ID
GENESIS_DIR Directory containing genesis component files
NETWORK_ID Network ID
Examples:
# Generate local genesis from keys in ~/.lux/keys
+8 -8
View File
@@ -7,8 +7,8 @@
//
// Dynamic P-Chain Allocations:
// P-Chain allocations can be specified dynamically at runtime via:
// - LUX_PCHAIN_ALLOCS: JSON string of allocations
// - LUX_PCHAIN_ALLOCS_FILE: Path to allocations JSON file
// - PCHAIN_ALLOCS: JSON string of allocations
// - PCHAIN_ALLOCS_FILE: Path to allocations JSON file
// - ~/.lux/genesis/{network}/pchain.json: Standard override location
//
// The C-Chain genesis remains embedded and immutable.
@@ -72,8 +72,8 @@ var embeddedGenesis embed.FS
// GetGenesis returns the genesis JSON bytes for a network ID.
// It supports dynamic P-Chain allocations via environment variables or files:
// - LUX_PCHAIN_ALLOCS: JSON string of allocations
// - LUX_PCHAIN_ALLOCS_FILE: Path to allocations JSON file
// - PCHAIN_ALLOCS: JSON string of allocations
// - PCHAIN_ALLOCS_FILE: Path to allocations JSON file
// - ~/.lux/genesis/{network}/pchain.json: Standard override location
//
// C-Chain genesis remains embedded and immutable.
@@ -117,16 +117,16 @@ func GetGenesisWithAllocations(networkID uint32, allocations []genesis.Allocatio
// loadDynamicPChainAllocations loads P-Chain allocations from environment or files.
func loadDynamicPChainAllocations(networkName string) *genesis.PChainConfig {
// First, check LUX_PCHAIN_ALLOCS environment variable (JSON string)
if allocsJSON := os.Getenv("LUX_PCHAIN_ALLOCS"); allocsJSON != "" {
// First, check PCHAIN_ALLOCS environment variable (JSON string)
if allocsJSON := os.Getenv("PCHAIN_ALLOCS"); allocsJSON != "" {
var pchain genesis.PChainConfig
if err := json.Unmarshal([]byte(allocsJSON), &pchain); err == nil {
return &pchain
}
}
// Second, check LUX_PCHAIN_ALLOCS_FILE environment variable
if allocsFile := os.Getenv("LUX_PCHAIN_ALLOCS_FILE"); allocsFile != "" {
// Second, check PCHAIN_ALLOCS_FILE environment variable
if allocsFile := os.Getenv("PCHAIN_ALLOCS_FILE"); allocsFile != "" {
data, err := os.ReadFile(allocsFile)
if err == nil {
var pchain genesis.PChainConfig
+5 -5
View File
@@ -191,12 +191,12 @@ func GetConfigFromDir(dir string) (*Config, error) {
// GetConfigFromEnv builds genesis config using environment variables
// Environment variables:
// - LUX_NETWORK_ID: network ID (default: custom)
// - LUX_GENESIS_DIR: directory containing genesis files
// - LUX_KEYS_DIR: directory containing node keys (default: ~/.lux/keys)
// - NETWORK_ID: network ID (default: custom)
// - GENESIS_DIR: directory containing genesis files
// - KEYS_DIR: directory containing node keys (default: ~/.lux/keys)
func GetConfigFromEnv() (*Config, error) {
networkID := uint32(constants.LocalID)
if envID := os.Getenv("LUX_NETWORK_ID"); envID != "" {
if envID := os.Getenv("NETWORK_ID"); envID != "" {
var id uint32
if _, err := fmt.Sscanf(envID, "%d", &id); err == nil {
networkID = id
@@ -204,7 +204,7 @@ func GetConfigFromEnv() (*Config, error) {
}
// Get genesis directory from env
genesisDir := os.Getenv("LUX_GENESIS_DIR")
genesisDir := os.Getenv("GENESIS_DIR")
if genesisDir != "" {
config, err := GetConfigFromDir(genesisDir)
if err == nil {
-1
View File
@@ -212,7 +212,6 @@ func TestLoadKeysFromMnemonic_BranchesIndependent(t *testing.T) {
// both an ML-DSA-65 pubkey (1952 B) and a populated secp256k1 ETHAddr.
func TestLoadKeysFromMnemonicEnvForNetwork_Integration(t *testing.T) {
t.Setenv("MNEMONIC", "")
t.Setenv("LUX_MNEMONIC", "")
t.Setenv("LIGHT_MNEMONIC", hdTestMnemonic)
const n = 3
+13 -13
View File
@@ -576,7 +576,7 @@ func mldsaKeygenFromChildSeed(childSeed []byte) ([]byte, error) {
}
// LoadKeysFromMnemonicEnv loads keys from mnemonic env vars.
// Priority: MNEMONIC > LUX_MNEMONIC > LIGHT_MNEMONIC.
// Priority: MNEMONIC > LIGHT_MNEMONIC.
//
// nid is the Hanzo mesh network id baked into the hardened derivation
// path. Callers that already know the network id MUST use
@@ -585,7 +585,7 @@ func mldsaKeygenFromChildSeed(childSeed []byte) ([]byte, error) {
func LoadKeysFromMnemonicEnv(nid uint32, numAccounts int) ([]KeyInfo, error) {
mnemonic := getMnemonicEnv()
if mnemonic == "" {
return nil, fmt.Errorf("mnemonic not set (set MNEMONIC, LUX_MNEMONIC, or LIGHT_MNEMONIC)")
return nil, fmt.Errorf("mnemonic not set (set MNEMONIC or LIGHT_MNEMONIC)")
}
return LoadKeysFromMnemonic(mnemonic, nid, numAccounts)
@@ -658,18 +658,18 @@ func genesisMessage(networkID uint32) string {
}
// getMnemonicEnv returns the mnemonic from environment variables.
// Priority: MNEMONIC > LUX_MNEMONIC > LIGHT_MNEMONIC
// Priority: MNEMONIC > LIGHT_MNEMONIC
//
// LIGHT_MNEMONIC is the publicly-known dev seed. Anyone in the world can
// derive its first 200 child keys; the auto-fund pre-allocation in
// HIP-0077 §"Auto-funding the first 200 devices" is *only* meant for
// network IDs >= 1337 (dev / primary local mesh). Production networks
// MUST set MNEMONIC (preferred) or LUX_MNEMONIC.
// MUST set MNEMONIC.
//
// Use IsLightMnemonic and RefuseLightMnemonicOnProduction to enforce that
// rule wherever a key is loaded for a known network ID.
func getMnemonicEnv() string {
for _, env := range []string{"MNEMONIC", "LUX_MNEMONIC", "LIGHT_MNEMONIC"} {
for _, env := range []string{"MNEMONIC", "LIGHT_MNEMONIC"} {
if v := os.Getenv(env); v != "" {
return v
}
@@ -790,7 +790,7 @@ func RefuseLightMnemonicOnProduction(networkID uint32) error {
"refusing to derive keys: a publicly-known mnemonic is set on production "+
"network %d (mainnet/testnet/<1337). Public mnemonics (LIGHT_MNEMONIC, "+
"BIP-39 test vectors, Hardhat/Trezor demos) are deterministic — anyone "+
"can derive every child key. Set MNEMONIC or LUX_MNEMONIC env var with "+
"can derive every child key. Set MNEMONIC env var with "+
"a private hardware-RNG mnemonic loaded from KMS, or run on a dev "+
"network ID (>= 1337)", networkID,
)
@@ -824,15 +824,15 @@ func subtleConstantTimeEqual(a, b []byte) bool {
return v == 0
}
// BuildWalletAllocations derives wallet keys from the MNEMONIC /
// LUX_MNEMONIC env var on the per-network branch 1' hardened path
// BuildWalletAllocations derives wallet keys from the MNEMONIC env var
// on the per-network branch 1' hardened path
// (m/44'/9000'/nid'/1'/i') and returns free (no vesting) spending
// allocations for each key. Each allocation has both ETHAddr and
// LUXAddr (StakingAddr).
func BuildWalletAllocations(nid uint32, numKeys int, amountPerKey uint64) ([]Allocation, error) {
mnemonic := getMnemonicEnv()
if mnemonic == "" {
return nil, fmt.Errorf("wallet allocations require MNEMONIC or LUX_MNEMONIC env var")
return nil, fmt.Errorf("wallet allocations require MNEMONIC env var")
}
if !bip39.IsMnemonicValid(mnemonic) {
return nil, fmt.Errorf("invalid mnemonic for wallet key derivation")
@@ -966,7 +966,7 @@ func BuildBIP44WalletAllocations(networkID uint32, numKeys int, amountPerKey uin
_ = networkID // see comment above
mnemonic := getMnemonicEnv()
if mnemonic == "" {
return nil, fmt.Errorf("wallet allocations require MNEMONIC or LUX_MNEMONIC env var")
return nil, fmt.Errorf("wallet allocations require MNEMONIC env var")
}
if !bip39.IsMnemonicValid(mnemonic) {
return nil, fmt.Errorf("invalid mnemonic for wallet key derivation")
@@ -1032,7 +1032,7 @@ func BuildBIP44WalletAllocations(networkID uint32, numKeys int, amountPerKey uin
}
// BuildConfigFromEnv builds genesis config from environment variables
// Checks in order: KEYS_DIR, mnemonic (MNEMONIC/LUX_MNEMONIC/LIGHT_MNEMONIC), PRIVATE_KEY
// Checks in order: KEYS_DIR, mnemonic (MNEMONIC/LIGHT_MNEMONIC), PRIVATE_KEY
//
// Architecture:
// - X-Chain: 100 accounts × 500M LUX each, FREE
@@ -1058,7 +1058,7 @@ func BuildConfigFromEnv(networkID uint32, numValidators int, allocationPerKey ui
// m/44'/9000'/0'/0/i (the same path the genesis CLI's -bip44-wallet-keys
// flag uses, and the same path the derive100 / luxfi wallet UIs use).
// This is what every user-facing tool that scans the chain for funded
// addresses will expect — derive100 against $LUX_MNEMONIC and the
// addresses will expect — derive100 against $MNEMONIC and the
// addresses here must match byte-for-byte.
//
// NOTE: this is intentionally a SEPARATE concern from
@@ -1254,7 +1254,7 @@ func buildConfigFromKeyInfos(networkID uint32, validatorKeys []KeyInfo, allKeys
func BuildWalletKeyHex(nid uint32, index int) (string, error) {
mnemonic := getMnemonicEnv()
if mnemonic == "" {
return "", fmt.Errorf("MNEMONIC or LUX_MNEMONIC env var required")
return "", fmt.Errorf("MNEMONIC env var required")
}
if !bip39.IsMnemonicValid(mnemonic) {
return "", fmt.Errorf("invalid mnemonic")
-8
View File
@@ -97,7 +97,6 @@ func TestIsKnownPublicMnemonic(t *testing.T) {
func TestRefuseLightMnemonicOnProduction(t *testing.T) {
// 1. No mnemonic set: not our problem at this layer.
t.Setenv("MNEMONIC", "")
t.Setenv("LUX_MNEMONIC", "")
t.Setenv("LIGHT_MNEMONIC", "")
if err := RefuseLightMnemonicOnProduction(constants.MainnetID); err != nil {
t.Fatalf("no-mnemonic case: unexpected error: %v", err)
@@ -140,12 +139,6 @@ func TestRefuseLightMnemonicOnProduction(t *testing.T) {
t.Fatalf("real mnemonic on mainnet: unexpected error: %v", err)
}
// 8. Real LUX_MNEMONIC on mainnet: allowed.
t.Setenv("MNEMONIC", "")
t.Setenv("LUX_MNEMONIC", realMnemonic)
if err := RefuseLightMnemonicOnProduction(constants.MainnetID); err != nil {
t.Fatalf("real LUX_MNEMONIC on mainnet: unexpected error: %v", err)
}
}
// TestLoadKeysFromMnemonicEnvForNetwork — F30 fix. The new entry point
@@ -156,7 +149,6 @@ func TestRefuseLightMnemonicOnProduction(t *testing.T) {
func TestLoadKeysFromMnemonicEnvForNetwork(t *testing.T) {
// Setup: LIGHT_MNEMONIC on mainnet should refuse derivation.
t.Setenv("MNEMONIC", "")
t.Setenv("LUX_MNEMONIC", "")
t.Setenv("LIGHT_MNEMONIC", LightMnemonic)
_, err := LoadKeysFromMnemonicEnvForNetwork(constants.MainnetID, 1)
if err == nil {
+1 -1
View File
@@ -233,7 +233,7 @@ func GetBootstrappers(networkID uint32) []Bootstrapper {
networkName = "devnet"
default:
// For custom/local networks, check environment variable for bootstrappers path
if envPath := os.Getenv("LUX_BOOTSTRAPPERS_FILE"); envPath != "" {
if envPath := os.Getenv("BOOTSTRAPPERS_FILE"); envPath != "" {
data, err := os.ReadFile(envPath)
if err == nil {
var bootstrappers []Bootstrapper