miner

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2020 License: GPL-3.0 Imports: 23 Imported by: 0

README

truechain-engineering-code

init

Documentation

Overview

Package miner implements Ethereum block creation and mining.

Index

Constants

View Source
const DATASETHEADLENGH = 10240
View Source
const UPDATABLOCKLENGTH = 12000 //12000  3000

Variables

This section is empty.

Functions

This section is empty.

Types

type Agent

type Agent interface {
	Work() chan<- *Work
	SetReturnCh(chan<- *Result)
	Stop()
	Start()
	GetHashRate() int64
}

Agent can register themself with the worker

type Backend

type Backend interface {
	AccountManager() *accounts.Manager
	SnailBlockChain() *snailchain.SnailBlockChain
	BlockChain() *core.BlockChain
	TxPool() *core.TxPool
	SnailPool() *snailchain.SnailPool
	ChainDb() etruedb.Database
}

Backend wraps all methods required for mining.

type CPUAgent

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

CPUAgent is for agent to mine

func NewCPUAgent

func NewCPUAgent(chain consensus.SnailChainReader, engine consensus.Engine) *CPUAgent

NewCPUAgent create a Agent for miner

func (*CPUAgent) GetHashRate

func (agent *CPUAgent) GetHashRate() int64

GetHashRate return the cpu miner rate

func (*CPUAgent) SetReturnCh

func (agent *CPUAgent) SetReturnCh(ch chan<- *Result)

SetReturnCh is Agent return monitor result chan after the miner

func (*CPUAgent) Start

func (agent *CPUAgent) Start()

Start is a interface the work can control the Agent to start miner

func (*CPUAgent) Stop

func (agent *CPUAgent) Stop()

Stop is a interface the work can control the Agent to stop miner

func (*CPUAgent) Work

func (agent *CPUAgent) Work() chan<- *Work

Work is Agent return monitor work chan

type CommitteeElection

type CommitteeElection interface {
	//VerifySigns verify the fast chain committee signatures in batches
	VerifySigns(pvs []*types.PbftSign) ([]*types.CommitteeMember, []error)

	//Get a list of committee members
	GetCommittee(fastNumber *big.Int) []*types.CommitteeMember

	SubscribeElectionEvent(ch chan<- types.ElectionEvent) event.Subscription

	IsCommitteeMember(members []*types.CommitteeMember, publickey []byte) bool
}

CommitteeElection interface is Election module implementation committee interface

type Miner

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

Miner creates blocks and searches for proof-of-work values.

func New

func New(truechain Backend, config *params.ChainConfig, mux *event.TypeMux, engine consensus.Engine,
	election CommitteeElection, mineFruit bool, singleNode bool, remoteMining bool, mining bool) *Miner

New is create a miner object

func (*Miner) GetCurrentBlock

func (miner *Miner) GetCurrentBlock() *types.SnailBlock

GetCurrentBlock return the fruit or block it is mining

func (*Miner) HashRate

func (miner *Miner) HashRate() (tot int64)

HashRate can calc the Mine cpu hash rate

func (*Miner) Mining

func (miner *Miner) Mining() bool

Mining start mining set flage

func (*Miner) Pending

func (miner *Miner) Pending() (*types.Block, *state.StateDB)

Pending returns the currently pending block and associated state.

func (*Miner) PendingBlock

func (miner *Miner) PendingBlock() *types.Block

PendingBlock returns the currently pending block. Note, to access both the pending block and the pending state simultaneously, please use Pending(), as the pending state can change between multiple method calls

func (*Miner) PendingSnail

func (miner *Miner) PendingSnail() (*types.SnailBlock, *state.StateDB)

PendingSnail returns the currently pending Snailblock and associated state.

func (*Miner) PendingSnailBlock

func (miner *Miner) PendingSnailBlock() *types.SnailBlock

PendingSnailBlock returns the currently pending block. Note, to access both the pending block and the pending state simultaneously, please use Pending(), as the pending state can change between multiple method calls

func (*Miner) Register

func (miner *Miner) Register(agent Agent)

Register is for register Agent to start or stop Agent

func (*Miner) SetElection

func (miner *Miner) SetElection(toElect bool, pubkey []byte)

SetElection Election is after mine the miner can be committee number

func (*Miner) SetEtherbase

func (miner *Miner) SetEtherbase(addr common.Address)

SetEtherbase for reward

func (*Miner) SetExtra

func (miner *Miner) SetExtra(extra []byte) error

SetExtra set Extra data

func (*Miner) SetFruitOnly

func (miner *Miner) SetFruitOnly(FruitOnly bool)

SetFruitOnly allow the mine only mined fruit

func (*Miner) SetShouldStartMining

func (miner *Miner) SetShouldStartMining(start bool)

Stop stop miner

func (*Miner) Start

func (miner *Miner) Start(coinbase common.Address)

Start miner

func (*Miner) Stop

func (miner *Miner) Stop()

Stop stop miner

func (*Miner) Unregister

func (miner *Miner) Unregister(agent Agent)

Unregister is Unregister the Agent

type RemoteAgent

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

RemoteAgent for Remote mine

func NewRemoteAgent

func NewRemoteAgent(chain consensus.ChainReader, snailchain consensus.SnailChainReader, engine consensus.Engine) *RemoteAgent

NewRemoteAgent create remote agent object

func (*RemoteAgent) CompletionHexString

func (a *RemoteAgent) CompletionHexString(n int, src string) string

func (*RemoteAgent) GetDataset

func (a *RemoteAgent) GetDataset() ([DATASETHEADLENGH]string, error)

GetWork return the current block hash without nonce

func (*RemoteAgent) GetDatasetBySeedHash

func (a *RemoteAgent) GetDatasetBySeedHash(seedHash string) ([DATASETHEADLENGH]string, error)

GetWork return the current block hash without nonce

func (*RemoteAgent) GetHashRate

func (a *RemoteAgent) GetHashRate() (tot int64)

GetHashRate returns the accumulated hashrate of all identifier combined

func (*RemoteAgent) GetWork

func (a *RemoteAgent) GetWork() ([4]string, error)

GetWork return the current block hash without nonce

func (*RemoteAgent) SetReturnCh

func (a *RemoteAgent) SetReturnCh(returnCh chan<- *Result)

SetReturnCh return a mine result for return chan

func (*RemoteAgent) Start

func (a *RemoteAgent) Start()

Start remote control the start mine

func (*RemoteAgent) Stop

func (a *RemoteAgent) Stop()

Stop remote control the stop mine

func (*RemoteAgent) SubmitHashrate

func (a *RemoteAgent) SubmitHashrate(id common.Hash, rate uint64)

SubmitHashrate return the HashRate for remote agent

func (*RemoteAgent) SubmitWork

func (a *RemoteAgent) SubmitWork(nonce types.BlockNonce, mixDigest, hash common.Hash) bool

SubmitWork tries to inject a pow solution into the remote agent, returning whether the solution was accepted or not (not can be both a bad pow as well as any other error, like no work pending).

func (*RemoteAgent) Work

func (a *RemoteAgent) Work() chan<- *Work

Work return a work chan

type Result

type Result struct {
	Work  *Work
	Block *types.SnailBlock
}

Result is for miner and get mined result

type Work

type Work struct {
	Block *types.SnailBlock // the new block
	// contains filtered or unexported fields
}

Work is the workers current environment and holds all of the current state information

Jump to

Keyboard shortcuts

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