config

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2026 License: BSD-3-Clause Imports: 17 Imported by: 9

Documentation

Overview

Package config provides unified configuration management for the Lux blockchain stack. All components (cli, netrunner, node, evm) should import this package for consistent configuration handling.

Package config provides unified configuration and path management for all Lux tools. This is the single source of truth for directory structures across CLI, netrunner, and node.

Directory Structure:

~/.lux/                          # Root data directory
├── chains/                      # Unified chain configs (shared by all nodes)
│   └── <chainName>/
│       ├── genesis.json
│       ├── config.json
│       └── upgrade.json
├── networks/                    # Network-specific data
│   └── <networkName>/           # mainnet, testnet, local
│       └── runs/
│           └── <runID>/         # run_20251222_102823
│               ├── node1/
│               ├── node2/
│               └── ...
├── plugins/                     # VM plugins
│   └── current/                 # Active plugins (symlinks)
│       └── <vmid>               # e.g., ag3GReYPNuSR17rUP8acMdZipQBikdXNRKDyFszAysmy3vDXE
├── keys/                        # Validator keys
│   └── <networkName>/
│       └── <nodeName>/
│           ├── staking.key
│           ├── staking.crt
│           └── signer.key
└── snapshots/                   # Network snapshots for save/restore
    └── <snapshotName>/

Index

Constants

View Source
const (
	// Core directories
	DataDirKey   = "data-dir"
	PluginDirKey = "plugin-dir"

	// Logging
	LogLevelKey      = "log-level"
	LogFormatKey     = "log-format"
	LogDirKey        = "log-dir"
	LogMaxSizeKey    = "log-max-size"
	LogMaxFilesKey   = "log-max-files"
	LogMaxAgeKey     = "log-max-age"
	LogCompressKey   = "log-compress"
	LogShowCallerKey = "log-show-caller"
	LogShowColorsKey = "log-show-colors"

	// Network
	NetworkIDKey          = "network-id"
	NetworkNameKey        = "network-name"
	NetworkAPIEndpointKey = "api-endpoint"

	// Node
	HTTPPortKey    = "http-port"
	StakingPortKey = "staking-port"
	DBTypeKey      = "db-type"

	// Config file
	ConfigFileKey = "config-file"
)

Flag keys used across all components

View Source
const (
	// EnvPrefix is the prefix for environment variables
	EnvPrefix = "LUX"

	// ConfigFileName is the default config file name (without extension)
	ConfigFileName = "config"

	// DefaultDataDir is the default data directory
	DefaultDataDir = "~/.lux"
)
View Source
const (
	HTTPHostKey                  = "http-host"
	BootstrapNodesKey            = "bootstrap-nodes"
	BootstrapIPsKey              = "bootstrap-ips"
	BootstrapIDsKey              = "bootstrap-ids"
	DBPathKey                    = "db-dir"
	LogsDirKey                   = "log-dir"
	TrackChainsKey               = "track-chains"
	ChainConfigDirKey            = "chain-config-dir"
	NetConfigDirKey              = "net-config-dir"
	GenesisFileKey               = "genesis-file"
	StakingTLSKeyPathKey         = "staking-tls-key-file"
	StakingCertPathKey           = "staking-tls-cert-file"
	StakingSignerKeyPathKey      = "staking-signer-key-file"
	SybilProtectionEnabledKey    = "sybil-protection-enabled"
	IndexEnabledKey              = "index-enabled"
	IndexAllowIncompleteKey      = "index-allow-incomplete"
	NetworkAllowPrivateIPsKey    = "network-allow-private-ips"
	PartialSyncPrimaryNetworkKey = "partial-sync-primary-network"
)

Luxd config keys referenced by netrunner/cli.

View Source
const (
	// Root directory name
	LuxDir = ".lux"

	// Top-level directories under ~/.lux/
	ChainsDir    = "chains"
	NetworksDir  = "networks"
	PluginsDir   = "plugins"
	KeysDir      = "keys"
	SnapshotsDir = "snapshots"

	// Subdirectories
	RunsDir           = "runs"
	CurrentPluginsDir = "current"

	// File names for chain configs
	GenesisFile = "genesis.json"
	ConfigFile  = "config.json"
	UpgradeFile = "upgrade.json"

	// File names for node keys
	StakingKeyFile  = "staking.key"
	StakingCertFile = "staking.crt"
	SignerKeyFile   = "signer.key"

	// Network names
	NetworkMainnet = "mainnet"
	NetworkTestnet = "testnet"
	NetworkLocal   = "local"

	// Run directory prefix
	RunPrefix = "run"
)

Directory names - single source of truth

