cphash

package
v0.0.0-...-9fbb145 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2021 License: MIT Imports: 29 Imported by: 4

Documentation

Index

Constants

View Source
const (
	MinFoundedSeconds = 5
)

Variables

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

Functions

func MakeCache

func MakeCache(block uint64, dir string)

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

func MakeDataset

func MakeDataset(block uint64, dir string)

MakeDataset generates a new cphash 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 Config

type Config struct {
	CacheDir       string
	CachesInMem    int
	CachesOnDisk   int
	DatasetDir     string
	DatasetsInMem  int
	DatasetsOnDisk int
	PowMode        Mode
}

Config are the configuration parameters of the cphash.

type Cphash

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

Cphash is a pow engine based on proof-of-work implementing the cphash algorithm.

func New

func New(config Config) *Cphash

New creates a full sized cphash PoW scheme.

func NewFakeDelayer

func NewFakeDelayer(delay time.Duration) *Cphash

NewFakeDelayer creates a cphash pow 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 Cypherium pow rules.

func NewFakeFailer

func NewFakeFailer(fail uint64) *Cphash

NewFakeFailer creates a cphash pow 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 Cypherium pow rules.

func NewFaker

func NewFaker() *Cphash

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

func NewFullFaker

func NewFullFaker() *Cphash

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

func NewShared

func NewShared() *Cphash

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

func NewTester

func NewTester() *Cphash

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

func (*Cphash) APIs

func (cphash *Cphash) APIs(chain types.ChainReader) []rpc.API

APIs implements pow.Engine, returning the user facing RPC APIs. Currently that is empty.

func (*Cphash) CalcKeyBlockDifficulty

func (cphash *Cphash) CalcKeyBlockDifficulty(chain types.KeyChainReader, time uint64, parent *types.KeyBlockHeader) *big.Int

CalcKeyBlockDifficulty is the difficulty adjustment algorithm. It returns the difficulty that a new block should have when created at time given the parent block's time and difficulty.

func (*Cphash) Hashrate

func (cphash *Cphash) Hashrate() float64

Hashrate implements PoW, returning the measured rate of the search invocations per second over the last minute.

func (*Cphash) PowMode

func (cphash *Cphash) PowMode() uint

func (*Cphash) PrepareCandidate

func (cphash *Cphash) PrepareCandidate(chain types.KeyChainReader, candidate *types.Candidate, committeeSize int) error

Prepare implements pow.Engine, initializing the difficulty field of a candidate to conform to the cphash protocol. The changes are done inline.

func (*Cphash) SealCandidate

func (cphash *Cphash) SealCandidate(candidate *types.Candidate, stop <-chan struct{}) (*types.Candidate, error)

SealCandidate implements pow.Engine, attempting to find a nonce that satisfies the candidate's difficulty requirements.

func (*Cphash) SetThreads

func (cphash *Cphash) 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 (*Cphash) Threads

func (cphash *Cphash) Threads() int

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

func (*Cphash) VerifyCandidate

func (cphash *Cphash) VerifyCandidate(chain types.KeyChainReader, candidate *types.Candidate) error

////////////////////////////////////////////////////////////////////////////////////////////// VerifyCandidate implements pow.Engine, checking whether the given candidate satisfies the PoW difficulty requirements.

type Mode

type Mode uint

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

const (
	ModeNormal Mode = iota
	ModeShared
	ModeTest
	ModeFake
	ModeFullFake
	ModeLocalMock
)

Jump to

Keyboard shortcuts

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