ethash

package module
v0.0.0-...-89e4c4a Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2023 License: GPL-3.0 Imports: 27 Imported by: 0

README

go-etchash

Etchash go module intended for use by core-pool (and open-ethereum-pool).

  • supports etchash, ethash & ubqhash
usage (etchash)
var ecip1099FBlockClassic uint64 = 11700000 // classic mainnet
var ecip1099FBlockMordor uint64 = 2520000 // mordor testnet

var hasher = etchash.New(&ecip1099FBlockMordor, nil)

if hasher.Verify(block) {
    ...
}
usage (ethash)
var hasher = etchash.New(nil, nil)

if hasher.Verify(block) {
    ...
}
usage (ubqhash)
var uip1FEpoch uint64 = 22 // ubiq mainnet

var hasher = etchash.New(nil, &uip1FEpoch)

if hasher.Verify(block) {
    ...
}

Documentation

Overview

Package ethash implements the ethash proof-of-work consensus engine.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidDumpMagic = errors.New("invalid dump magic")

Functions

func MakeCache

func MakeCache(block uint64, dir string)

MakeCache generates a new ethash cache and optionally stores it to disk.

func MakeDataset

func MakeDataset(block uint64, dir string)

MakeDataset generates a new ethash dataset and optionally stores it to disk.

func SeedHash

func SeedHash(block uint64) []byte

SeedHash is the seed to use for generating a verification cache and the mining dataset.

Types

type Block

type Block interface {
	Difficulty() *big.Int
	HashNoNonce() common.Hash
	Nonce() uint64
	MixDigest() common.Hash
	NumberU64() uint64
}

type Config

type Config struct {
	CacheDir         string
	CachesInMem      int
	CachesOnDisk     int
	CachesLockMmap   bool
	DatasetDir       string
	DatasetsInMem    int
	DatasetsOnDisk   int
	DatasetsLockMmap bool
	PowMode          Mode

	// When set, notifications sent by the remote sealer will
	// be block header JSON objects instead of work package arrays.
	NotifyFull bool

	Log log.Logger `toml:"-"`
}

Config are the configuration parameters of the ethash.

type Ethash

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

Ethash is a consensus engine based on proof-of-work implementing the ethash algorithm.

func New

func New(config Config, notify []string, noverify bool) *Ethash

New creates a full sized ethash PoW scheme and starts a background thread for remote mining, also optionally notifying a batch of remote services of new work packages.

func NewFakeDelayer

func NewFakeDelayer(delay time.Duration) *Ethash

NewFakeDelayer creates a ethash consensus engine with a fake PoW scheme that accepts all blocks as valid, but delays verifications by some time, though they still have to conform to the Ethereum consensus rules.

func NewFakeFailer

func NewFakeFailer(fail uint64) *Ethash

NewFakeFailer creates a ethash consensus engine with a fake PoW scheme that accepts all blocks as valid apart from the single one specified, though they still have to conform to the Ethereum consensus rules.

func NewFaker

func NewFaker() *Ethash

NewFaker creates a ethash consensus engine with a fake PoW scheme that accepts all blocks' seal as valid, though they still have to conform to the Ethereum consensus rules.

func NewFullFaker

func NewFullFaker() *Ethash

NewFullFaker creates an ethash consensus engine with a full fake scheme that accepts all blocks as valid, without checking any consensus rules whatsoever.

func NewShared

func NewShared() *Ethash

NewShared creates a full sized ethash PoW shared between all requesters running in the same process.

func NewTester

func NewTester(notify []string, noverify bool) *Ethash

NewTester creates a small sized ethash PoW scheme useful only for testing purposes.

func (*Ethash) APIs

func (ethash *Ethash) APIs(chain consensus.ChainHeaderReader) []rpc.API

APIs implements consensus.Engine, returning the user facing RPC APIs.

func (*Ethash) Close

func (ethash *Ethash) Close() error

Close closes the exit channel to notify all backend threads exiting.

func (*Ethash) Hashrate

func (ethash *Ethash) Hashrate() float64

Hashrate implements PoW, returning the measured rate of the search invocations per second over the last minute. Note the returned hashrate includes local hashrate, but also includes the total hashrate of all remote miner.

func (*Ethash) SetThreads

func (ethash *Ethash) SetThreads(threads int)

SetThreads updates the number of mining threads currently enabled. Calling this method does not start mining, only sets the thread count. If zero is specified, the miner will use all cores of the machine. Setting a thread count below zero is allowed and will cause the miner to idle, without any work being done.

func (*Ethash) StopRemoteSealer

func (ethash *Ethash) StopRemoteSealer() error

StopRemoteSealer stops the remote sealer

func (*Ethash) Threads

func (ethash *Ethash) Threads() int

Threads returns the number of mining threads currently enabled. This doesn't necessarily mean that mining is running!

type Mode

type Mode uint

Mode defines the type and amount of PoW verification an ethash engine makes.

const (
	ModeNormal Mode = iota
	ModeShared
	ModeTest
	ModeFake
	ModeFullFake
)

Jump to

Keyboard shortcuts

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