miner

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2019 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Overview

Package miner implements various Lethean-compatible miners that can be used by the GUI

Index

Constants

This section is empty.

Variables

View Source
var SupportedMiners = []string{"xmr-stak", "xmrig"}

SupportedMiners contains a list of the currently supported miners

Functions

func DetermineMinerType

func DetermineMinerType(dir string) (string, string, error)

DetermineMinerType checks the given path for supported miners and returns the type of miner and path to the executable

func HumanizeHashrate

func HumanizeHashrate(hashrate float64) string

HumanizeHashrate returns the H/s, KH/s or MH/s representation of hashrate

func HumanizeTime

func HumanizeTime(seconds int) string

HumanizeTime turns seconds into minutes, hours, etc

Types

type Base

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

Base implements core functionality common to all miners

func (*Base) Start

func (b *Base) Start() error

Start the miner

func (*Base) Stop

func (b *Base) Stop() error

Stop the miner

type Config

type Config struct {
	// Type of miner
	Type string `json:"type"`
	// Path to the selected miner's executable
	Path string `json:"path"`
	// Endpoint of the miner's JSON API
	Endpoint string `json:"endpoint"`
}

Config holds miner specific configuration information

type Miner

type Miner interface {
	// Start the miner
	Start() error
	// Stop the miner
	Stop() error
	// WriteConfig writes the miner's configuration to the file format as
	// specified by the miner
	WriteConfig(
		poolEndpoint string,
		walletAddress string,
		processingConfig ProcessingConfig) error
	// GetProcessingConfig returns the current miner processing config
	// TODO: Currently only CPU threads, extend this to full CPU/GPU config
	GetProcessingConfig() ProcessingConfig
	// GetName returns the name of the miner
	GetName() string
	// GetLastHashrate returns the last reported hashrate
	GetLastHashrate() float64
	// GetStats returns the current miner stats
	GetStats() (Stats, error)
}

Miner defines the required behaviour to be implemented by a miner to work with the GUI

func CreateMiner

func CreateMiner(config Config) (Miner, error)

CreateMiner creates a supported miner from the given configuration

type ProcessingConfig

type ProcessingConfig struct {
	// Type of miner
	Type string `json:"type"`
	// Threads is the amount of CPU threads
	Threads uint16 `json:"threads"`
	// MaxThreads is the maximum threads as read by runtime.NumCPU
	MaxThreads uint16 `json:"max_threads"`
	// MaxUsage is the maximum CPU usage in percentage the miner should
	// attempt to use.
	// Currently only supported by xmrig CPU backend
	MaxUsage uint8 `json:"max_usage"`
}

ProcessingConfig holds the config for the miner's processing setup TODO: Right now this is only for CPU threads and will be extended into full CPU/GPU config

type Stats

type Stats struct {
	// Hashrate is the current miner hashrate
	Hashrate float64 `json:"hashrate"`
	// HashrateHuman is the H/s, KH/s or MH/s representation of hashrate
	HashrateHuman string `json:"hashrate_human"`
	// CurrentDifficulty as set by the pool
	CurrentDifficulty int `json:"current_difficulty"`
	// SharesGood is the good shares counter
	SharesGood int `json:"shares_good"`
	// SharesGood is the bad shares counter
	SharesBad int `json:"shares_bad"`
	// Uptime for the miner in seconds
	Uptime int `json:"uptime"`
	// UptimeHuman is the human readable version of uptime, ex. 10 minutes
	UptimeHuman string `json:"uptime_human"`
	// Errors is a list of errors that have occurred
	Errors []string `json:"errors"`
	// UpdateGraph is set to true if the stats graph should be updated
	UpdateGraph bool `json:"update_graph"`
	// Address contains the Lethean address we are mining to
	// TODO: This should be somewhere else, it's not stats!
	Address string `json:"address"`
}

Stats contains the miner statistics required by the front-end

type XmrStak

type XmrStak struct {
	Base
	// contains filtered or unexported fields
}

XmrStak implements the miner interface for the xmr-stak miner https://github.com/fireice-uk/xmr-stak