View Source
const (
	// Well-known VM names
	VMNameLuxEVM = "Lux EVM"
	VMNameCoreVM = "Core VM"
	VMNameXVM    = "XVM"
)
View Source
const (
	LuxNodeDataDirVar = "LUXD_DATA_DIR"
)

Luxd environment variables referenced by cli helpers.

Variables

View Source
var FlagDescriptions = map[string]string{
	DataDirKey:            "Base directory for all Lux data including plugins, logs, database, and configuration files",
	PluginDirKey:          "Directory containing VM plugin binaries. Defaults to $DATA_DIR/plugins if not specified",
	LogLevelKey:           "Minimum log level to output. Available levels: verbo, debug, trace, info, warn, error, fatal, off",
	LogFormatKey:          "Output format for logs. 'terminal' for colored output, 'json' for structured logs, 'plain' for uncolored text",
	LogDirKey:             "Directory where log files are written. Defaults to $DATA_DIR/logs if not specified",
	LogMaxSizeKey:         "Maximum size of a single log file in megabytes before rotation",
	LogMaxFilesKey:        "Maximum number of old log files to retain after rotation",
	LogMaxAgeKey:          "Maximum age in days for old log files. Files older than this are deleted. 0 means no age limit",
	LogCompressKey:        "Whether to compress rotated log files using gzip",
	LogShowCallerKey:      "Include file name and line number in log entries",
	LogShowColorsKey:      "Use ANSI colors in terminal output",
	NetworkIDKey:          "Network ID for the blockchain network",
	NetworkNameKey:        "Human-readable network name (mainnet, testnet, local, or custom)",
	NetworkAPIEndpointKey: "HTTP endpoint for the node's API",
	HTTPPortKey:           "Port for HTTP API server",
	StakingPortKey:        "Port for staking and P2P connections",
	DBTypeKey:             "Database backend type. Options: badgerdb (default), leveldb, pebbledb, memdb",
	ConfigFileKey:         "Path to configuration file. Supports JSON, YAML, and TOML formats",
}

FlagDescription provides descriptions for flags

Functions

func AddAllFlags

func AddAllFlags(fs *pflag.FlagSet)

AddAllFlags adds all available flags

func AddGlobalFlags

func AddGlobalFlags(fs *pflag.FlagSet)

AddGlobalFlags adds common flags used by all Lux components This should be called by root command of each component

func AddLogFlags

func AddLogFlags(fs *pflag.FlagSet)

AddLogFlags adds logging-specific flags

func AddNetworkFlags

func AddNetworkFlags(fs *pflag.FlagSet)

AddNetworkFlags adds network-related flags

func AddNodeFlags

func AddNodeFlags(fs *pflag.FlagSet)

AddNodeFlags adds node-specific flags

func CreateDevelopmentLogger

func CreateDevelopmentLogger(name string) (*zap.Logger, error)

CreateDevelopmentLogger creates a logger suitable for development

func CreateNopLogger

func CreateNopLogger() *zap.Logger

CreateNopLogger creates a no-op logger that discards all output

func CreateProductionLogger

func CreateProductionLogger(name string, logDir string) (*zap.Logger, error)

CreateProductionLogger creates a logger suitable for production

func Exists

func Exists(path string) bool

Exists checks if a path exists

func FormatError

func FormatError(err error, context string, args ...interface{}) string

FormatError provides consistent error formatting This fixes issues like "last checked %s" format bugs

func GPUBackend

func GPUBackend() string

GPUBackend returns the configured GPU backend.

func GetChainIDFromGenesis

func GetChainIDFromGenesis(genesis []byte) (uint64, error)

GetChainIDFromGenesis extracts chainID from an EVM genesis file

func GetFlagDescription

func GetFlagDescription(key string) string

GetFlagDescription returns the description for a flag

func IsGPUEnabled

func IsGPUEnabled() bool

IsGPUEnabled returns whether GPU acceleration is enabled globally.

func IsSymlink(path string) bool

IsSymlink checks if a path is a symlink

func NewRunID

func NewRunID() string

NewRunID generates a new timestamped run ID Returns: run_20251222_102823

func ResolvePluginBaseDir

func ResolvePluginBaseDir() string

ResolvePluginBaseDir returns the base plugin directory This contains packages/, current/, and registry.json

func ResolvePluginDir

func ResolvePluginDir() string

ResolvePluginDir resolves the plugin directory using the configuration stack This returns the "current" directory where VMID symlinks live for node compatibility Structure:

~/.lux/plugins/
├── packages/luxfi/evm/v1.0.0/  # Actual packages
├── current/ag3GReY.../         # VMID symlinks (what node uses)
└── registry.json

func SetGlobal

func SetGlobal(cfg *LuxConfig)

