Documentation ¶
Overview ¶
Package pool is an implementation of the pool module, and is responsible for creating a mining pool, accepting incoming potential block solutions and rewarding the submitters proportionally for their shares.
Index ¶
- Constants
- Variables
- func BigToCompact(n *big.Int) uint32
- func ReadMerkleBranches(b types.Block) []string
- type Client
- type ClientRecord
- type Dispatcher
- func (d *Dispatcher) AddHandler(conn net.Conn)
- func (d *Dispatcher) ClearJobAndNotifyClients()
- func (d *Dispatcher) IncrementConnectionsOpened()
- func (d *Dispatcher) ListenHandlers(port string)
- func (d *Dispatcher) NotifyClients()
- func (d *Dispatcher) NumConnections() int
- func (d *Dispatcher) NumConnectionsOpened() uint64
- type Handler
- type Job
- type Pool
- func (p *Pool) AddClient(c *Client)
- func (p *Pool) AddClientDB(c *Client) error
- func (p *Pool) Client(name string) *Client
- func (p *Pool) Close() error
- func (p *Pool) DeleteAllWorkerRecords() error
- func (p *Pool) FindClientDB(name string) (*Client, error)
- func (p *Pool) InternalSettings() modules.PoolInternalSettings
- func (p *Pool) NumConnections() int
- func (p *Pool) NumConnectionsOpened() uint64
- func (p *Pool) ProcessConsensusChange(cc modules.ConsensusChange)
- func (p *Pool) ReceiveUpdatedUnconfirmedTransactions(diff *modules.TransactionPoolDiff)
- func (p *Pool) SetInternalSettings(settings modules.PoolInternalSettings) error
- type Session
- func (s *Session) Authorized() bool
- func (s *Session) CurrentDifficulty() float64
- func (s *Session) DetectDisconnected() bool
- func (s *Session) HighestDifficulty() float64
- func (s *Session) IsStable() bool
- func (s *Session) SetAuthorized(b bool)
- func (s *Session) SetClientVersion(v string)
- func (s *Session) SetCurrentDifficulty(d float64)
- func (s *Session) SetDisableVarDiff(flag bool)
- func (s *Session) SetHeartbeat()
- func (s *Session) SetHighestDifficulty(d float64)
- func (s *Session) SetLastShareTimestamp(t time.Time)
- func (s *Session) ShareDurationAverage() (float64, float64)
- func (s *Session) Shift() *Shift
- type Share
- type Shift
- func (s *Shift) IncrementInvalid()
- func (s *Shift) IncrementShares(share *Share)
- func (s *Shift) LastShareTime() time.Time
- func (s *Shift) PoolID() uint64
- func (s *Shift) SaveShift() error
- func (s *Shift) SetLastShareTime(t time.Time)
- func (s *Shift) Shares() []Share
- func (s *Shift) ShiftID() uint64
- func (s *Shift) StartShiftTime() time.Time
- type Vardiff
- type Worker
- func (w *Worker) CurrentDifficulty() float64
- func (w *Worker) IncrementInvalidShares()
- func (w *Worker) IncrementShares(sessionDifficulty float64, reward float64)
- func (w *Worker) LastShareTime() time.Time
- func (w *Worker) Name() string
- func (w *Worker) Online() bool
- func (w *Worker) Parent() *Client
- func (w *Worker) Session() *Session
- func (w *Worker) SetLastShareTime(t time.Time)
- func (w *Worker) SetName(n string)
- func (w *Worker) SetParent(p *Client)
- func (w *Worker) SetSession(s *Session)
- type WorkerRecord
Constants ¶
const ( // MajorVersion is the significant version of the pool module MajorVersion = 0 // MinorVersion is the minor version of the pool module MinorVersion = 3 // SiaCoinID is the coin id used by yiimp to associate various records // with Siacoin SiaCoinID = 1318 // SiaCoinSymbol is the coin symbol used by yiimp to associate various records // with Siacoin SiaCoinSymbol = "SCP" // SiaCoinAlgo is the algo used by yiimp to associate various records // with blake2b mining SiaCoinAlgo = "blake2b" )
Variables ¶
var ( // ErrDuplicateUserInDifferentCoin is an error when a address used in // different coin ErrDuplicateUserInDifferentCoin = errors.New("duplicate user in different coin, you need use a different address") // ErrNoUsernameInDatabase is an error when can't find a username in db ErrNoUsernameInDatabase = errors.New("user is not found in db") // ErrCreateClient is an error when can't create a new client ErrCreateClient = errors.New("Error when creating a new client") )
var ( // HeaderMemory is the number of previous calls to 'header' // that are remembered. Additionally, 'header' will only poll for a // new block every 'headerMemory / blockMemory' times it is // called. This reduces the amount of memory used, but comes at the cost of // not always having the most recent transactions. HeaderMemory = build.Select(build.Var{ Standard: 10000, Dev: 500, Testing: 50, }).(int) // BlockMemory is the maximum number of blocks the miner will store // Blocks take up to 2 megabytes of memory, which is why this number is // limited. BlockMemory = build.Select(build.Var{ Standard: 50, Dev: 10, Testing: 5, }).(int) // MaxSourceBlockAge is the maximum amount of time that is allowed to // elapse between generating source blocks. MaxSourceBlockAge = build.Select(build.Var{ Standard: 30 * time.Second, Dev: 5 * time.Second, Testing: 1 * time.Second, }).(time.Duration) // ShiftDuration is how often we commit mining data to persistent // storage when a block hasn't been found. ShiftDuration = build.Select(build.Var{ Standard: 20 * time.Second, Dev: 20 * time.Second, Testing: 1 * time.Second, }).(time.Duration) )
Functions ¶
func BigToCompact ¶
BigToCompact converts a whole number N to a compact representation using an unsigned 32-bit number. The compact representation only provides 23 bits of precision, so values larger than (2^23 - 1) only encode the most significant digits of the number. See CompactToBig for details.
func ReadMerkleBranches ¶ added in v1.5.0
ReadMerkleBranches returns the merkle branches of a block, as used in stratum mining.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
A Client represents a user and may have one or more workers associated with it. It is primarily used for accounting and statistics.
func (*Client) SetWallet ¶
func (c *Client) SetWallet(w types.UnlockHash)
SetWallet sets the unlockhash associated with the client
func (*Client) Wallet ¶
func (c *Client) Wallet() *types.UnlockHash
Wallet returns the unlockhash associated with the client
type ClientRecord ¶
type ClientRecord struct {
// contains filtered or unexported fields
}
A ClientRecord represents the persistent data portion of the Client record
type Dispatcher ¶
type Dispatcher struct {
// contains filtered or unexported fields
}
Dispatcher contains a map of ip addresses to handlers
func (*Dispatcher) AddHandler ¶
func (d *Dispatcher) AddHandler(conn net.Conn)
AddHandler connects the incoming connection to the handler which will handle it
func (*Dispatcher) ClearJobAndNotifyClients ¶
func (d *Dispatcher) ClearJobAndNotifyClients()
ClearJobAndNotifyClients clear all stale jobs and tells the dispatcher to notify all clients that the block has changed
func (*Dispatcher) IncrementConnectionsOpened ¶
func (d *Dispatcher) IncrementConnectionsOpened()
IncrementConnectionsOpened increments the number of tcp connections that the pool has ever opened
func (*Dispatcher) ListenHandlers ¶
func (d *Dispatcher) ListenHandlers(port string)
ListenHandlers listens on a passed port and upon accepting the incoming connection, adds the handler to deal with it
func (*Dispatcher) NotifyClients ¶
func (d *Dispatcher) NotifyClients()
NotifyClients tells the dispatcher to notify all clients that the block has changed
func (*Dispatcher) NumConnections ¶
func (d *Dispatcher) NumConnections() int
NumConnections returns the number of open tcp connections
func (*Dispatcher) NumConnectionsOpened ¶
func (d *Dispatcher) NumConnectionsOpened() uint64
NumConnectionsOpened returns the number of tcp connections that the pool has ever opened
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler represents the status (open/closed) of each connection
type Job ¶
type Job struct { JobID uint64 MarshalledBlock []byte MerkleRoot crypto.Hash SubmitedNonce map[string]bool }
A Job in the stratum server is a unit of work which is passed to the client miner to solve. It is primarily identified by a Job ID and this is used to keep track of what work has been assigned to each client
type Pool ¶
type Pool struct { modules.StorageManager // contains filtered or unexported fields }
A Pool contains all the fields necessary for storing status for clients and performing the evaluation and rewarding on submitted shares
func New ¶
func New(cs modules.ConsensusSet, tpool modules.TransactionPool, gw modules.Gateway, wallet modules.Wallet, persistDir string, initConfig config.MiningPoolConfig) (*Pool, error)
New returns an initialized Pool.
func (*Pool) AddClientDB ¶
AddClientDB add user into accounts
func (*Pool) Client ¶
Client returns the client with the specified name that has been stored in memory
func (*Pool) DeleteAllWorkerRecords ¶
DeleteAllWorkerRecords deletes all worker records associated with a pool. This should be used on pool startup and shutdown to ensure the database is clean and isn't storing any worker records for non-connected workers.
func (*Pool) FindClientDB ¶
FindClientDB find user in accounts
func (*Pool) InternalSettings ¶
func (p *Pool) InternalSettings() modules.PoolInternalSettings
InternalSettings returns the settings of a pool.
func (*Pool) NumConnections ¶
NumConnections returns the number of tcp connections from clients the pool currently has open
func (*Pool) NumConnectionsOpened ¶
NumConnectionsOpened returns the total number of tcp connections from clients the pool has opened since startup
func (*Pool) ProcessConsensusChange ¶
func (p *Pool) ProcessConsensusChange(cc modules.ConsensusChange)
ProcessConsensusChange will update the pool's most recent block.
func (*Pool) ReceiveUpdatedUnconfirmedTransactions ¶
func (p *Pool) ReceiveUpdatedUnconfirmedTransactions(diff *modules.TransactionPoolDiff)
ReceiveUpdatedUnconfirmedTransactions will replace the current unconfirmed set of transactions with the input transactions.
func (*Pool) SetInternalSettings ¶
func (p *Pool) SetInternalSettings(settings modules.PoolInternalSettings) error
SetInternalSettings updates the pool's internal PoolInternalSettings object.
type Session ¶
type Session struct { SessionID uint64 CurrentJobs []*Job Client *Client CurrentWorker *Worker CurrentShift *Shift ExtraNonce1 uint32 // contains filtered or unexported fields }
A Session captures the interaction with a miner client from when they connect until the connection is closed. A session is tied to a single client and has many jobs associated with it
func (*Session) Authorized ¶
Authorized returns whether or not the session has been authorized
func (*Session) CurrentDifficulty ¶
CurrentDifficulty returns the session's current difficulty
func (*Session) DetectDisconnected ¶
DetectDisconnected checks to see if we haven't heard from a client for too long of a time. It does this via 2 mechanisms:
- how long ago was the last share submitted? (the hearbeat)
- how low has the difficulty dropped from the highest difficulty the client ever faced?
func (*Session) HighestDifficulty ¶
HighestDifficulty returns the highest difficulty the session has seen
func (*Session) IsStable ¶
IsStable checks if the session has been running long enough to fill up the vardiff buffer
func (*Session) SetAuthorized ¶
SetAuthorized specifies whether or not the session has been authorized
func (*Session) SetClientVersion ¶
SetClientVersion sets the current client version for the session
func (*Session) SetCurrentDifficulty ¶
SetCurrentDifficulty sets the current difficulty for the session
func (*Session) SetDisableVarDiff ¶
SetDisableVarDiff sets the disable var diff flag for the session
func (*Session) SetHeartbeat ¶
func (s *Session) SetHeartbeat()
SetHeartbeat indicates that we just received a share submission
func (*Session) SetHighestDifficulty ¶
SetHighestDifficulty records the highest difficulty the session has seen
func (*Session) SetLastShareTimestamp ¶
SetLastShareTimestamp add a new time stamp
func (*Session) ShareDurationAverage ¶
ShareDurationAverage caculate the average duration of the
type Share ¶
type Share struct {
// contains filtered or unexported fields
}
A Share is how we track each worker's submissions and their difficulty
type Shift ¶
type Shift struct {
// contains filtered or unexported fields
}
A Shift is a period over which a worker submits shares. At the end of the period, we record those shares into the database.
func (*Shift) IncrementInvalid ¶
func (s *Shift) IncrementInvalid()
IncrementInvalid marks a share as having been invalid
func (*Shift) IncrementShares ¶
IncrementShares adds a new share to the slice of shares processed during the shift
func (*Shift) LastShareTime ¶
LastShareTime returns the most recent time a share was submitted during this shift
func (*Shift) PoolID ¶
PoolID returns the pool's unique ID. Multiple stratum servers connecting to the same database should use unique ids so that workers can be tracked as belonging to which server.
func (*Shift) SetLastShareTime ¶
SetLastShareTime specifies the most recent time a share was submitted during this shift
func (*Shift) StartShiftTime ¶
StartShiftTime returns the time this shift started
type Vardiff ¶
type Vardiff struct {
// contains filtered or unexported fields
}
Vardiff is a structure representing maximum and minimum share submission times, along with the size of the buffer over which share submission times should be monitored
type Worker ¶
type Worker struct {
// contains filtered or unexported fields
}
A Worker is an instance of one miner. A Client often represents a user and the worker represents a single miner. There is a one to many client worker relationship
func (*Worker) CurrentDifficulty ¶
CurrentDifficulty returns the average difficulty of all instances of this worker
func (*Worker) IncrementInvalidShares ¶
func (w *Worker) IncrementInvalidShares()
IncrementInvalidShares adds a record of an invalid share submission
func (*Worker) IncrementShares ¶
IncrementShares creates a new share according to current session difficulty for the worker to work on
func (*Worker) LastShareTime ¶
LastShareTime returns the last time a share was submitted during the current shift
func (*Worker) SetLastShareTime ¶
SetLastShareTime specifies the last time a share was submitted during the current shift
func (*Worker) SetSession ¶
SetSession sets the tcp session associated with the worker
type WorkerRecord ¶
type WorkerRecord struct {
// contains filtered or unexported fields
}
A WorkerRecord is used to track worker information in memory