allocator

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2025 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HashratePredictionAdjustment = 1.0
	AllocationMinDuration        = 5 * time.Second
	AllocationMinJob             = 5000.0
)

Variables

View Source
var (
	ErrConnPrimary           = errors.New("failed to connect to primary dest")
	ErrConnDest              = errors.New("failed to connect to dest")
	ErrProxyExited           = errors.New("proxy exited")
	ErrTaskDeadlineExceeded  = errors.New("task deadline exceeded")
	ErrTaskMinerDisconnected = errors.New("miner disconnected")
)

Functions

This section is empty.

Types

type Allocator

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

func NewAllocator

func NewAllocator(proxies *lib.Collection[*Scheduler], log gi.ILogger) *Allocator

func (*Allocator) AddVettedListener

func (p *Allocator) AddVettedListener(f func(ID string)) ListenerHandle

func (*Allocator) AllocateFullMinersForHR

func (p *Allocator) AllocateFullMinersForHR(
	ID string,
	hrGHS float64,
	dest *url.URL,
	duration time.Duration,
	onSubmit OnSubmitCb,
	onDisconnect OnDisconnectCb,
	onEnd OnEndCb,
) (minerIDs []string, deltaGHS float64)

func (*Allocator) AllocatePartialForJob

func (p *Allocator) AllocatePartialForJob(
	ID string,
	jobNeeded float64,
	dest *url.URL,
	cycleEndTimeout time.Duration,
	onSubmit func(diff float64, ID string),
	onDisconnect func(ID string, hrGHS float64, remainingJob float64),
	onEnd OnEndCb,
) (minerIDJob MinerIDJob, remainderGHS float64)

func (*Allocator) GetMiners

func (p *Allocator) GetMiners() *lib.Collection[*Scheduler]

func (*Allocator) GetMinersFulfillingContract

func (p *Allocator) GetMinersFulfillingContract(contractID string, cycleDuration time.Duration) []*MinerItemJobScheduled

func (*Allocator) InvokeVettedListeners

func (p *Allocator) InvokeVettedListeners(minerID string)

func (*Allocator) RemoveVettedListener

func (p *Allocator) RemoveVettedListener(s ListenerHandle)

type DestItem

type DestItem struct {
	Dest     string
	Job      float64
	Fraction float64
}

type HashrateFactory

type HashrateFactory = func() *hashrate.Hashrate

type ListenerHandle

type ListenerHandle int

type MinerIDJob

type MinerIDJob = map[string]float64

type MinerItem

type MinerItem struct {
	ID            string
	HrGHS         float64
	JobRemaining  float64
	TimeRemaining time.Duration
	IsFullMiner   bool
}

type MinerItemJobScheduled

type MinerItemJobScheduled struct {
	ID       string
	Job      float64
	Fraction float64
}

type MinerStatus

type MinerStatus uint8
const (
	MinerStatusVetting       MinerStatus = iota // vetting period
	MinerStatusFree                             // serving default pool
	MinerStatusBusy                             // fully or partially serving contract(s)
	MinerStatusPartialBusy                      // partially serving contract(s)
	MinerStatusDisconnecting                    // error or connection closeout caused the miner to disconnect, it might be briefly available in miners collection
)

func (MinerStatus) String

func (m MinerStatus) String() string

type MinerTask

type MinerTask struct {
	ID           string
	Dest         *url.URL
	Job          float64
	Deadline     time.Time
	OnSubmit     OnSubmitCb
	OnDisconnect OnDisconnectCb
	OnEnd        OnEndCb

	RemainingJobToSubmit *atomic.Int64
	// contains filtered or unexported fields
}

func NewTask

func NewTask(ID string, dest *url.URL, job float64, deadline time.Time, onSubmit OnSubmitCb, onDisconnect OnDisconnectCb, onEnd OnEndCb) *MinerTask

func (*MinerTask) Cancel

func (t *MinerTask) Cancel() (firstCancel bool)

func (*MinerTask) RemainingJob

func (t *MinerTask) RemainingJob() float64

type OnDisconnectCb

type OnDisconnectCb func(ID string, HrGHS float64, remainingJob float64)

type OnEndCb

type OnEndCb func(ID string, HrGHS float64, remainingJob float64, err error)

type OnSubmitCb

type OnSubmitCb func(diff float64, ID string)

type Scheduler

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

Scheduler is a proxy wrapper that can schedule one-time tasks to different destinations

func NewScheduler

func NewScheduler(proxy StratumProxyInterface, hashrateCounterID string, defaultDest *url.URL, minerVettingShares int, hashrateFactory HashrateFactory, onVetted func(ID string), onDestErr func(contractID *string, err error), log interfaces.ILogger) *Scheduler

func (*Scheduler) AddTask

func (p *Scheduler) AddTask(
	ID string,
	dest *url.URL,
	jobSubmitted float64,
	onSubmit OnSubmitCb,
	onDisconnect OnDisconnectCb,
	onEnd OnEndCb,
	deadline time.Time,
)