SetGlobal sets the global configuration instance This should be called early in application startup

func SetGlobalGPUConfig

func SetGlobalGPUConfig(cfg GPUConfig) error

SetGlobalGPUConfig sets the global GPU configuration. This should be called once during node initialization before any GPU accelerators are created.

func VMID

func VMID(vmName string) string

VMID computes the VM ID from a VM name. This is the standard way to compute VMID: base58check(sha256(pad32(vmName))) Example: "Lux EVM" -> "ag3GReYPNuSR17rUP8acMdZipQBikdXNRKDyFszAysmy3vDXE"

func WellKnownVMIDs

func WellKnownVMIDs() map[string]string

WellKnownVMIDs returns a map of well-known VM names to their IDs

Types

type AirdropConfig

type AirdropConfig struct {
	Enabled         bool
	SnapshotDate    string
	ConversionRatio float64 // Legacy token to LUX conversion ratio
	VestingPeriod   uint64  // in seconds
	ClaimPeriod     uint64  // in seconds
}

AirdropConfig defines airdrop parameters

type ChainConfig

type ChainConfig struct {
	Name    string          // Chain name (e.g., "zoo", "mychain")
	Genesis json.RawMessage // Genesis JSON
	Config  json.RawMessage // Chain config JSON (eth APIs, etc.)
	Upgrade json.RawMessage // Upgrade config JSON
}

ChainConfig represents the chain configuration files

type ChainManager

type ChainManager struct {
	// contains filtered or unexported fields
}

ChainManager handles unified chain configuration across all nodes

func DefaultChainManager

func DefaultChainManager() (*ChainManager, error)

DefaultChainManager creates a chain manager with default paths

func NewChainManager

func NewChainManager(paths *Paths) *ChainManager

NewChainManager creates a new chain manager

func (*ChainManager) ChainExists

func (cm *ChainManager) ChainExists(chainName string) bool

ChainExists checks if a chain configuration exists

func (*ChainManager) CopyChainConfigsToNode

func (cm *ChainManager) CopyChainConfigsToNode(chainName, chainID, nodeDir string) error

CopyChainConfigsToNode copies chain configs to a node's chain directory This is used when starting nodes to provide chain-specific configuration Destination: <nodeDir>/configs/chains/<chainID>/

func (*ChainManager) DeleteChain

func (cm *ChainManager) DeleteChain(chainName string) error

DeleteChain removes all configuration for a chain

func (*ChainManager) ListChains

func (cm *ChainManager) ListChains() ([]string, error)

ListChains returns all configured chains

func (*ChainManager) LoadChain

func (cm *ChainManager) LoadChain(chainName string) (*ChainConfig, error)

LoadChain loads all configuration for a chain

func (*ChainManager) LoadGenesis

func (cm *ChainManager) LoadGenesis(chainName string) ([]byte, error)

LoadGenesis loads just the genesis file for a chain

func (*ChainManager) SaveChain

func (cm *ChainManager) SaveChain(cc *ChainConfig) error

SaveChain saves chain configuration

func (*ChainManager) SaveGenesis

func (cm *ChainManager) SaveGenesis(chainName string, genesis []byte) error

SaveGenesis saves just the genesis file for a chain

type ChainStakeRequirement

type ChainStakeRequirement struct {
	ChainID               string
	MinimumStake          uint64
	RequiresSpecialAccess bool   // e.g., B-chain bridge validators
	AccessRequirements    string // Description of special requirements
}

ChainStakeRequirement defines chain-specific staking requirements

type DefaultPluginManager

type DefaultPluginManager struct {
	// contains filtered or unexported fields
}

DefaultPluginManager implements PluginManager

func (*DefaultPluginManager) EnsureDir

func (pm *DefaultPluginManager) EnsureDir() error

EnsureDir ensures the plugin directory exists

func (*DefaultPluginManager) Exists

func (pm *DefaultPluginManager) Exists(vmID string) bool

Exists checks if a plugin is installed

func (*DefaultPluginManager) Get

func (pm *DefaultPluginManager) Get(ctx context.Context, vmID string) (*PluginInfo, error)

Get returns info about a specific plugin

func (*DefaultPluginManager) GetPath

func (pm *DefaultPluginManager) GetPath(vmID string) string

GetPath returns the full path for a plugin binary

func (*DefaultPluginManager) GetPluginDir

func (pm *DefaultPluginManager) GetPluginDir() string

GetPluginDir returns the plugin directory

func (*DefaultPluginManager) GetTarget

func (pm *DefaultPluginManager) GetTarget(vmID string) (string, error)

GetTarget returns the target of a plugin symlink

func (*DefaultPluginManager) Install

