mining

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2025 License: EUPL-1.2 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// HighResolutionDuration is the duration for which hashrate data is kept at high resolution (10s intervals)
	HighResolutionDuration = 5 * time.Minute
	// HighResolutionInterval is the interval at which hashrate data is collected for high resolution
	HighResolutionInterval = 10 * time.Second
	// LowResolutionInterval is the interval for aggregated hashrate data (1m averages)
	LowResolutionInterval = 1 * time.Minute
	// LowResHistoryRetention is the duration for which low-resolution hashrate data is retained
	LowResHistoryRetention = 24 * time.Hour // Example: keep 24 hours of 1-minute averages
)

Variables

This section is empty.

Functions

func GetVersion

func GetVersion() string

GetVersion returns the version of the application

Types

type API

type API struct {
	Enabled    bool   `json:"enabled"`
	ListenHost string `json:"listenHost"`
	ListenPort int    `json:"listenPort"`
}

API represents the XMRig API configuration

type AvailableMiner

type AvailableMiner struct {
	Name        string `json:"name"`
	Description string `json:"description"`
}

AvailableMiner represents a miner that is available to be started

type Config

type Config struct {
	Miner     string `json:"miner"`
	Pool      string `json:"pool"`
	Wallet    string `json:"wallet"`
	Threads   int    `json:"threads"`
	TLS       bool   `json:"tls"`
	HugePages bool   `json:"hugePages"`

	// Network options
	Algo            string `json:"algo,omitempty"`
	Coin            string `json:"coin,omitempty"`
	Password        string `json:"password,omitempty"` // Corresponds to -p, not --userpass
	UserPass        string `json:"userPass,omitempty"` // Corresponds to -O
	Proxy           string `json:"proxy,omitempty"`
	Keepalive       bool   `json:"keepalive,omitempty"`
	Nicehash        bool   `json:"nicehash,omitempty"`
	RigID           string `json:"rigId,omitempty"`
	TLSSingerprint  string `json:"tlsFingerprint,omitempty"`
	Retries         int    `json:"retries,omitempty"`
	RetryPause      int    `json:"retryPause,omitempty"`
	UserAgent       string `json:"userAgent,omitempty"`
	DonateLevel     int    `json:"donateLevel,omitempty"`
	DonateOverProxy bool   `json:"donateOverProxy,omitempty"`

	// CPU backend options
	NoCPU             bool   `json:"noCpu,omitempty"`
	CPUAffinity       string `json:"cpuAffinity,omitempty"`
	AV                int    `json:"av,omitempty"`
	CPUPriority       int    `json:"cpuPriority,omitempty"`
	CPUMaxThreadsHint int    `json:"cpuMaxThreadsHint,omitempty"`
	CPUMemoryPool     int    `json:"cpuMemoryPool,omitempty"`
	CPUNoYield        bool   `json:"cpuNoYield,omitempty"`
	HugepageSize      int    `json:"hugepageSize,omitempty"`
	HugePagesJIT      bool   `json:"hugePagesJIT,omitempty"`
	ASM               string `json:"asm,omitempty"`
	Argon2Impl        string `json:"argon2Impl,omitempty"`
	RandomXInit       int    `json:"randomXInit,omitempty"`
	RandomXNoNUMA     bool   `json:"randomXNoNuma,omitempty"`
	RandomXMode       string `json:"randomXMode,omitempty"`
	RandomX1GBPages   bool   `json:"randomX1GBPages,omitempty"`
	RandomXWrmsr      string `json:"randomXWrmsr,omitempty"`
	RandomXNoRdmsr    bool   `json:"randomXNoRdmsr,omitempty"`
	RandomXCacheQoS   bool   `json:"randomXCacheQoS,omitempty"`

	// API options (can be overridden or supplemented here)
	APIWorkerID      string `json:"apiWorkerId,omitempty"`
	APIID            string `json:"apiId,omitempty"`
	HTTPHost         string `json:"httpHost,omitempty"`
	HTTPPort         int    `json:"httpPort,omitempty"`
	HTTPAccessToken  string `json:"httpAccessToken,omitempty"`
	HTTPNoRestricted bool   `json:"httpNoRestricted,omitempty"`

	// Logging options
	Syslog          bool   `json:"syslog,omitempty"`
	LogFile         string `json:"logFile,omitempty"`
	PrintTime       int    `json:"printTime,omitempty"`
	HealthPrintTime int    `json:"healthPrintTime,omitempty"`
	NoColor         bool   `json:"noColor,omitempty"`
	Verbose         bool   `json:"verbose,omitempty"`
	LogOutput       bool   `json:"logOutput,omitempty"` // New field to control stdout/stderr logging

	// Misc options
	Background     bool   `json:"background,omitempty"`
	Title          string `json:"title,omitempty"`
	NoTitle        bool   `json:"noTitle,omitempty"`
	PauseOnBattery bool   `json:"pauseOnBattery,omitempty"`
	PauseOnActive  int    `json:"pauseOnActive,omitempty"`
	Stress         bool   `json:"stress,omitempty"`
	Bench          string `json:"bench,omitempty"`
	Submit         bool   `json:"submit,omitempty"`
	Verify         string `json:"verify,omitempty"`
	Seed           string `json:"seed,omitempty"`
	Hash           string `json:"hash,omitempty"`
	NoDMI          bool   `json:"noDMI,omitempty"`
}

