stratumminer

package
v1.9.1 Latest Latest
Warning

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

Go to latest
Published: May 20, 2024 License: MIT, BSD-2-Clause Imports: 26 Imported by: 0

Documentation

Overview

Package stratumminer provides some utilities and common code for specific client implementations

Package stratumminer is responsible for finding valid block headers and submitting them to a stratum server

Package stratumminer implements the basic stratum protocol. This is normal jsonrpc but the go standard library is insufficient since we need features like notifications.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseClient

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

BaseClient implements some common properties and functionality

func (*BaseClient) AddJobToDeprecate

func (sc *BaseClient) AddJobToDeprecate(jobid string)

AddJobToDeprecate add the jobid to the list of jobs that should be deprecated when the times comes

func (*BaseClient) DeprecateOutstandingJobs

func (sc *BaseClient) DeprecateOutstandingJobs()

DeprecateOutstandingJobs closes all deprecationChannels and removes them from the list This method is not threadsafe

func (*BaseClient) GetDeprecationChannel

func (sc *BaseClient) GetDeprecationChannel(jobid string) chan bool

GetDeprecationChannel return the channel that will be closed when a job gets deprecated

func (*BaseClient) SetDeprecatedJobCall

func (sc *BaseClient) SetDeprecatedJobCall(call DeprecatedJobCall)

SetDeprecatedJobCall sets the function to be called when the previous jobs should be abandoned

type DeprecatedJobCall

type DeprecatedJobCall func()

DeprecatedJobCall is a function that can be registered on a client to be executed when the server indicates that all previous jobs should be abandoned

type ErrorCallback

type ErrorCallback func(err error)

ErrorCallback is the type of function that be registered to be notified of errors requiring a client to be dropped and a new one to be created

type GenericClient

type GenericClient interface {
	HeaderProvider
	HeaderReporter
	// Start connects to a sia daemon and starts supplying valid headers
	// It can be empty in case of a "getwork" implementation or maintain a tcp connection
	// in case of stratum for example
	Start()
	// Stop disconnects
	Stop()
	// Connected specifies if we're connected or not
	Connected() bool
	// SetDeprecatedJobCall sets the function to be called when the previous jobs should be
	// abandoned
	SetDeprecatedJobCall(call DeprecatedJobCall)
}

GenericClient defines the interface for a client towards a work provider

func NewClient

func NewClient(connectionstring, pooluser string) (sc GenericClient)

NewClient creates a new client given a '[stratum+tcp://]host:port' connectionstring

type HeaderProvider

type HeaderProvider interface {
	// GetHeaderForWork providers a header to mine on
	// the deprecationChannel is closed when the job should be abandoned
	GetHeaderForWork() (target, header []byte, deprecationChannel chan bool, job interface{}, err error)
}

HeaderProvider supplies headers for a miner to mine on

type HeaderReporter

type HeaderReporter interface {
	//SubmitHeader reports a solved header
	SubmitHeader(header []byte, job interface{}) (err error)
}

HeaderReporter defines the required method a SIA client or pool client should implement for miners to be able to report solved headers

type NotificationHandler

type NotificationHandler func(args []interface{})

NotificationHandler is the signature for a function that handles notifications

type SiadClient

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

SiadClient is a simple client to a spd

func (*SiadClient) Connected

func (sc *SiadClient) Connected() bool

Connected is always true if we're using a local node

func (*SiadClient) GetHeaderForWork

func (sc *SiadClient) GetHeaderForWork() (target []byte, header []byte, deprecationChannel chan bool, job interface{}, err error)

GetHeaderForWork fetches new work from the SIA daemon

func (*SiadClient) SetDeprecatedJobCall

func (sc *SiadClient) SetDeprecatedJobCall(call DeprecatedJobCall)

SetDeprecatedJobCall does nothing

func (*SiadClient) Start

func (sc *SiadClient) Start()

Start does nothing

func (*SiadClient) Stop

func (sc *SiadClient) Stop()

Stop does nothing

func (*SiadClient) SubmitHeader

func (sc *SiadClient) SubmitHeader(header []byte, job interface{}) (err error)