func (pm *DefaultPluginManager) Install(ctx context.Context, source string, vmID string) error

Install installs a plugin from a source path

func (pm *DefaultPluginManager) IsSymlink(vmID string) bool

IsSymlink checks if a plugin path is a symlink

func (pm *DefaultPluginManager) Link(vmID, binaryPath string) error

Link creates a symlink from the plugin directory to a VM binary. This is the preferred way to "install" a VM for development.

func (*DefaultPluginManager) LinkByName

func (pm *DefaultPluginManager) LinkByName(vmName, binaryPath string) error

LinkByName creates a symlink using the VM name to compute VMID

func (*DefaultPluginManager) List

List returns all installed plugins

func (*DefaultPluginManager) Uninstall

func (pm *DefaultPluginManager) Uninstall(ctx context.Context, vmID string) error

Uninstall removes a plugin

func (*DefaultPluginManager) Verify

func (pm *DefaultPluginManager) Verify(vmID string) error

Verify checks if a plugin is properly installed and executable

type GPUConfig

type GPUConfig struct {
	// Enabled controls whether GPU acceleration is used
	Enabled bool

	// Backend specifies which GPU backend to use: "auto", "metal", "cuda", "cpu"
	Backend string

	// DeviceIndex specifies which GPU device to use when multiple are available
	DeviceIndex int

	// LogLevel sets the GPU subsystem log level: "debug", "info", "warn", "error"
	LogLevel string
}

GPUConfig holds GPU acceleration configuration.

func DefaultGPUConfig

func DefaultGPUConfig() GPUConfig

DefaultGPUConfig returns the default GPU configuration.

func GetGlobalGPUConfig

func GetGlobalGPUConfig() GPUConfig

GetGlobalGPUConfig returns the global GPU configuration. If not set, returns the default configuration.

func (GPUConfig) ResolveBackend

func (c GPUConfig) ResolveBackend() string

ResolveBackend returns the actual backend to use based on configuration. If Backend is "auto", it detects the best available backend.

func (GPUConfig) Validate

func (c GPUConfig) Validate() error

Validate checks that the GPU configuration is valid.

type Loader

type Loader struct {
	// contains filtered or unexported fields
}

Loader handles configuration loading from all sources

func NewLoader

func NewLoader(opts ...LoaderOption) *Loader

NewLoader creates a new configuration loader

func (*Loader) BindFlags

func (l *Loader) BindFlags(fs *pflag.FlagSet) error

BindFlags binds CLI flags to the configuration

func (*Loader) GetConfigFilePath

func (l *Loader) GetConfigFilePath() string

GetConfigFilePath returns the path of the config file that was loaded

func (*Loader) Load

func (l *Loader) Load() (*LuxConfig, error)

Load loads configuration from all sources following precedence: CLI Flags > Environment Variables > Config File > Defaults

type LoaderOption

type LoaderOption func(*Loader)

LoaderOption is a functional option for the Loader

func WithConfigFile

func WithConfigFile(path string) LoaderOption

WithConfigFile sets an explicit config file path

func WithConfigPaths

func WithConfigPaths(paths ...string) LoaderOption

WithConfigPaths sets custom config search paths

type LogConfig

type LogConfig struct {
	// Level is the minimum log level to output
	Level string `json:"level" yaml:"level" mapstructure:"level"`

	// Format is the log output format (terminal, json, plain)
	Format string `json:"format" yaml:"format" mapstructure:"format"`

	// Directory is where log files are written
	Directory string `json:"directory" yaml:"directory" mapstructure:"directory"`

	// MaxSize is the maximum size in megabytes before log rotation
	MaxSize int `json:"max-size" yaml:"max-size" mapstructure:"max-size"`

	// MaxFiles is the maximum number of old log files to retain
	MaxFiles int `json:"max-files" yaml:"max-files" mapstructure:"max-files"`

	// MaxAge is the maximum number of days to retain old log files
	MaxAge int `json:"max-age" yaml:"max-age" mapstructure:"max-age"`

	// Compress enables compression of rotated log files
	Compress bool `json:"compress" yaml:"compress" mapstructure:"compress"`

	// ShowCaller shows caller information in log entries
	ShowCaller bool `json:"show-caller" yaml:"show-caller" mapstructure:"show-caller"`

	// ShowColors enables colored output for terminal format
	ShowColors bool `json:"show-colors" yaml:"show-colors" mapstructure:"show-colors"`
}

LogConfig defines unified logging settings

type LogFactory

type LogFactory struct {
	// contains filtered or unexported fields
}

LogFactory creates configured loggers

func NewLogFactory

func NewLogFactory(cfg LogConfig) *LogFactory

NewLogFactory creates a new log factory from configuration