Config represents the config for a miner, including XMRig specific options

type HashratePoint added in v0.0.6

type HashratePoint struct {
	Timestamp time.Time `json:"timestamp"`
	Hashrate  int       `json:"hashrate"`
}

HashratePoint represents a single hashrate measurement at a specific time

type History

type History struct {
	Miner   string               `json:"miner"`
	Stats   []PerformanceMetrics `json:"stats"`
	Updated int64                `json:"updated"`
}

History represents the history of a miner

type InstallationDetails

type InstallationDetails struct {
	IsInstalled bool   `json:"is_installed"`
	Version     string `json:"version"`
	Path        string `json:"path"`
	MinerBinary string `json:"miner_binary"`
}

InstallationDetails contains information about an installed miner

type Manager

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

Manager handles miner lifecycle and operations

func NewManager

func NewManager() *Manager

NewManager creates a new miner manager

func (*Manager) GetMiner

func (m *Manager) GetMiner(name string) (Miner, error)

GetMiner retrieves a miner by ID

func (*Manager) GetMinerHashrateHistory added in v0.0.6

func (m *Manager) GetMinerHashrateHistory(name string) ([]HashratePoint, error)

GetMinerHashrateHistory returns the hashrate history for a specific miner

func (*Manager) ListAvailableMiners

func (m *Manager) ListAvailableMiners() []AvailableMiner

ListAvailableMiners returns a list of available miners

func (*Manager) ListMiners

func (m *Manager) ListMiners() []Miner

ListMiners returns all miners

func (*Manager) StartMiner

func (m *Manager) StartMiner(minerType string, config *Config) (Miner, error)

StartMiner starts a new miner with the given configuration

func (*Manager) Stop added in v0.0.6

func (m *Manager) Stop()

Stop stops the manager and its background goroutines

func (*Manager) StopMiner

func (m *Manager) StopMiner(name string) error

StopMiner stops a running miner

type Miner

type Miner interface {
	Install() error
	Uninstall() error
	Start(config *Config) error
	Stop() error
	GetStats() (*PerformanceMetrics, error)
	GetName() string
	GetPath() string
	GetBinaryPath() string // New method to get the full path to the miner executable
	CheckInstallation() (*InstallationDetails, error)
	GetLatestVersion() (string, error)
	GetHashrateHistory() []HashratePoint  // New method to get hashrate history
	AddHashratePoint(point HashratePoint) // New method to add a hashrate point
	ReduceHashrateHistory(now time.Time)  // New method to trigger history reduction
}

Miner is the interface for a miner

type PerformanceMetrics

type PerformanceMetrics struct {
	Hashrate  int                    `json:"hashrate"`
	Shares    int                    `json:"shares"`
	Rejected  int                    `json:"rejected"`
	Uptime    int                    `json:"uptime"`
	LastShare int64                  `json:"lastShare"`
	Algorithm string                 `json:"algorithm"`
	ExtraData map[string]interface{} `json:"extraData,omitempty"`
}

PerformanceMetrics represents the performance metrics for a miner

type Service

type Service struct {
	Manager             *Manager
	Router              *gin.Engine
	Server              *http.Server
	DisplayAddr         string // The address to display in messages (e.g., 127.0.0.1:8080)
	SwaggerInstanceName string
	APIBasePath         string // The base path for all API routes (e.g., /api/v1/mining)
	SwaggerUIPath       string // The path where Swagger UI assets are served (e.g., /api/v1/mining/swagger)
}

func NewService

func NewService(manager *Manager, listenAddr string, displayAddr string, swaggerNamespace string) *Service

NewService creates a new mining service

func (*Service) ServiceStartup

func (s *Service) ServiceStartup(ctx context.Context) error

type SystemInfo

type SystemInfo struct {
	Timestamp           time.Time              `json:"timestamp"`
	OS                  string                 `json:"os"`
	Architecture        string                 `json:"architecture"`
	GoVersion           string                 `json:"go_version"`
	AvailableCPUCores   int                    `json:"available_cpu_cores"`
	TotalSystemRAMGB    float64                `json:"total_system_ram_gb"`
	InstalledMinersInfo []*InstallationDetails `json:"installed_miners_info"`
}