func NewXmrStak

func NewXmrStak(config Config) (*XmrStak, error)

NewXmrStak creates a new xmr-stak miner instance

func (*XmrStak) GetLastHashrate

func (miner *XmrStak) GetLastHashrate() float64

GetLastHashrate returns the last reported hashrate

func (*XmrStak) GetName

func (miner *XmrStak) GetName() string

GetName returns the name of the miner

func (*XmrStak) GetProcessingConfig

func (miner *XmrStak) GetProcessingConfig() ProcessingConfig

GetProcessingConfig returns the current miner processing config TODO: Currently only CPU threads, extend this to full CPU/GPU config

func (*XmrStak) GetStats

func (miner *XmrStak) GetStats() (Stats, error)

GetStats returns the current miner stats

func (*XmrStak) WriteConfig

func (miner *XmrStak) WriteConfig(
	poolEndpoint string,
	walletAddress string,
	processingConfig ProcessingConfig) error

WriteConfig writes the miner's configuration in the xmr-stak format

type XmrStakResponse

type XmrStakResponse struct {
	Version  string `json:"version"`
	Hashrate struct {
		Threads [][]interface{} `json:"threads"`
		Total   []float64       `json:"total"`
		Highest float64         `json:"highest"`
	} `json:"hashrate"`
	Results struct {
		DiffCurrent int     `json:"diff_current"`
		SharesGood  int     `json:"shares_good"`
		SharesTotal int     `json:"shares_total"`
		AvgTime     float64 `json:"avg_time"`
		HashesTotal int     `json:"hashes_total"`
		Best        []int   `json:"best"`
		ErrorLog    []struct {
			Count    int    `json:"count"`
			LastSeen int    `json:"last_seen"`
			Text     string `json:"text"`
		} `json:"error_log"`
	} `json:"results"`
	Connection struct {
		Pool     string `json:"pool"`
		Uptime   int    `json:"uptime"`
		Ping     int    `json:"ping"`
		ErrorLog []struct {
			LastSeen int    `json:"last_seen"`
			Text     string `json:"text"`
		} `json:"error_log"`
	} `json:"connection"`
}

XmrStakResponse contains the data from xmr-stak API Generated with https://mholt.github.io/json-to-go/

type Xmrig

type Xmrig struct {
	Base
	// contains filtered or unexported fields
}

Xmrig implements the miner interface for the xmrig miner, including xmrig-amd and xmrig-nvidia https://github.com/xmrig/xmrig https://github.com/xmrig/xmrig-amd https://github.com/xmrig/xmrig-nvidia

func NewXmrig

func NewXmrig(config Config) (*Xmrig, error)

NewXmrig creates a new xmrig miner instance

func (*Xmrig) GetLastHashrate

func (miner *Xmrig) GetLastHashrate() float64

GetLastHashrate returns the last reported hashrate

func (*Xmrig) GetName

func (miner *Xmrig) GetName() string

GetName returns the name of the miner

func (*Xmrig) GetProcessingConfig

func (miner *Xmrig) GetProcessingConfig() ProcessingConfig

GetProcessingConfig returns the current miner processing config TODO: Currently only CPU threads, extend this to full CPU/GPU config

func (*Xmrig) GetStats

func (miner *Xmrig) GetStats() (Stats, error)

GetStats returns the current miner stats

func (*Xmrig) WriteConfig

func (miner *Xmrig) WriteConfig(
	poolEndpoint string,
	walletAddress string,
	processingConfig ProcessingConfig) error

WriteConfig writes the miner's configuration in the xmrig format

type XmrigAPIConfig

type XmrigAPIConfig struct {
	Port        int         `json:"port"`
	AccessToken interface{} `json:"access-token"`
	WorkerID    interface{} `json:"worker-id"`
}

XmrigAPIConfig contains the Xmrig API config

type XmrigConfig

