Documentation ¶
Index ¶
- Constants
- Variables
- func AcceptedWorkID(blockHash string, blockHeight uint32) []byte
- func AccountID(address string) (string, error)
- func DifficultyToTarget(net *chaincfg.Params, difficulty *big.Int) (*big.Int, error)
- func DisableLog()
- func GenerateBlockHeader(blockVersionE string, prevBlockE string, genTx1E string, extraNonce1E string, ...) (*wire.BlockHeader, error)
- func GenerateJobID(height uint32) (string, error)
- func GeneratePaymentID(createdOnNano int64, height uint32, account string) []byte
- func GenerateSolvedBlockHeader(headerE string, extraNonce1E string, extraNonce2E string, nTimeE string, ...) (*wire.BlockHeader, error)
- func IsError(err error, code ErrorCode) bool
- func PPLNSSharePercentages(db *bolt.DB, poolFee float64, height uint32, periodSecs uint32) (map[string]*big.Rat, error)
- func PPSSharePercentages(db *bolt.DB, poolFee float64, height uint32) (map[string]*big.Rat, error)
- func ParseAuthorizeRequest(req *Request) (string, error)
- func ParseSetDifficultyNotification(req *Request) (uint64, error)
- func ParseSubmitWorkRequest(req *Request, miner string) (string, string, string, string, string, error)
- func ParseSubscribeRequest(req *Request) (string, string, error)
- func ParseSubscribeResponse(resp *Response) (string, string, string, uint64, error)
- func ParseWorkNotification(req *Request) (string, string, string, string, string, string, string, bool, error)
- func PayPerLastNShares(db *bolt.DB, amount hcutil.Amount, poolFee float64, height uint32, ...) error
- func PayPerShare(db *bolt.DB, total hcutil.Amount, poolFee float64, height uint32, ...) error
- func PruneAcceptedWork(db *bolt.DB, height uint32) error
- func PruneJobs(db *bolt.DB, height uint32) error
- func PruneShares(db *bolt.DB, minNano int64) error
- func UseLogger(logger slog.Logger)
- type AcceptedWork
- type Account
- type Client
- type ClientInfo
- type DifficultyData
- type Error
- type ErrorCode
- type Hub
- func (h *Hub) AccountExists(accountID string) bool
- func (h *Hub) BackupDB(w http.ResponseWriter) error
- func (h *Hub) CSRFSecret(getCSRF func() ([]byte, error)) ([]byte, error)
- func (h *Hub) FetchAccountClientInfo(accountID string) []*ClientInfo
- func (h *Hub) FetchClientInfo() map[string][]*ClientInfo
- func (h *Hub) FetchLastPaymentHeight() uint32
- func (h *Hub) FetchLastWorkHeight() uint32
- func (h *Hub) FetchMinedWork() ([]*AcceptedWork, error)
- func (h *Hub) FetchMinedWorkByAddress(id string) ([]*AcceptedWork, error)
- func (h *Hub) FetchPaymentsForAddress(id string) ([]*Payment, error)
- func (h *Hub) FetchPoolHashRate() (*big.Rat, map[string][]*ClientInfo)
- func (h *Hub) FetchWorkQuotas() ([]*Quota, error)
- func (h *Hub) GetWork() (string, string, error)
- func (h *Hub) HasClients() bool
- func (h *Hub) PublishTransaction(payouts map[hcutil.Address]hcutil.Amount, targetAmt hcutil.Amount) (string, error)
- func (h *Hub) Run(ctx context.Context)
- func (h *Hub) SubmitWork(data *string) (bool, error)
- type HubConfig
- type Job
- type Message
- type Payment
- func CalculatePayments(percentages map[string]*big.Rat, total hcutil.Amount, poolFee float64, ...) ([]*Payment, error)
- func FetchMaturePendingPayments(db *bolt.DB, height uint32) ([]*Payment, error)
- func FetchPendingPayments(db *bolt.DB) ([]*Payment, error)
- func FetchPendingPaymentsAtHeight(db *bolt.DB, height uint32) ([]*Payment, error)
- func GetPayment(db *bolt.DB, id []byte) (*Payment, error)
- func NewPayment(account string, amount hcutil.Amount, height uint32, estMaturity uint32) *Payment
- type PaymentBundle
- type Quota
- type RateLimiter
- type Request
- func AuthorizeRequest(id *uint64, name string, address string) *Request
- func NewRequest(id *uint64, method string, params interface{}) *Request
- func SetDifficultyNotification(difficulty *big.Int) *Request
- func SubmitWorkRequest(id *uint64, workerName string, jobID string, extraNonce2 string, nTime string, ...) *Request
- func SubscribeRequest(id *uint64, userAgent string, version string, notifyID string) *Request
- func WorkNotification(jobID string, prevBlock string, genTx1 string, genTx2 string, ...) *Request
- type Response
- func AuthorizeResponse(id uint64, status bool, err *StratumError) *Response
- func NewResponse(id uint64, result interface{}, err *StratumError) *Response
- func SubmitWorkResponse(id uint64, status bool, err *StratumError) *Response
- func SubscribeResponse(id uint64, notifyID string, extraNonce1 string, extraNonce2Size int, ...) *Response
- type Share
- type StratumError
Constants ¶
const ( // MaxReorgLimit is an estimated maximum chain reorganization limit. // That is, it is highly improbable for the the chain to reorg beyond six // blocks from the chain tip. MaxReorgLimit = 6 CPU = "cpu" InnosiliconD9 = "innosilicond9" AntminerDR3 = "antminerdr3" AntminerDR5 = "antminerdr5" WhatsminerD1 = "whatsminerd1" )
const ( // apiClient represents an api client. APIClient = "api" // poolClient represents a pool client. PoolClient = "pool" )
const ( RequestType = "request" ResponseType = "response" NotificationType = "notification" )
Message types.
const ( Authorize = "mining.authorize" Subscribe = "mining.subscribe" SetDifficulty = "mining.set_difficulty" Notify = "mining.notify" Submit = "mining.submit" )
Handler types.
const ( Unknown = 20 StaleJob = 21 NotSubscribed = 25 )
Error codes.
const ( // DBVersion is the latest version of the database that is understood by the // program. Databases with recorded versions higher than this will fail to // open (meaning any upgrades prevent reverting to older software). DBVersion = transactionIDVersion )
const (
ExtraNonce2Size = 4
)
Stratum constants.
const ( // MaxMessageSize represents the maximum size of a transmitted message // allowed, in bytes. MaxMessageSize = 250 )
Variables ¶
var ( // ZeroInt is the default value for a big.Int. ZeroInt = new(big.Int).SetInt64(0) // ZeroRat is the default value for a big.Rat. ZeroRat = new(big.Rat).SetInt64(0) )
var ( // PPS represents the pay per share payment method. PPS = "pps" // PPLNS represents the pay per last n shares payment method. PPLNS = "pplns" )
new(big.Rat).SetFloat64(1.0), InnosiliconD9: new(big.Rat).SetFloat64(2.182), AntminerDR3: new(big.Rat).SetFloat64(7.091), AntminerDR5: new(big.Rat).SetFloat64(31.181), WhatsminerD1: new(big.Rat).SetFloat64(43.636), }CPU:
ShareWeights reprsents the associated weights for each known DCR miner. With the share weight of the lowest hash DCR miner (LHM) being 1, the rest were calculated as :
(Hash of Miner X * Weight of LHM)/ Hash of LHM
Functions ¶
func AcceptedWorkID ¶
AcceptedWorkID generates a unique id for the work accepted by the network.
func DifficultyToTarget ¶
DifficultyToTarget converts the provided difficulty to a target based on the active network.
func DisableLog ¶
func DisableLog()
DisableLog disables all library log output. Logging output is disabled by default until UseLogger is called.
func GenerateBlockHeader ¶
func GenerateBlockHeader(blockVersionE string, prevBlockE string, genTx1E string, extraNonce1E string, genTx2E string) (*wire.BlockHeader, error)
GenerateBlockHeader creates a block header from a mining.notify message and the extraNonce1 of the client.
func GenerateJobID ¶
GenerateJobID generates a unique job id of the provided block height.
func GeneratePaymentID ¶
GeneratePaymentID generates a unique id using the provided account and the created on nano time.
func GenerateSolvedBlockHeader ¶
func GenerateSolvedBlockHeader(headerE string, extraNonce1E string, extraNonce2E string, nTimeE string, nonceE string, miner string) (*wire.BlockHeader, error)
GenerateSolvedBlockHeader create a block header from a mining.submit message and its associated job.
func PPLNSSharePercentages ¶
func PPLNSSharePercentages(db *bolt.DB, poolFee float64, height uint32, periodSecs uint32) (map[string]*big.Rat, error)
PPLNSSharePercentages computes the current mining reward percentages due pool accounts based on work performed measured by the PPLNS payment scheme.
func PPSSharePercentages ¶
PPLNSSharePercentages computes the current mining reward percentages due pool accounts based on work performed measured by the PPS payment scheme.
func ParseAuthorizeRequest ¶
ParseAuthorizeRequest resolves an authorize request into its components.
func ParseSetDifficultyNotification ¶
ParseSetDifficultyNotification resolves a set difficulty notification into its components.
func ParseSubmitWorkRequest ¶
func ParseSubmitWorkRequest(req *Request, miner string) (string, string, string, string, string, error)
ParseSubmitWorkRequest resolves a submit work request into its components.
func ParseSubscribeRequest ¶
ParseSubscribeRequest resolves a subscribe request into its components.
func ParseSubscribeResponse ¶
ParseSubscribeResponse resolves a subscribe response into its components.
func ParseWorkNotification ¶
func ParseWorkNotification(req *Request) (string, string, string, string, string, string, string, bool, error)
ParseWorkNotification resolves a work notification message into its components.
func PayPerLastNShares ¶
func PayPerLastNShares(db *bolt.DB, amount hcutil.Amount, poolFee float64, height uint32, coinbaseMaturity uint16, periodSecs uint32) error
PayPerLastNShares generates a payment bundle comprised of payments to all participating accounts within the last n time period provided.
func PayPerShare ¶
func PayPerShare(db *bolt.DB, total hcutil.Amount, poolFee float64, height uint32, coinbaseMaturity uint16) error
PayPerShare generates a payment bundle comprised of payments to all participating accounts. Payments are calculated based on work contributed to the pool since the last payment batch.
func PruneAcceptedWork ¶
PruneAcceptedWork removes all accepted work not confirmed as mined work with heights less than the provided height.
func PruneShares ¶
PruneShares removes invalidated shares from the db.
Types ¶
type AcceptedWork ¶
type AcceptedWork struct { UUID string `json:"uuid"` BlockHash string `json:"blockhash"` PrevHash string `json:"prevhash"` Height uint32 `json:"height"` MinedBy string `json:"minedby"` Miner string `json:"miner"` CreatedOn int64 `json:"createdon"` // An accepted work becomes mined work once it is confirmed by an incoming // work as the parent block it was built on. Confirmed bool `json:"confirmed"` }
AcceptedWork represents an accepted work submission to the network.
func FetchAcceptedWork ¶
func FetchAcceptedWork(db *bolt.DB, id []byte) (*AcceptedWork, error)
FetchAcceptedWork fetches the accepted work referenced by the provided id.
func ListMinedWork ¶
func ListMinedWork(db *bolt.DB, n int) ([]*AcceptedWork, error)
ListMinedWork returns the N most recent work data associated with blocks mined by the pool.
List is ordered, most recent comes first.
func NewAcceptedWork ¶
func NewAcceptedWork(blockHash string, prevHash string, height uint32, minedBy string, miner string) *AcceptedWork
NewAcceptedWork creates an accepted work instance.
func (*AcceptedWork) Create ¶
func (work *AcceptedWork) Create(db *bolt.DB) error
Create persists the accepted work to the database.
type Account ¶
type Account struct { UUID string `json:"uuid"` Address string `json:"address"` CreatedOn uint64 `json:"createdon"` }
Account represents a mining pool account.
func FetchAccount ¶
FetchAccount fetches the account referenced by the provided id.
func NewAccount ¶
NewAccount generates a new account.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client represents a client connection.
type DifficultyData ¶
type DifficultyData struct {
// contains filtered or unexported fields
}
DifficultyData captures the pool target difficulty and pool difficulty ratio of a mining client.
type Error ¶
Error extends the base error type by adding an error description and an error code.
The caller can use type assertions to determine if an error is an Error and access the ErrorCode field to ascertain the specific reason for the failure.
type ErrorCode ¶
type ErrorCode int
ErrorCode identifies a kind of error.
const ( // ErrValueNotFound indicates a key does not map to any value. ErrValueNotFound ErrorCode = iota // ErrValueNotFound indicates a bucket key does not map to a bucket. ErrBucketNotFound // ErrBucketCreate indicates bucket creation failed. ErrBucketCreate // ErrDBOpen indicates database open error. ErrDBOpen // ErrWorkExists indicates an already existing work. ErrWorkExists // ErrWorkNotFound indicates non-existent work. ErrWorkNotFound // ErrWrongInputLength indicates an incorrect input size. ErrWrongInputLength // ErrDifficultyNotFound indicates a non-existent miner pool difficulty. ErrDifficultyNotFound // ErrCalcPoolTarget indicates a pool target calculation error. ErrCalcPoolTarget // ErrParse indicates a message parsing error. ErrParse // ErrDecode indicates a decode error. ErrDecode // ErrNotSupported indicates not supported functionality. ErrNotSupported // ErrDivideByZero indicates a division by zero error. ErrDivideByZero // ErrDBUpgrade indicates a database upgrade error. ErrDBUpgrade // ErrOther indicates a miscellenious error. ErrOther )
These constants are used to identify a specific error.
type Hub ¶
type Hub struct {
// contains filtered or unexported fields
}
Hub maintains the set of active clients and facilitates message broadcasting to all active clients.
func NewHub ¶
func NewHub(ctx context.Context, cancel context.CancelFunc, httpc *http.Client, hcfg *HubConfig, limiter *RateLimiter) (*Hub, error)
NewHub initializes a websocket hub.
func (*Hub) AccountExists ¶
AccountExists asserts if the provided account id references a pool account.
func (*Hub) BackupDB ¶
func (h *Hub) BackupDB(w http.ResponseWriter) error
BackupDB streams a backup of the database over an http response.
func (*Hub) CSRFSecret ¶
CSRFSecret fetches a persisted secret or generates a new one.
func (*Hub) FetchAccountClientInfo ¶
func (h *Hub) FetchAccountClientInfo(accountID string) []*ClientInfo
FetchAccountClientInfo returns all clients belonging to the provided account id.
func (*Hub) FetchClientInfo ¶
func (h *Hub) FetchClientInfo() map[string][]*ClientInfo
FetchClientInfo returns connection details about all pool clients.
func (*Hub) FetchLastPaymentHeight ¶
FetchLastPaymentHeight returns the last height payments were made at.
func (*Hub) FetchLastWorkHeight ¶
FetchLastWorkHeight returns the last height work was generated for.
func (*Hub) FetchMinedWork ¶
func (h *Hub) FetchMinedWork() ([]*AcceptedWork, error)
FetchMinedWork returns the last ten mined blocks by the pool.
func (*Hub) FetchMinedWorkByAddress ¶
func (h *Hub) FetchMinedWorkByAddress(id string) ([]*AcceptedWork, error)
FetchMinedWorkByAddress returns a list of mined work by the provided address. List is ordered, most recent comes first.
func (*Hub) FetchPaymentsForAddress ¶
FetchPaymentsForAddress returns a list or payments made to the provided address. List is ordered, most recent comes first.
func (*Hub) FetchPoolHashRate ¶
func (h *Hub) FetchPoolHashRate() (*big.Rat, map[string][]*ClientInfo)
FetchPoolHashRate returns the hash rate of the pool.
func (*Hub) FetchWorkQuotas ¶
FetchWorkQuotas returns the reward distribution to pool accounts based on work contributed per the peyment scheme used by the pool.
func (*Hub) HasClients ¶
HasClients asserts the mining pool has clients.
func (*Hub) PublishTransaction ¶
func (h *Hub) PublishTransaction(payouts map[hcutil.Address]hcutil.Amount, targetAmt hcutil.Amount) (string, error)
PublishTransaction creates a transaction paying pool accounts for work done.
type HubConfig ¶
type HubConfig struct { ActiveNet *chaincfg.Params DcrdRPCCfg *rpcclient.ConnConfig PoolFee float64 MaxTxFeeReserve hcutil.Amount MaxGenTime uint64 WalletRPCCertFile string WalletGRPCHost string PaymentMethod string LastNPeriod uint32 WalletPass string MinPayment hcutil.Amount DBFile string SoloPool bool PoolFeeAddrs []hcutil.Address BackupPass string Secret string NonceIterations float64 MinerPorts map[string]uint32 MaxConnectionsPerHost uint32 }
HubConfig represents configuration details for the hub.
type Job ¶
type Job struct { UUID string `json:"uuid"` Height uint32 `json:"height"` Header string `json:"header"` }
Job represents cached copies of work delivered to clients.
type Payment ¶
type Payment struct { Account string `json:"account"` EstimatedMaturity uint32 `json:"estimatedmaturity"` Height uint32 `json:"height"` Amount hcutil.Amount `json:"amount"` CreatedOn int64 `json:"createdon"` PaidOnHeight uint32 `json:"paidonheight"` TransactionID string `json:"transactionid"` }
Payment represents an outstanding payment for a pool account.
func CalculatePayments ¶
func CalculatePayments(percentages map[string]*big.Rat, total hcutil.Amount, poolFee float64, height uint32, estMaturity uint32) ([]*Payment, error)
CalculatePayments calculates the payments due participating accounts.
func FetchMaturePendingPayments ¶
FetchMaturePendingPayments fetches all payments past their estimated maturities which have not been paid yet.
func FetchPendingPayments ¶
FetchPendingPayments fetches all unpaid payments.
func FetchPendingPaymentsAtHeight ¶
FetchPendingPaymentsAtHeight fetches all pending payments at the provided height.
func GetPayment ¶
GetPayment fetches the payment referenced by the provided id.
func NewPayment ¶
NewPayment creates a payment instance.
type PaymentBundle ¶
PaymentBundle is a convenience type for grouping payments for an account.
func FetchEligiblePaymentBundles ¶
func FetchEligiblePaymentBundles(db *bolt.DB, height uint32, minPayment hcutil.Amount) ([]*PaymentBundle, error)
FetchEligiblePaymentBundles fetches payment bundles greater than the configured minimum payment.
func (*PaymentBundle) ArchivePayments ¶
func (bundle *PaymentBundle) ArchivePayments(db *bolt.DB) error
ArchivePayments removes all payments included in the payment bundle from the payment bucket and archives them.
func (*PaymentBundle) Total ¶
func (bundle *PaymentBundle) Total() hcutil.Amount
Total returns the sum of all payments amount for the account.
func (*PaymentBundle) UpdateAsPaid ¶
func (bundle *PaymentBundle) UpdateAsPaid(db *bolt.DB, height uint32, txid string)
UpdateAsPaid updates all associated payments referenced by a payment bundle as paid.
type Quota ¶
Quota details the portion of mining rewrds due an account for work contributed to the pool.
type RateLimiter ¶
type RateLimiter struct {
// contains filtered or unexported fields
}
RateLimiter keeps connected clients within their allocated request rates.
func (*RateLimiter) AddRequestLimiter ¶
func (r *RateLimiter) AddRequestLimiter(ip string, clientType string) *rate.Limiter
AddRequestLimiter adds a new client request limiter to the limiter set.
func (*RateLimiter) GetLimiter ¶
func (r *RateLimiter) GetLimiter(ip string) *rate.Limiter
GetLimiter fetches the request limiter referenced by the provided IP address.
func (*RateLimiter) RemoveLimiter ¶
func (r *RateLimiter) RemoveLimiter(ip string)
RemoveLimiter deletes the request limiter associated with the provided ip.
func (*RateLimiter) WithinLimit ¶
func (r *RateLimiter) WithinLimit(ip string, clientType string) bool
WithinLimit asserts that the client referenced by the provided IP address is within the limits of the rate limiter, therefore can make further requests. If no request limiter is found for the provided IP address a new one is created.
type Request ¶
type Request struct { ID *uint64 `json:"id"` Method string `json:"method"` Params interface{} `json:"params"` }
Request defines a request message.
func AuthorizeRequest ¶
AuthorizeRequest creates an authorize request message.
func NewRequest ¶
NewRequest creates a request instance.
func SetDifficultyNotification ¶
SetDifficultyNotification creates a set difficulty notification message.
func SubmitWorkRequest ¶
func SubmitWorkRequest(id *uint64, workerName string, jobID string, extraNonce2 string, nTime string, nonce string) *Request
SubmitWorkRequest creates a submit request message.
func SubscribeRequest ¶
SubscribeRequest creates a subscribe request message.
func WorkNotification ¶
func WorkNotification(jobID string, prevBlock string, genTx1 string, genTx2 string, blockVersion string, nBits string, nTime string, cleanJob bool) *Request
WorkNotification creates a work notification message.
func (*Request) MessageType ¶
MessageType returns the request message type.
type Response ¶
type Response struct { ID uint64 `json:"id"` Error *StratumError `json:"error"` Result interface{} `json:"result,omitempty"` }
Response defines a response message.
func AuthorizeResponse ¶
func AuthorizeResponse(id uint64, status bool, err *StratumError) *Response
AuthorizeResponse creates an authorize response.
func NewResponse ¶
func NewResponse(id uint64, result interface{}, err *StratumError) *Response
NewResponse creates a response instance.
func SubmitWorkResponse ¶
func SubmitWorkResponse(id uint64, status bool, err *StratumError) *Response
SubmitWorkResponse creates a submit response.
func SubscribeResponse ¶
func SubscribeResponse(id uint64, notifyID string, extraNonce1 string, extraNonce2Size int, err *StratumError) *Response
SubscribeResponse creates a mining.subscribe response.
func (*Response) MessageType ¶
MessageType returns the response message type.
type Share ¶
type Share struct {}
Share represents verifiable work performed by a pool client.
func PPLNSEligibleShares ¶
PPLNSEligibleShares fetches all shares keyed greater than the provided minimum.
func PPSEligibleShares ¶
PPSEligibleShares fetches all shares within the provided inclusive bounds.
type StratumError ¶
type StratumError struct { Code uint32 `json:"code"` Message string `json:"message"` Traceback *string `json:"traceback"` }
StratumError represents a stratum error message.
func NewStratumError ¶
func NewStratumError(code uint32, traceback *string) *StratumError
NewStratumError creates a stratum error instance.
func ParseAuthorizeResponse ¶
func ParseAuthorizeResponse(resp *Response) (bool, *StratumError, error)
ParseAuthorizeResponse resolves an authorize response into its components.
func ParseSubmitWorkResponse ¶
func ParseSubmitWorkResponse(resp *Response) (bool, *StratumError, error)
ParseSubmitWorkResponse resolves a submit response into its components.