func NewLogFactoryFromGlobal

func NewLogFactoryFromGlobal() *LogFactory

NewLogFactoryFromGlobal creates a log factory from global config

func (*LogFactory) CreateLogger

func (f *LogFactory) CreateLogger(name string) (*zap.Logger, error)

CreateLogger creates a new logger with the given name

type LogFormat

type LogFormat string

LogFormat represents log output formats

const (
	LogFormatTerminal LogFormat = "terminal"
	LogFormatJSON     LogFormat = "json"
	LogFormatPlain    LogFormat = "plain"
)

type LogLevel

type LogLevel string

LogLevel represents logging levels

const (
	LogLevelVerbo LogLevel = "verbo"
	LogLevelDebug LogLevel = "debug"
	LogLevelTrace LogLevel = "trace"
	LogLevelInfo  LogLevel = "info"
	LogLevelWarn  LogLevel = "warn"
	LogLevelError LogLevel = "error"
	LogLevelFatal LogLevel = "fatal"
	LogLevelOff   LogLevel = "off"
)

type LoggerAdapter

type LoggerAdapter struct {
	*zap.Logger
	// contains filtered or unexported fields
}

LoggerAdapter wraps zap.Logger to provide additional functionality

func NewLoggerAdapter

func NewLoggerAdapter(logger *zap.Logger) *LoggerAdapter

NewLoggerAdapter creates a new logger adapter

func (*LoggerAdapter) Sugared

func (l *LoggerAdapter) Sugared() *zap.SugaredLogger

Sugared returns the sugared logger for printf-style logging

func (*LoggerAdapter) WithContext

func (l *LoggerAdapter) WithContext(ctx map[string]interface{}) *LoggerAdapter

WithContext adds common context fields

type LuxConfig

type LuxConfig struct {
	// DataDir is the base directory for all Lux data
	DataDir string `json:"data-dir" yaml:"data-dir" mapstructure:"data-dir"`

	// PluginDir is the directory for VM plugins
	PluginDir string `json:"plugin-dir" yaml:"plugin-dir" mapstructure:"plugin-dir"`

	// Log contains logging configuration
	Log LogConfig `json:"log" yaml:"log" mapstructure:"log"`

	// Network contains network-related configuration
	Network NetworkConfig `json:"network" yaml:"network" mapstructure:"network"`

	// Node contains node-specific configuration
	Node NodeConfig `json:"node" yaml:"node" mapstructure:"node"`
}

LuxConfig is the unified configuration for all Lux components

func DefaultConfig

func DefaultConfig() *LuxConfig

DefaultConfig returns the default configuration

func Global

func Global() *LuxConfig

Global returns the global configuration instance (singleton) This lazily loads configuration on first call

func MustLoad

func MustLoad(opts ...LoaderOption) *LuxConfig

MustLoad loads configuration and panics on error

func (*LuxConfig) GetChainsConfigPath

func (c *LuxConfig) GetChainsConfigPath() string

GetChainsConfigPath returns the chains config directory path

func (*LuxConfig) GetConfigsPath

func (c *LuxConfig) GetConfigsPath() string

GetConfigsPath returns the configs directory path

func (*LuxConfig) GetDBPath

func (c *LuxConfig) GetDBPath() string

GetDBPath returns the database path

func (*LuxConfig) GetLogPath

func (c *LuxConfig) GetLogPath(name string) string

GetLogPath returns the full path for a named log file

func (*LuxConfig) GetNetsConfigPath

func (c *LuxConfig) GetNetsConfigPath() string

GetNetsConfigPath returns the nets config directory path

func (*LuxConfig) GetPluginPath

func (c *LuxConfig) GetPluginPath(vmID string) string

GetPluginPath returns the full path for a plugin binary

func (*LuxConfig) GetStakingPath

func (c *LuxConfig) GetStakingPath() string

GetStakingPath returns the staking keys path

func (*LuxConfig) GetVMsConfigPath

func (c *LuxConfig) GetVMsConfigPath() string

GetVMsConfigPath returns the VMs config directory path

func (*LuxConfig) Validate

func (c *LuxConfig) Validate() error

Validate validates the configuration

type NFTTier

type NFTTier struct {
	Name              string
	RequiredLUX       uint64 // Base LUX requirement with NFT
	StakingMultiplier uint32 // Reward multiplier percentage
	MaxValidators     uint32 // Max validators in this tier
}

NFTTier represents different validator NFT tiers

type NetworkConfig

