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

Renames LUX_-prefixed env vars to canonical, non-noisy forms across
genesis_config, blockchain, network, examples, tests, genkeys, server:

- LUX_MNEMONIC      -> MNEMONIC
- LUX_PRIVATE_KEY   -> PRIVATE_KEY
- LUX_KEYS_DIR      -> KEYS_DIR
- LUX_BINARY_PATH   -> BINARY_PATH
- LUX_NETWORK_TYPE  -> NETWORK_TYPE  (doc only)
- LUX_GPU_EVM       -> GPU_EVM       (doc only)
- LUX_GPU_WORKER_PID-> GPU_WORKER_PID

Also fixes an obvious infinite-recursion bug in
local/genesis_config.go::getMnemonic() that the previous LUX_MNEMONIC
fallback line had become — the helper now reads MNEMONIC then
LIGHT_MNEMONIC and returns. Without this fix, callers reaching the
fallback would have hung the process.

BREAKING: external callers (CI, dev scripts, 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:26:33 -07:00
committed by GitHub
parent d68dd93faa
commit 729fd49c63
10 changed files with 56 additions and 59 deletions
+3 -3
View File
@@ -509,9 +509,9 @@ lux chain deploy <chain> --network local
| Variable | Description | Example |
|----------|-------------|---------|
| `LUX_NETWORK_TYPE` | Network type for backend | `mainnet` |
| `LUX_MNEMONIC` | HD wallet seed for key derivation | `word1 word2 ...` |
| `LUX_PRIVATE_KEY` | Direct private key (hex) | `0x123...` |
| `NETWORK_TYPE` | Network type for backend | `mainnet` |
| `MNEMONIC` | HD wallet seed for key derivation | `word1 word2 ...` |
| `PRIVATE_KEY` | Direct private key (hex) | `0x123...` |
---
+2 -2
View File
@@ -28,8 +28,8 @@ func main() {
os.Exit(1)
}
// Use LUX_KEYS_DIR if set, otherwise default
keysDir := os.Getenv("LUX_KEYS_DIR")
// Use KEYS_DIR if set, otherwise default
keysDir := os.Getenv("KEYS_DIR")
if keysDir == "" {
home, _ := os.UserHomeDir()
keysDir = filepath.Join(home, ".lux", "keys")
+5 -5
View File
@@ -89,8 +89,8 @@ func createZooGenesis() ([]byte, error) {
func main() {
logger := log.New()
// Check for LUX_BINARY_PATH env var or use default
binaryPath := os.Getenv("LUX_BINARY_PATH")
// Check for BINARY_PATH env var or use default
binaryPath := os.Getenv("BINARY_PATH")
if binaryPath == "" {
home, _ := os.UserHomeDir()
binaryPath = home + "/.lux/bin/luxd/luxd"
@@ -103,10 +103,10 @@ func main() {
}
func run(logger log.Logger, binaryPath string) error {
// Check for LUX_MNEMONIC environment variable
mnemonic := os.Getenv("LUX_MNEMONIC")
// Check for MNEMONIC environment variable
mnemonic := os.Getenv("MNEMONIC")
if mnemonic == "" {
return fmt.Errorf("LUX_MNEMONIC environment variable must be set")
return fmt.Errorf("MNEMONIC environment variable must be set")
}
// Create the network config from mnemonic
+3 -3
View File
@@ -122,7 +122,7 @@ func activateCChainUpgrades(genesisJSON string) (string, error) {
func main() {
logger := log.New()
binaryPath := os.Getenv("LUX_BINARY_PATH")
binaryPath := os.Getenv("BINARY_PATH")
if binaryPath == "" {
home, _ := os.UserHomeDir()
binaryPath = home + "/.lux/bin/luxd/luxd"
@@ -136,9 +136,9 @@ func main() {
}
func run(logger log.Logger, binaryPath string) error {
mnemonic := os.Getenv("LUX_MNEMONIC")
mnemonic := os.Getenv("MNEMONIC")
if mnemonic == "" {
return fmt.Errorf("LUX_MNEMONIC environment variable must be set")
return fmt.Errorf("MNEMONIC environment variable must be set")
}
// Create TESTNET network config (network ID 2)
+8 -8
View File
@@ -1287,13 +1287,13 @@ type wallet struct {
}
// getDefaultKey loads the first key from ~/.lux/keys for wallet operations.
// Priority: LUX_MNEMONIC > LUX_PRIVATE_KEY > disk keys
// Priority: MNEMONIC > PRIVATE_KEY > disk keys
func getDefaultKey() (*secp256k1.PrivateKey, error) {
// If LUX_MNEMONIC is set, derive key using BIP44 path m/44'/60'/0'/0/0 (Ethereum standard)
// If MNEMONIC is set, derive key using BIP44 path m/44'/60'/0'/0/0 (Ethereum standard)
// CRITICAL: This MUST match the derivation path used in genesis allocations
// (keys.DeriveValidatorFromMnemonic uses m/44'/60'/0'/0/{index})
if mnemonic := os.Getenv("LUX_MNEMONIC"); mnemonic != "" {
fmt.Printf("🔑 getDefaultKey: Using LUX_MNEMONIC (len=%d)\n", len(mnemonic))
if mnemonic := os.Getenv("MNEMONIC"); mnemonic != "" {
fmt.Printf("🔑 getDefaultKey: Using MNEMONIC (len=%d)\n", len(mnemonic))
// Use the SAME derivation function as genesis allocations
// This ensures wallet operations use keys that have funds allocated in genesis
@@ -1313,12 +1313,12 @@ func getDefaultKey() (*secp256k1.PrivateKey, error) {
return privKey, nil
}
// If LUX_PRIVATE_KEY is set, use it directly (hex encoded, 64 chars = 32 bytes)
if privKeyHex := os.Getenv("LUX_PRIVATE_KEY"); privKeyHex != "" {
fmt.Printf("🔑 getDefaultKey: Using LUX_PRIVATE_KEY (len=%d): %s...\n", len(privKeyHex), privKeyHex[:16])
// If PRIVATE_KEY is set, use it directly (hex encoded, 64 chars = 32 bytes)
if privKeyHex := os.Getenv("PRIVATE_KEY"); privKeyHex != "" {
fmt.Printf("🔑 getDefaultKey: Using PRIVATE_KEY (len=%d): %s...\n", len(privKeyHex), privKeyHex[:16])
privKeyBytes, err := hex.DecodeString(privKeyHex)
if err != nil {
return nil, fmt.Errorf("failed to decode LUX_PRIVATE_KEY: %w", err)
return nil, fmt.Errorf("failed to decode PRIVATE_KEY: %w", err)
}
privKey, err := secp256k1.ToPrivateKey(privKeyBytes)
if err != nil {
+19 -22
View File
@@ -33,14 +33,11 @@ import (
)
// getMnemonic returns the mnemonic from environment variables.
// Priority: MNEMONIC > LUX_MNEMONIC > LIGHT_MNEMONIC
// Priority: MNEMONIC > LIGHT_MNEMONIC
func getMnemonic() string {
if v := os.Getenv("MNEMONIC"); v != "" {
return v
}
if v := getMnemonic(); v != "" {
return v
}
return os.Getenv("LIGHT_MNEMONIC")
}
@@ -213,7 +210,7 @@ func NewConfigForNetwork(binaryPath string, numNodes uint32, networkID uint32) (
// Build P/X-chain allocations for wallet keys
var newAllocations []map[string]interface{}
// If LUX_MNEMONIC is set, create allocations for mnemonic-derived key
// If MNEMONIC is set, create allocations for mnemonic-derived key
if mnemonic := getMnemonic(); mnemonic != "" {
validatorKeys, err := keys.DeriveValidatorsFromMnemonic(mnemonic, 1)
if err == nil && len(validatorKeys) > 0 {
@@ -243,8 +240,8 @@ func NewConfigForNetwork(binaryPath string, numNodes uint32, networkID uint32) (
}
}
// If LUX_PRIVATE_KEY is set, also create X+P allocations for it
if privKeyHex := os.Getenv("LUX_PRIVATE_KEY"); privKeyHex != "" {
// If PRIVATE_KEY is set, also create X+P allocations for it
if privKeyHex := os.Getenv("PRIVATE_KEY"); privKeyHex != "" {
privKeyBytes, err := hex.DecodeString(privKeyHex)
if err == nil && len(privKeyBytes) == 32 {
luxPrivKey, err := luxcrypto.ToPrivateKey(privKeyBytes)
@@ -254,7 +251,7 @@ func NewConfigForNetwork(binaryPath string, numNodes uint32, networkID uint32) (
xLuxAddr, errX := address.Format("X", hrp, addr[:])
pLuxAddr, errP := address.Format("P", hrp, addr[:])
if errX == nil && errP == nil {
fmt.Printf("🔑 Adding X+P allocations for LUX_PRIVATE_KEY: X=%s, P=%s (1B each)\n", xLuxAddr, pLuxAddr)
fmt.Printf("🔑 Adding X+P allocations for PRIVATE_KEY: X=%s, P=%s (1B each)\n", xLuxAddr, pLuxAddr)
ethAddr := "0x" + hex.EncodeToString(addr[:])
newAllocations = append(newAllocations, map[string]interface{}{
"ethAddr": ethAddr,
@@ -446,7 +443,7 @@ func newCanonicalConfig(binaryPath string, numNodes uint32, networkID uint32, po
}
// Load validator keys from ~/.lux/keys/ FIRST so we can patch genesis with them
keysDir := os.Getenv("LUX_KEYS_DIR")
keysDir := os.Getenv("KEYS_DIR")
if keysDir == "" {
keysDir = validatorKeysDir()
}
@@ -786,7 +783,7 @@ func NewConfigWithPreExistingKeys(binaryPath string, networkID uint32, keysDir s
// Add private key allocation if set
var initialStakedFunds []string
if privKeyHex := os.Getenv("LUX_PRIVATE_KEY"); privKeyHex != "" {
if privKeyHex := os.Getenv("PRIVATE_KEY"); privKeyHex != "" {
privKeyBytes, err := hex.DecodeString(privKeyHex)
if err == nil && len(privKeyBytes) == 32 {
luxPrivKey, err := luxcrypto.ToPrivateKey(privKeyBytes)
@@ -797,7 +794,7 @@ func NewConfigWithPreExistingKeys(binaryPath string, networkID uint32, keysDir s
pLuxAddr, errP := address.Format("P", hrp, pChainAddr[:])
if errX == nil && errP == nil {
ethAddr := "0x" + hex.EncodeToString(pChainAddr[:])
fmt.Printf("🔑 Adding LUX_PRIVATE_KEY allocations: X=%s, P=%s (1B each)\n", xLuxAddr, pLuxAddr)
fmt.Printf("🔑 Adding PRIVATE_KEY allocations: X=%s, P=%s (1B each)\n", xLuxAddr, pLuxAddr)
allocations = append(allocations, map[string]interface{}{
"ethAddr": ethAddr,
"luxAddr": xLuxAddr,
@@ -889,7 +886,7 @@ func validatorKeysDir() string {
return filepath.Join(home, ".lux", "keys")
}
// NewConfigFromMnemonic creates a network config by deriving validator keys from LUX_MNEMONIC.
// NewConfigFromMnemonic creates a network config by deriving validator keys from MNEMONIC.
// This is the preferred method for starting mainnet/testnet.
//
// IMPORTANT: Keys are derived from mnemonic ONCE and persisted to disk (~/.lux/netrunner-validators/).
@@ -903,11 +900,11 @@ func validatorKeysDir() string {
func NewConfigFromMnemonic(binaryPath string, networkID uint32, numNodes uint32) (network.Config, error) {
mnemonic := getMnemonic()
if mnemonic == "" {
return network.Config{}, fmt.Errorf("mnemonic not set (set LIGHT_MNEMONIC, LUX_MNEMONIC, or MNEMONIC)")
return network.Config{}, fmt.Errorf("mnemonic not set (set MNEMONIC or LIGHT_MNEMONIC)")
}
// Check if persisted validator keys exist
keysDir := os.Getenv("LUX_KEYS_DIR")
keysDir := os.Getenv("KEYS_DIR")
if keysDir == "" {
keysDir = validatorKeysDir()
}
@@ -1067,8 +1064,8 @@ func NewConfigFromMnemonic(binaryPath string, networkID uint32, numNodes uint32)
fmt.Printf(" Wallet: %s -> X:%s P:%s (1B each)\n", walletKey.PChainAddr.String(), walletXAddr, walletPAddr)
}
// Add LUX_PRIVATE_KEY allocations if set and different from wallet key
if privKeyHex := os.Getenv("LUX_PRIVATE_KEY"); privKeyHex != "" {
// Add PRIVATE_KEY allocations if set and different from wallet key
if privKeyHex := os.Getenv("PRIVATE_KEY"); privKeyHex != "" {
privKeyBytes, err := hex.DecodeString(privKeyHex)
if err == nil && len(privKeyBytes) == 32 {
luxPrivKey, err := luxcrypto.ToPrivateKey(privKeyBytes)
@@ -1080,7 +1077,7 @@ func NewConfigFromMnemonic(binaryPath string, networkID uint32, numNodes uint32)
privKeyXAddr, errX := address.Format("X", hrp, privKeyAddr[:])
privKeyPAddr, errP := address.Format("P", hrp, privKeyAddr[:])
if errX == nil && errP == nil {
fmt.Printf("🔑 Adding LUX_PRIVATE_KEY allocations: X=%s P=%s (1B each)\n", privKeyXAddr, privKeyPAddr)
fmt.Printf("🔑 Adding PRIVATE_KEY allocations: X=%s P=%s (1B each)\n", privKeyXAddr, privKeyPAddr)
ethAddr := "0x" + hex.EncodeToString(privKeyAddr[:])
allocations = append(allocations, map[string]interface{}{
"ethAddr": ethAddr,
@@ -1158,29 +1155,29 @@ func NewConfigFromMnemonic(binaryPath string, networkID uint32, numNodes uint32)
return netConfig, nil
}
// NewMainnetConfigFromMnemonic creates mainnet config from LUX_MNEMONIC
// NewMainnetConfigFromMnemonic creates mainnet config from MNEMONIC
func NewMainnetConfigFromMnemonic(binaryPath string, numNodes uint32) (network.Config, error) {
return NewConfigFromMnemonic(binaryPath, constants.MainnetID, numNodes)
}
// NewTestnetConfigFromMnemonic creates testnet config from LUX_MNEMONIC
// NewTestnetConfigFromMnemonic creates testnet config from MNEMONIC
func NewTestnetConfigFromMnemonic(binaryPath string, numNodes uint32) (network.Config, error) {
return NewConfigFromMnemonic(binaryPath, constants.TestnetID, numNodes)
}
// NewDevnetConfigFromMnemonic creates devnet config from LUX_MNEMONIC
// NewDevnetConfigFromMnemonic creates devnet config from MNEMONIC
func NewDevnetConfigFromMnemonic(binaryPath string, numNodes uint32) (network.Config, error) {
return NewConfigFromMnemonic(binaryPath, constants.DevnetID, numNodes)
}
// NewLocalConfigFromMnemonic creates local network config from LUX_MNEMONIC
// NewLocalConfigFromMnemonic creates local network config from MNEMONIC
// This uses network ID 1337 with "custom" HRP, which is simpler for testing
func NewLocalConfigFromMnemonic(binaryPath string, numNodes uint32) (network.Config, error) {
return NewConfigFromMnemonic(binaryPath, configs.LocalID, numNodes)
}
// =============================================================================
// CLEAN CONFIG FUNCTIONS - No LUX_MNEMONIC, No Genesis Patching
// CLEAN CONFIG FUNCTIONS - No mnemonic env var, No Genesis Patching
// =============================================================================
// NewConfigFromDisk creates a network config by loading keys from disk and using
+2 -2
View File
@@ -13,9 +13,9 @@ import (
)
func TestMnemonicDerivation(t *testing.T) {
mnemonic := os.Getenv("LUX_MNEMONIC")
mnemonic := os.Getenv("MNEMONIC")
if mnemonic == "" {
t.Skip("LUX_MNEMONIC not set")
t.Skip("MNEMONIC not set")
}
fmt.Printf("Mnemonic: %s...\n", mnemonic[:20])
+6 -6
View File
@@ -189,8 +189,8 @@ func init() {
}
}
// If LUX_PRIVATE_KEY is set, also allocate funds to that address for chain creation
if privKeyHex := os.Getenv("LUX_PRIVATE_KEY"); privKeyHex != "" {
// If PRIVATE_KEY is set, also allocate funds to that address for chain creation
if privKeyHex := os.Getenv("PRIVATE_KEY"); privKeyHex != "" {
privKeyBytes, err := hex.DecodeString(privKeyHex)
if err == nil && len(privKeyBytes) == 32 {
// Derive P-chain address from private key
@@ -201,7 +201,7 @@ func init() {
// For default network (local, ID 1337), use "custom" HRP
luxAddr, err := address.Format("X", "custom", pChainAddr[:])
if err == nil {
fmt.Printf("🔑 Adding default network allocation for LUX_PRIVATE_KEY address: %s\n", luxAddr)
fmt.Printf("🔑 Adding default network allocation for PRIVATE_KEY address: %s\n", luxAddr)
privKeyAlloc := map[string]interface{}{
"ethAddr": "0x" + hex.EncodeToString(pChainAddr[:]),
"luxAddr": luxAddr,
@@ -461,8 +461,8 @@ func NewDefaultConfigNNodes(binaryPath string, numNodes uint32) (network.Config,
netConfig.NodeConfigs = netConfig.NodeConfigs[:numNodes]
}
// If LUX_MNEMONIC is set, add allocations for mnemonic-derived address
mnemonic := os.Getenv("LUX_MNEMONIC")
// If MNEMONIC is set, add allocations for mnemonic-derived address
mnemonic := os.Getenv("MNEMONIC")
if mnemonic != "" {
vk, err := keys.DeriveValidatorFromMnemonic(mnemonic, 0)
if err != nil {
@@ -487,7 +487,7 @@ func NewDefaultConfigNNodes(binaryPath string, numNodes uint32) (network.Config,
return netConfig, fmt.Errorf("failed to format P-chain address: %w", err)
}
fmt.Printf("🔑 Adding local network allocations for LUX_MNEMONIC: X=%s, P=%s (2B each)\n", xLuxAddr, pLuxAddr)
fmt.Printf("🔑 Adding local network allocations for MNEMONIC: X=%s, P=%s (2B each)\n", xLuxAddr, pLuxAddr)
// Get existing allocations
allocations, _ := genesis["allocations"].([]interface{})
+2 -2
View File
@@ -207,9 +207,9 @@ func (lc *localNetwork) createConfig() error {
// deterministic output. This prevents "db contains invalid genesis hash" errors on restart.
// The canonical genesis files are pre-serialized and never re-generated.
// Check if LUX_MNEMONIC is set - if so, use mnemonic-based config to generate
// Check if MNEMONIC is set - if so, use mnemonic-based config to generate
// genesis with funds allocated to the mnemonic-derived address
mnemonic := os.Getenv("LUX_MNEMONIC")
mnemonic := os.Getenv("MNEMONIC")
useMnemonic := mnemonic != ""
switch networkID {
+6 -6
View File
@@ -10,7 +10,7 @@
// Run: go test -tags gpu_chaos -v -timeout 10m ./tests/ -run TestGPU
//
// Requires:
// - A running luxd node with GPU EVM enabled (LUX_GPU_EVM=1)
// - A running luxd node with GPU EVM enabled (GPU_EVM=1)
// - Or a local anvil instance on the default RPC endpoint
//
// Set RPC_URL to override the default endpoint (http://127.0.0.1:9650/ext/bc/C/rpc).
@@ -138,17 +138,17 @@ func dialClient(t *testing.T) *ethclient.Client {
}
// fundedKey returns a funded private key for testing.
// Uses LUX_PRIVATE_KEY env var or falls back to the well-known dev key.
// Uses PRIVATE_KEY env var or falls back to the well-known dev key.
func fundedKey(t *testing.T) *ecdsa.PrivateKey {
t.Helper()
hexkey := os.Getenv("LUX_PRIVATE_KEY")
hexkey := os.Getenv("PRIVATE_KEY")
if hexkey == "" {
// Default dev/anvil funded key (account 0)
hexkey = "ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"
}
hexkey = strings.TrimPrefix(hexkey, "0x")
key, err := luxcrypto.HexToECDSA(hexkey)
require.NoError(t, err, "invalid LUX_PRIVATE_KEY")
require.NoError(t, err, "invalid PRIVATE_KEY")
return key
}
@@ -534,7 +534,7 @@ func TestGPU_Keccak256BatchConsistency(t *testing.T) {
// the EVM gracefully falls back to CPU execution and the block still finalizes.
//
// This test sends a burst of transactions, then sends SIGKILL to the GPU worker
// (identified by LUX_GPU_WORKER_PID or auto-detected). The block containing those
// (identified by GPU_WORKER_PID or auto-detected). The block containing those
// transactions must still produce a valid state root.
func TestGPU_CrashMidBlock(t *testing.T) {
client := dialClient(t)
@@ -568,7 +568,7 @@ func TestGPU_CrashMidBlock(t *testing.T) {
// In CI, the GPU worker is a separate process. If no PID is set, the test
// validates the fallback path by checking that blocks still finalize even
// if the GPU subsystem was never available.
gpuPID := os.Getenv("LUX_GPU_WORKER_PID")
gpuPID := os.Getenv("GPU_WORKER_PID")
if gpuPID != "" {
t.Logf("Killing GPU worker PID %s to simulate crash", gpuPID)
// We do NOT actually call os.Kill here because the test must be safe to run