AddTask adds new task to the queue

func (*Scheduler) GetConnectedAt

func (p *Scheduler) GetConnectedAt() time.Time

func (*Scheduler) GetCurrentDest

func (p *Scheduler) GetCurrentDest() *url.URL

func (*Scheduler) GetCurrentDifficulty

func (p *Scheduler) GetCurrentDifficulty() float64

func (*Scheduler) GetDestConns

func (p *Scheduler) GetDestConns() *map[string]string

func (*Scheduler) GetDestinations

func (p *Scheduler) GetDestinations(cycleDuration time.Duration) []*DestItem

func (*Scheduler) GetHashrate

func (p *Scheduler) GetHashrate() proxy.Hashrate

func (*Scheduler) GetID

func (p *Scheduler) GetID() string

func (*Scheduler) GetJobCouldBeScheduledTill

func (p *Scheduler) GetJobCouldBeScheduledTill(interval time.Duration) float64

func (*Scheduler) GetStats

func (p *Scheduler) GetStats() interface{}

func (*Scheduler) GetStatus

func (p *Scheduler) GetStatus(cycleDuration time.Duration) MinerStatus

func (*Scheduler) GetTaskCount

func (p *Scheduler) GetTaskCount() int

func (*Scheduler) GetTasksByID

func (p *Scheduler) GetTasksByID(ID string) []*MinerTask

func (*Scheduler) GetTotalScheduledJob

func (p *Scheduler) GetTotalScheduledJob() float64

func (*Scheduler) GetUptime

func (p *Scheduler) GetUptime() time.Duration

func (*Scheduler) GetUsedHashrate

func (p *Scheduler) GetUsedHashrate() proxy.Hashrate

func (*Scheduler) GetWorkerName

func (p *Scheduler) GetWorkerName() string

func (*Scheduler) HashrateGHS

func (p *Scheduler) HashrateGHS() float64

HashrateGHS returns hashrate in GHS

func (*Scheduler) ID

func (p *Scheduler) ID() string

func (*Scheduler) IsAcceptingTasks

func (p *Scheduler) IsAcceptingTasks(duration time.Duration) bool

AcceptsTasks returns true if there are vacant space for tasks for provided interval

func (*Scheduler) IsBusy

func (p *Scheduler) IsBusy(cycleDuration time.Duration) bool

func (*Scheduler) IsDisconnecting

func (p *Scheduler) IsDisconnecting() bool

func (*Scheduler) IsFree

func (p *Scheduler) IsFree() bool

func (*Scheduler) IsPartialBusy

func (p *Scheduler) IsPartialBusy(cycleDuration time.Duration) bool

func (*Scheduler) IsVetting

func (p *Scheduler) IsVetting() bool

func (*Scheduler) RemoveTasksByID

func (p *Scheduler) RemoveTasksByID(ID string)

func (*Scheduler) Run

func (p *Scheduler) Run(ctx context.Context) error

func (*Scheduler) SetPrimaryDest

func (p *Scheduler) SetPrimaryDest(dest *url.URL)

SetPrimaryDest is not protected by mutex

type StratumProxyInterface

type StratumProxyInterface interface {
	Connect(ctx context.Context) error
	// deprecated
	ConnectDest(ctx context.Context, newDestURL *url.URL) error

	Run(ctx context.Context) error
	SetDest(ctx context.Context, dest *url.URL, onSubmit func(diff float64)) error
	SetDestWithoutAutoread(ctx context.Context, dest *url.URL, onSubmit func(diff float64)) error

	GetID() string
	GetHashrate() proxy.Hashrate
	GetDifficulty() float64
	GetDest() *url.URL
	GetSourceWorkerName() string
	GetDestWorkerName() string
	GetMinerConnectedAt() time.Time
	GetStats() map[string]int
	GetDestConns() *map[string]string
	IsVetting() bool
	VettingDone() <-chan struct{}
	GetIncomingContractID() *string
}

type TaskList

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

func NewTaskList

func NewTaskList() *TaskList

func (*TaskList) Add

func (p *TaskList) Add(ID string, dest *url.URL, job float64, deadline time.Time, onSubmit OnSubmitCb, onDisconnect OnDisconnectCb, onEnd OnEndCb) int

func (*TaskList) Cancel

func (p *TaskList) Cancel(contractID string)

func (*TaskList) CancelAll

func (p *TaskList) CancelAll()

func (*TaskList) LockNextTask

func (p *TaskList) LockNextTask() (t *MinerTask, ok bool)

returns the first element of the task queue

func (*TaskList) Range

func (p *TaskList) Range(f func(task *MinerTask) bool)

func (*TaskList) Size

func (p *TaskList) Size() int

func (*TaskList) Unlock

func (p *TaskList) Unlock()

func (*TaskList) UnlockAndRemove

func (p *TaskList) UnlockAndRemove()

removes lock and removes from the task queue

Jump to

Keyboard shortcuts

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