etchash

package module
v0.0.0-...-c831de6 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2021 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).

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

Index

Constants

This section is empty.

Variables

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

Functions

func MakeDAG

func MakeDAG(block uint64, epochLength uint64, dir string)

MakeDAG generates a new etchash dataset and optionally stores it to disk.

Types

type Block

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

type Etchash

type Etchash struct {
	*Light
	*Full
}

Etchash combines block verification with Light and nonce searching with Full into a single proof of work.

func New

func New(ecip1099FBlock *uint64, uip1FEpoch *uint64) *Etchash

New creates an instance of the proof of work.

func NewForTesting

func NewForTesting(ecip1099FBlock *uint64, uip1FEpoch *uint64) (*Etchash, error)

NewForTesting creates a proof of work for use in unit tests. It uses a smaller DAG and cache size to keep test times low. DAG files are stored in a temporary directory.

Nonces found by a testing instance are not verifiable with a regular-size cache.

func NewShared

func NewShared(ecip1099FBlock *uint64, uip1FEpoch *uint64) *Etchash

NewShared creates an instance of the proof of work., where a single instance of the Light cache is shared across all instances created with NewShared.

type Full

type Full struct {
	Dir string // use this to specify a non-default DAG directory
	// contains filtered or unexported fields
}

Full implements the Search half of the proof of work.

func (*Full) GetHashrate

func (pow *Full) GetHashrate() int64

func (*Full) Search

func (pow *Full) Search(block Block, stop <-chan struct{}, index int) (nonce uint64, mixDigest []byte)

func (*Full) Turbo

func (pow *Full) Turbo(on bool)

type Light

type Light struct {
	NumCaches int // Maximum number of caches to keep before eviction (only init, don't modify)
	// contains filtered or unexported fields
}

Light implements the Verify half of the proof of work. It uses a few small in-memory caches to verify the nonces found by Full.

func (*Light) Compute

func (l *Light) Compute(blockNum uint64, hashNoNonce common.Hash, nonce uint64) (mixDigest common.Hash, result common.Hash)

compute() to get mixhash and result

func (*Light) Verify

func (l *Light) Verify(block Block) bool

Verify checks whether the block's nonce is valid.

Jump to

Keyboard shortcuts

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