mining

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2021 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const ComponentName = "miner"
View Source
const NumProcessors = 1

Variables

This section is empty.

Functions

This section is empty.

Types

type Backend

type Backend struct {
	Hasher
	TotalHashes      uint64
	HashSincePrint   uint64
	HashRateEstimate float64
}

type Config

type Config struct {
	LogLevel  string
	Heartbeat time.Duration
}

type CpuMiner

type CpuMiner int64

func NewCpuMiner

func NewCpuMiner(id int64) *CpuMiner

func (*CpuMiner) CheckRange

func (c *CpuMiner) CheckRange(anySolution context.Context, hash *HashSettings, start uint64, n uint64) (string, uint64, error)

func (*CpuMiner) Name

func (c *CpuMiner) Name() string

func (*CpuMiner) StepSize

func (c *CpuMiner) StepSize() uint64

type HashSettings

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

func NewHashSettings

func NewHashSettings(challenge *MiningChallenge, publicAddr string) *HashSettings

type Hasher

type Hasher interface {
	//base is a 52 byte slice containing the challenge and public address
	// the guessed nonce is appended to this slice and used as input to the first hash fn
	// returns a valid nonce, or empty string if none was found
	CheckRange(anySolution context.Context, hash *HashSettings, start uint64, n uint64) (string, uint64, error)

	//number of hashes this backend checks at a time
	StepSize() uint64

	Name() string
}

interface for all mining implementations.

type MiningChallenge

type MiningChallenge struct {
	Challenge  []byte
	Difficulty *big.Int
	RequestIDs [5]*big.Int
}

MiningChallenge holds information about a PoW challenge.

type MiningGroup

type MiningGroup struct {
	Backends    []*Backend
	LastPrinted time.Time
	// contains filtered or unexported fields
}

func NewMiningGroup

func NewMiningGroup(logger log.Logger, ctx context.Context, cfg Config, hashers []Hasher, contractInstance contracts.TellorCaller) (*MiningGroup, error)

func SetupMiningGroup

func SetupMiningGroup(logger log.Logger, ctx context.Context, cfg Config, contractInstance contracts.TellorCaller) (*MiningGroup, error)

func (*MiningGroup) HashRateEstimate

func (g *MiningGroup) HashRateEstimate() float64

func (*MiningGroup) Mine

func (g *MiningGroup) Mine(ctx context.Context, input chan *Work, output chan *Result)

func (*MiningGroup) PreferredWorkMultiple

func (g *MiningGroup) PreferredWorkMultiple() uint64

func (*MiningGroup) PrintHashRateSummary

func (g *MiningGroup) PrintHashRateSummary()

type MiningMgr

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

MiningMgr manages mining, submiting a solution and requesting data. In the tellor contract a solution is saved in slots where a value is valid only when it has 5 confirmed slots. The manager tracks tx costs and profitThreshold is set it skips any transactions below the profit threshold. The profit is calculated the same way as in the Tellor contract. Transaction cost for submitting in each slot might be different so because of this the manager needs to complete few transaction to gather the tx cost for each slot.

func NewManager

func NewManager(
	ctx context.Context,
	logger log.Logger,
	cfg Config,
	contractInstance contracts.TellorCaller,
	taskerCh chan *Work,
	submitterCh chan *Result,
	client *ethclient.Client,
) (*MiningMgr, error)

NewManager is the MiningMgr constructor.

func (*MiningMgr) Start

func (mgr *MiningMgr) Start() error

Start will start the mining run loop.

func (*MiningMgr) Stop

func (mgr *MiningMgr) Stop()

Stop will take care of stopping the miner component.

type Result

type Result struct {
	Work  *Work
	Nonce string
}

type SolutionSink

type SolutionSink interface {
	Submit(context.Context, *Result) (*types.Transaction, error)
}

type Work

type Work struct {
	Context    context.Context
	Challenge  *MiningChallenge
	PublicAddr string
	Start      uint64
	N          uint64
}

Jump to

Keyboard shortcuts

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