SystemInfo provides general system and miner installation information

type TTMiner

type TTMiner struct {
	Name    string `json:"name"`
	Version string `json:"version"`
	URL     string `json:"url"`
	Path    string `json:"path"`
	Running bool   `json:"running"`
	Pid     int    `json:"pid"`
}

TTMiner represents a TT-Miner

func NewTTMiner

func NewTTMiner() *TTMiner

NewTTMiner creates a new TT-Miner

func (*TTMiner) GetName

func (m *TTMiner) GetName() string

GetName returns the name of the miner

func (*TTMiner) GetStats

func (m *TTMiner) GetStats() (*PerformanceMetrics, error)

GetStats returns the stats for the miner

func (*TTMiner) Install

func (m *TTMiner) Install() error

Install the miner

func (*TTMiner) Start

func (m *TTMiner) Start(config *Config) error

Start the miner

func (*TTMiner) Stop

func (m *TTMiner) Stop() error

Stop the miner

type XMRigMiner

type XMRigMiner struct {
	Name          string `json:"name"`
	Version       string `json:"version"`
	URL           string `json:"url"`
	Path          string `json:"path"`         // This will now be the versioned folder path
	MinerBinary   string `json:"miner_binary"` // New field for the full path to the miner executable
	Running       bool   `json:"running"`
	LastHeartbeat int64  `json:"lastHeartbeat"`
	ConfigPath    string `json:"configPath"`
	API           *API   `json:"api"`

	HashrateHistory       []HashratePoint `json:"hashrateHistory"`       // High-resolution (10s)
	LowResHashrateHistory []HashratePoint `json:"lowResHashrateHistory"` // Low-resolution (1m averages)
	LastLowResAggregation time.Time       `json:"-"`                     // Timestamp of the last low-res aggregation
	// contains filtered or unexported fields
}

XMRigMiner represents an XMRig miner

func NewXMRigMiner

func NewXMRigMiner() *XMRigMiner

NewXMRigMiner creates a new XMRig miner

func (*XMRigMiner) AddHashratePoint added in v0.0.6

func (m *XMRigMiner) AddHashratePoint(point HashratePoint)

AddHashratePoint adds a new hashrate measurement to the high-resolution history.

func (*XMRigMiner) CheckInstallation

func (m *XMRigMiner) CheckInstallation() (*InstallationDetails, error)

CheckInstallation checks if the miner is installed and returns its details

func (*XMRigMiner) GetBinaryPath added in v0.0.6

func (m *XMRigMiner) GetBinaryPath() string

GetBinaryPath returns the full path to the miner executable.

func (*XMRigMiner) GetHashrateHistory added in v0.0.6

func (m *XMRigMiner) GetHashrateHistory() []HashratePoint

GetHashrateHistory returns the combined high-resolution and low-resolution hashrate history.

func (*XMRigMiner) GetLatestVersion

func (m *XMRigMiner) GetLatestVersion() (string, error)

GetLatestVersion returns the latest version of XMRig

func (*XMRigMiner) GetName

func (m *XMRigMiner) GetName() string

GetName returns the name of the miner

func (*XMRigMiner) GetPath

func (m *XMRigMiner) GetPath() string

GetPath returns the path of the miner This now returns the base installation directory for xmrig, not the versioned one.

func (*XMRigMiner) GetStats

func (m *XMRigMiner) GetStats() (*PerformanceMetrics, error)

GetStats returns the stats for the miner

func (*XMRigMiner) Install

func (m *XMRigMiner) Install() error

Download and install the latest version of XMRig

func (*XMRigMiner) ReduceHashrateHistory added in v0.0.6

func (m *XMRigMiner) ReduceHashrateHistory(now time.Time)

ReduceHashrateHistory aggregates older high-resolution data into 1-minute averages and adds them to the low-resolution history.

func (*XMRigMiner) Start

func (m *XMRigMiner) Start(config *Config) error

Start the miner

func (*XMRigMiner) Stop

func (m *XMRigMiner) Stop() error

Stop the miner

func (*XMRigMiner) Uninstall

func (m *XMRigMiner) Uninstall() error

Uninstall removes the miner files

type XMRigSummary

type XMRigSummary struct {
	Hashrate struct {
		Total []float64 `json:"total"`
	} `json:"hashrate"`
	Results struct {
		SharesGood  uint64 `json:"shares_good"`
		SharesTotal uint64 `json:"shares_total"`
	} `json:"results"`
	Uptime    uint64 `json:"uptime"`
	Algorithm string `json:"algorithm"`
}

XMRigSummary represents the summary from the XMRig API

Jump to

Keyboard shortcuts

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