type NetworkConfig struct {
	// ID is the network ID
	ID uint32 `json:"id" yaml:"id" mapstructure:"id"`

	// Name is the network name (mainnet, testnet, local)
	Name string `json:"name" yaml:"name" mapstructure:"name"`

	// APIEndpoint is the primary API endpoint
	APIEndpoint string `json:"api-endpoint" yaml:"api-endpoint" mapstructure:"api-endpoint"`
}

NetworkConfig defines network-related settings

type NodeConfig

type NodeConfig struct {
	// HTTPPort is the HTTP API port
	HTTPPort int `json:"http-port" yaml:"http-port" mapstructure:"http-port"`

	// StakingPort is the staking/P2P port
	StakingPort int `json:"staking-port" yaml:"staking-port" mapstructure:"staking-port"`

	// DBType is the database backend type
	DBType string `json:"db-type" yaml:"db-type" mapstructure:"db-type"`
}

NodeConfig defines node-specific settings

type Paths

type Paths struct {
	// BaseDir is the root data directory (default: ~/.lux)
	BaseDir string
}

Paths provides unified path management for Lux tools. Create one instance and use it throughout your application.

func DefaultPaths

func DefaultPaths() (*Paths, error)

DefaultPaths returns a Paths instance using the default base directory (~/.lux)

func NewPaths

func NewPaths(baseDir string) *Paths

NewPaths creates a Paths instance with a custom base directory

func (*Paths) ChainConfig

func (p *Paths) ChainConfig(chainName string) string

ChainConfig returns the config file path for a chain Returns: ~/.lux/chains/<chainName>/config.json

func (*Paths) ChainDir

func (p *Paths) ChainDir(chainName string) string

ChainDir returns the config directory for a specific chain Returns: ~/.lux/chains/<chainName>/

func (*Paths) ChainGenesis

func (p *Paths) ChainGenesis(chainName string) string

ChainGenesis returns the genesis file path for a chain Returns: ~/.lux/chains/<chainName>/genesis.json

func (*Paths) ChainUpgrade

func (p *Paths) ChainUpgrade(chainName string) string

ChainUpgrade returns the upgrade file path for a chain Returns: ~/.lux/chains/<chainName>/upgrade.json

func (*Paths) ChainsBaseDir

func (p *Paths) ChainsBaseDir() string

ChainsBaseDir returns the base directory for all chain configs Returns: ~/.lux/chains/

func (*Paths) CurrentPluginsDir

func (p *Paths) CurrentPluginsDir() string

CurrentPluginsDir returns the directory for active plugin symlinks Returns: ~/.lux/plugins/current/

func (*Paths) EnsureChainDir

func (p *Paths) EnsureChainDir(chainName string) error

EnsureChainDir creates the chain config directory

func (*Paths) EnsureCurrentPluginsDir

func (p *Paths) EnsureCurrentPluginsDir() error

EnsureCurrentPluginsDir creates the current plugins directory

func (*Paths) EnsureDir

func (p *Paths) EnsureDir(path string) error

EnsureDir creates a directory if it doesn't exist

func (*Paths) EnsureNetworkRunsDir

func (p *Paths) EnsureNetworkRunsDir(networkName string) error

EnsureNetworkRunsDir creates the runs directory for a network

func (*Paths) EnsureNodeKeysDir

func (p *Paths) EnsureNodeKeysDir(networkName, nodeName string) error

EnsureNodeKeysDir creates the keys directory for a node

func (*Paths) FindLatestRun

func (p *Paths) FindLatestRun(networkName string) (string, error)

FindLatestRun finds the most recent run directory with node data Returns the run ID (not full path) or empty string if none found

func (*Paths) GetOrCreateRun

func (p *Paths) GetOrCreateRun(networkName string) (string, error)

GetOrCreateRun finds existing run or creates new one Returns the full path to the run directory

func (*Paths) KeysBaseDir

func (p *Paths) KeysBaseDir() string

KeysBaseDir returns the base directory for all keys Returns: ~/.lux/keys/

func (*Paths) NetworkDir

func (p *Paths) NetworkDir(networkName string) string

NetworkDir returns the directory for a specific network Returns: ~/.lux/networks/<networkName>/

func (*Paths) NetworkKeysDir

func (p *Paths) NetworkKeysDir(networkName string) string

NetworkKeysDir returns the keys directory for a specific network Returns: ~/.lux/keys/<networkName>/

func (*Paths) NetworkRunDir

func (p *Paths) NetworkRunDir(networkName, runID string) string

NetworkRunDir returns a specific run directory Returns: ~/.lux/networks/<networkName>/runs/<runID>/

func (*Paths) NetworkRunsDir

func (p *Paths) NetworkRunsDir(networkName string) string

NetworkRunsDir returns the runs directory for a network Returns: ~/.lux/networks/<networkName>/runs/

func (*Paths) NetworksBaseDir