type XmrigConfig struct {
	Algo        string            `json:"algo"`
	Av          int               `json:"av"`
	Background  bool              `json:"background"`
	Colors      bool              `json:"colors"`
	CPUAffinity interface{}       `json:"cpu-affinity"`
	CPUPriority interface{}       `json:"cpu-priority"`
	DonateLevel int               `json:"donate-level"`
	LogFile     interface{}       `json:"log-file"`
	MaxCPUUsage uint8             `json:"max-cpu-usage"`
	PrintTime   int               `json:"print-time"`
	Retries     int               `json:"retries"`
	RetryPause  int               `json:"retry-pause"`
	Safe        bool              `json:"safe"`
	Syslog      bool              `json:"syslog"`
	Threads     uint16            `json:"threads"`
	Pools       []XmrigPoolConfig `json:"pools"`
	API         XmrigAPIConfig    `json:"api"`
}

XmrigConfig is the config.json structure for Xmrig Generated with https://mholt.github.io/json-to-go/

type XmrigGPUConfig

type XmrigGPUConfig struct {
	Algo        string      `json:"algo"`
	Av          int         `json:"av"`
	Background  bool        `json:"background"`
	Colors      bool        `json:"colors"`
	CPUAffinity interface{} `json:"cpu-affinity"`
	CPUPriority interface{} `json:"cpu-priority"`
	DonateLevel int         `json:"donate-level"`
	LogFile     interface{} `json:"log-file"`
	MaxCPUUsage uint8       `json:"max-cpu-usage"`
	PrintTime   int         `json:"print-time"`
	Retries     int         `json:"retries"`
	RetryPause  int         `json:"retry-pause"`
	Safe        bool        `json:"safe"`
	Syslog      bool        `json:"syslog"`
	// TODO: This is the only difference between GPU and CPU, the threads
	// structure in the config. I need to merge the the config structures into
	// one with an omitempty tag on each and only fill in the one needed
	Threads []struct{}        `json:"threads"`
	Pools   []XmrigPoolConfig `json:"pools"`
	API     XmrigAPIConfig    `json:"api"`
}

XmrigGPUConfig is the config.json structure for Xmrig's GPU Generated with https://mholt.github.io/json-to-go/

type XmrigPoolConfig

type XmrigPoolConfig struct {
	URL       string `json:"url"`
	User      string `json:"user"`
	Pass      string `json:"pass"`
	Keepalive bool   `json:"keepalive"`
	Nicehash  bool   `json:"nicehash"`
	Variant   string `json:"variant"`
}

XmrigPoolConfig contains the configuration for a pool in Xmrig

type XmrigResponse

type XmrigResponse struct {
	ID       string `json:"id"`
	WorkerID string `json:"worker_id"`
	Version  string `json:"version"`
	Kind     string `json:"kind"`
	Ua       string `json:"ua"`
	CPU      struct {
		Brand   string `json:"brand"`
		Aes     bool   `json:"aes"`
		X64     bool   `json:"x64"`
		Sockets int    `json:"sockets"`
	} `json:"cpu"`
	Algo        string `json:"algo"`
	Hugepages   bool   `json:"hugepages"`
	DonateLevel int    `json:"donate_level"`
	Hashrate    struct {
		Total   []float64   `json:"total"`
		Highest float64     `json:"highest"`
		Threads [][]float64 `json:"threads"`
	} `json:"hashrate"`
	Results struct {
		DiffCurrent int      `json:"diff_current"`
		SharesGood  int      `json:"shares_good"`
		SharesTotal int      `json:"shares_total"`
		AvgTime     int      `json:"avg_time"`
		HashesTotal int      `json:"hashes_total"`
		Best        []int    `json:"best"`
		ErrorLog    []string `json:"error_log"`
	} `json:"results"`
	Connection struct {
		Pool     string   `json:"pool"`
		Uptime   int      `json:"uptime"`
		Ping     int      `json:"ping"`
		Failures int      `json:"failures"`
		ErrorLog []string `json:"error_log"`
	} `json:"connection"`
}

XmrigResponse contains the data from xmrig API Generated with https://mholt.github.io/json-to-go/

Jump to

Keyboard shortcuts

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