SubmitHeader reports a solved header to the SIA daemon

type StratumClient

type StratumClient struct {
	User string

	BaseClient
	// contains filtered or unexported fields
}

StratumClient is a sia client using the stratum protocol

func (*StratumClient) Connected

func (sc *StratumClient) Connected() bool

Connected returns whether or not the stratumclient has an open tcp connection

func (*StratumClient) GetHeaderForWork

func (sc *StratumClient) GetHeaderForWork() (target, header []byte, deprecationChannel chan bool, job interface{}, err error)

GetHeaderForWork fetches new work from the SIA daemon

func (*StratumClient) RestartOnError

func (sc *StratumClient) RestartOnError(err error)

RestartOnError closes the old tcpclient and starts the process of opening a new tcp connection

func (*StratumClient) Start

func (sc *StratumClient) Start()

Start connects to the stratumserver and processes the notifications

func (*StratumClient) Stop

func (sc *StratumClient) Stop()

Stop shuts down the stratumclient and closes the tcp connection

func (*StratumClient) SubmitHeader

func (sc *StratumClient) SubmitHeader(header []byte, job interface{}) (err error)

SubmitHeader reports a solution to the stratum server

func (*StratumClient) SubscribeAndAuthorize

func (sc *StratumClient) SubscribeAndAuthorize()

SubscribeAndAuthorize first attempts to authorize and, if successful, subscribes

type StratumMiner

type StratumMiner struct {
	HashRateReports chan float64

	Client GenericClient
	// contains filtered or unexported fields
}

StratumMiner does the actual stratum mining

func New

func New(persistDir string) (*StratumMiner, error)

New returns a new StratumMiner

func (*StratumMiner) Close

func (sm *StratumMiner) Close() error

Close is called when the module is shutting down and shuts down the miner

func (*StratumMiner) Connected

func (sm *StratumMiner) Connected() bool

Connected returns whether or not the miner has an open tcp connection to the stratum server

func (*StratumMiner) Hashrate

func (sm *StratumMiner) Hashrate() float64

Hashrate returns the miner's hashrate

func (*StratumMiner) Mining

func (sm *StratumMiner) Mining() bool

Mining returns whether or not the miner is both connected and hashing

func (*StratumMiner) StartStratumMining

func (sm *StratumMiner) StartStratumMining(server, username string)

StartStratumMining spins off two goroutines: One listens for work via a tcp connection and pushes it into a work channel The other waits for work from the channel and then grinds on it and submits solutions

func (*StratumMiner) StopStratumMining

func (sm *StratumMiner) StopStratumMining()

StopStratumMining tells the miner to stop mining

func (*StratumMiner) Submissions

func (sm *StratumMiner) Submissions() uint64

Submissions returns the count of submissions submitted by the miner

type TcpClient

type TcpClient struct {
	ErrorCallback ErrorCallback
	// contains filtered or unexported fields
}

TcpClient maintains a connection to the stratum server and (de)serializes requests/reponses/notifications

func (*TcpClient) Call

func (c *TcpClient) Call(serviceMethod string, args []string) (reply interface{}, err error)

Call invokes the named function, waits for it to complete, and returns its error status.

func (*TcpClient) Close

func (c *TcpClient) Close()

Close releases the tcp connection

func (*TcpClient) Connected

func (c *TcpClient) Connected() bool

Connected returns whether or not the tcp client has an open tcp socket

func (*TcpClient) Dial

func (c *TcpClient) Dial(host string) (err error)

Dial connects to a stratum+tcp at the specified network address. This function is not threadsafe If an error occurs, it is both returned here and through the ErrorCallback of the TcpClient

func (*TcpClient) Listen

func (c *TcpClient) Listen()

Listen reads data from the open connection, deserializes it and dispatches the reponses and notifications This is a blocking function and will continue to listen until an error occurs (io or deserialization)

func (*TcpClient) SetNotificationHandler

func (c *TcpClient) SetNotificationHandler(method string, handler NotificationHandler)

SetNotificationHandler registers a function to handle notification for a specific method. This function is not threadsafe and all notificationhandlers should be set prior to calling the Dial function

Jump to

Keyboard shortcuts

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