func (p *Paths) NetworksBaseDir() string

NetworksBaseDir returns the base directory for all networks Returns: ~/.lux/networks/

func (*Paths) NodeDir

func (p *Paths) NodeDir(networkName, runID, nodeName string) string

NodeDir returns the directory for a specific node within a run Returns: ~/.lux/networks/<networkName>/runs/<runID>/<nodeName>/

func (*Paths) NodeKeysDir

func (p *Paths) NodeKeysDir(networkName, nodeName string) string

NodeKeysDir returns the keys directory for a specific node Returns: ~/.lux/keys/<networkName>/<nodeName>/

func (*Paths) NodeSignerKey

func (p *Paths) NodeSignerKey(networkName, nodeName string) string

NodeSignerKey returns the signer key path for a node Returns: ~/.lux/keys/<networkName>/<nodeName>/signer.key

func (*Paths) NodeStakingCert

func (p *Paths) NodeStakingCert(networkName, nodeName string) string

NodeStakingCert returns the staking cert path for a node Returns: ~/.lux/keys/<networkName>/<nodeName>/staking.crt

func (*Paths) NodeStakingKey

func (p *Paths) NodeStakingKey(networkName, nodeName string) string

NodeStakingKey returns the staking key path for a node Returns: ~/.lux/keys/<networkName>/<nodeName>/staking.key

func (*Paths) PluginPath

func (p *Paths) PluginPath(vmID string) string

PluginPath returns the path for a specific VM plugin Returns: ~/.lux/plugins/current/<vmID>

func (*Paths) PluginsBaseDir

func (p *Paths) PluginsBaseDir() string

PluginsBaseDir returns the base directory for all plugins Returns: ~/.lux/plugins/

func (*Paths) SnapshotDir

func (p *Paths) SnapshotDir(snapshotName string) string

SnapshotDir returns the directory for a specific snapshot Returns: ~/.lux/snapshots/<snapshotName>/

func (*Paths) SnapshotsBaseDir

func (p *Paths) SnapshotsBaseDir() string

SnapshotsBaseDir returns the base directory for all snapshots Returns: ~/.lux/snapshots/

type PluginInfo

type PluginInfo struct {
	// VMID is the VM identifier (hash)
	VMID string `json:"vm_id"`

	// Name is the human-readable name
	Name string `json:"name"`

	// Version is the plugin version
	Version string `json:"version"`

	// Path is the full path to the plugin binary
	Path string `json:"path"`

	// Description is an optional description
	Description string `json:"description"`

	// Installed indicates if the plugin is installed
	Installed bool `json:"installed"`

	// Size is the file size in bytes
	Size int64 `json:"size"`

	// ModTime is the last modification time
	ModTime time.Time `json:"mod_time"`
}

PluginInfo describes an installed plugin

type PluginManager

type PluginManager interface {
	// GetPluginDir returns the resolved plugin directory
	GetPluginDir() string

	// List returns all installed plugins
	List(ctx context.Context) ([]PluginInfo, error)

	// Get returns info about a specific plugin
	Get(ctx context.Context, vmID string) (*PluginInfo, error)

	// Install installs a plugin from a source path
	Install(ctx context.Context, source string, vmID string) error

	// Uninstall removes a plugin
	Uninstall(ctx context.Context, vmID string) error

	// GetPath returns the full path for a plugin binary
	GetPath(vmID string) string

	// Exists checks if a plugin is installed
	Exists(vmID string) bool

	// EnsureDir ensures the plugin directory exists
	EnsureDir() error
}

PluginManager handles plugin discovery, installation, and loading

func NewPluginManager

func NewPluginManager(cfg *LuxConfig) PluginManager

NewPluginManager creates a new plugin manager

func NewPluginManagerWithDir

func NewPluginManagerWithDir(pluginDir string) PluginManager

NewPluginManagerWithDir creates a plugin manager with a specific directory

type PluginManifest

type PluginManifest struct {
	// Name is the package name (e.g., "evm")
	Name string `json:"name"`

	// Org is the organization/username (e.g., "luxfi")
	Org string `json:"org"`

	// Version is the semantic version (e.g., "v1.0.0")
	Version string `json:"version"`

	// VMID is the computed VM identifier hash
	VMID string `json:"vmid"`

	// VMName is the canonical VM name used to compute VMID
	VMName string `json:"vm_name,omitempty"`

	// Aliases are alternative names for this VM
	Aliases []string `json:"aliases,omitempty"`

	// Binary is the executable filename
	Binary string `json:"binary"`

	// Description is a human-readable description
	Description string `json:"description,omitempty"`

	// Repository is the source repository URL
	Repository string `json:"repository,omitempty"`

	// InstalledAt is when the plugin was installed
	InstalledAt time.Time `json:"installed_at"`

	// Size is the binary size in bytes
	Size int64 `json:"size,omitempty"`
}

PluginManifest contains metadata about an installed plugin

type PluginPackageManager

type PluginPackageManager struct {
	// contains filtered or unexported fields
}

PluginPackageManager provides proper package manager functionality

func NewPluginPackageManager

func NewPluginPackageManager(baseDir string) (*PluginPackageManager, error)

NewPluginPackageManager creates a new package manager

func (*PluginPackageManager) Activate

func (pm *PluginPackageManager) Activate(ctx context.Context, org, name, version string) error

Activate creates the VMID symlink for a specific version

func (*PluginPackageManager) ActivePath

func (pm *PluginPackageManager) ActivePath(vmid string) string

ActivePath returns the path for VMID symlinks (node compatibility)

func (*PluginPackageManager) GetActiveDir

func (pm *PluginPackageManager) GetActiveDir() string

GetActiveDir returns the directory containing VMID symlinks (for node compatibility)

func (*PluginPackageManager) GetManifest

func (pm *PluginPackageManager) GetManifest(org, name, version string) (*PluginManifest, error)

GetManifest loads the manifest for a specific package version

func (*PluginPackageManager) Install

func (pm *PluginPackageManager) Install(ctx context.Context, manifest *PluginManifest, binaryPath string) error

Install installs a plugin from a binary path

func (pm *PluginPackageManager) Link(ctx context.Context, manifest *PluginManifest, binaryPath string) error

Link creates a symlink-based installation (for development) Unlike Install which copies the binary, Link creates a symlink to the source

func (*PluginPackageManager) List

List returns all installed packages

func (*PluginPackageManager) ListActive

func (pm *PluginPackageManager) ListActive(ctx context.Context) (map[string]PluginManifest, error)

ListActive returns all active plugins (those with VMID symlinks)

func (*PluginPackageManager) MigrateFromLegacy

func (pm *PluginPackageManager) MigrateFromLegacy(ctx context.Context, legacyDir string) error

MigrateFromLegacy migrates plugins from the old VMID-based structure

func (*PluginPackageManager) PackagePath

func (pm *PluginPackageManager) PackagePath(org, name, version string) string

PackagePath returns the path for a specific package version

func (*PluginPackageManager) Uninstall

func (pm *PluginPackageManager) Uninstall(ctx context.Context, org, name, version string) error

Uninstall removes a specific version of a package

type PluginRegistry

type PluginRegistry struct {
	// Plugins maps "org/name" to list of installed versions
	Plugins map[string][]string `json:"plugins"`

	// Active maps VMID to active package reference
	Active map[string]string `json:"active"`

	// UpdatedAt is when the registry was last modified
	UpdatedAt time.Time `json:"updated_at"`
}

PluginRegistry tracks all installed plugins

type StakingConfig

type StakingConfig struct {
	// Minimum stake: 1M LUX for validators
	MinimumValidatorStake uint64

	// NFT staking tiers
	NFTStakingEnabled bool
	NFTTiers          []NFTTier

	// Delegation parameters
	MinimumDelegatorStake uint64
	MaxDelegationRatio    uint32

	// Chain-specific validator requirements
	ChainValidatorRequirements map[string]ChainStakeRequirement

	// Combined staking (NFT + delegation + staked) to reach minimum
	AllowCombinedStaking bool
}

StakingConfig defines staking parameters

type TokenomicsConfig

type TokenomicsConfig struct {
	// Total supply: 2T tokens
	TotalSupply uint64

	// Airdrop configuration for legacy token holders
	AirdropConfig AirdropConfig

	// Staking requirements
	StakingConfig StakingConfig

	// Chain-specific allocations
	ChainAllocations map[string]uint64
}

TokenomicsConfig defines the token economics for the Lux Network

func DefaultTokenomicsConfig

func DefaultTokenomicsConfig() *TokenomicsConfig

DefaultTokenomicsConfig returns the default tokenomics configuration

func (*TokenomicsConfig) GetMinimumStake

func (c *TokenomicsConfig) GetMinimumStake(hasNFT bool, nftTier string) uint64

GetMinimumStake returns the minimum stake based on NFT ownership

func (*TokenomicsConfig) GetStakingMultiplier

func (c *TokenomicsConfig) GetStakingMultiplier(nftTier string) uint32

GetStakingMultiplier returns the reward multiplier for a given NFT tier

Directories

Path Synopsis
Package configspec provides the embedded luxd configuration specification.
Package configspec provides the embedded luxd configuration specification.

Jump to

Keyboard shortcuts

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