blakimoto

package
v0.1.1-alpha Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2018 License: GPL-3.0 Imports: 13 Imported by: 2

Documentation

Overview

Package blakimoto provides functionalities for performing and verifying proof-of-work computation. It uses Blake2b-256 as the hash function.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUnknownParent indicates an unknown parent of a block
	ErrUnknownParent = fmt.Errorf("block's parent is unknown")

	// ErrFutureBlock is returned when a block's timestamp is in the future according
	// to the current node.
	ErrFutureBlock = errors.New("block in the future")

	// ErrInvalidNumber is returned if a block's number doesn't equal it's parent's
	// plus one.
	ErrInvalidNumber = errors.New("invalid block number")
)

Functions

func BlakeHash

func BlakeHash(headerHash []byte, nonce uint64) []byte

BlakeHash combines the header's hash and nonce and hashes the value using blake2b-256 to provide an output that is checked against a difficulty target

func CalcDifficulty

func CalcDifficulty(blockHeader types.Header, parent types.Header) *big.Int

CalcDifficulty 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.

Types

type Blakimoto

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

Blakimoto is a consensus engine based on proof-of-work implementing the blakimoto algorithm.

func ConfiguredBlakimoto

func ConfiguredBlakimoto(mode Mode, log logger.Logger) *Blakimoto

ConfiguredBlakimoto creates an Blakimoto instance pre-configured using the engine configuration.

func New

func New(config Config, log logger.Logger) *Blakimoto

New creates a full sized blakimoto PoW scheme.

func (*Blakimoto) CalcDifficulty

func (b *Blakimoto) CalcDifficulty(blockHeader types.Header, parent types.Header) *big.Int

CalcDifficulty 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 (*Blakimoto) Hashrate

func (blakimoto *Blakimoto) Hashrate() float64

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

func (*Blakimoto) Prepare

func (b *Blakimoto) Prepare(chain types.ChainReader, header types.Header) error

Prepare initializes the difficulty and total difficulty fields of a header to conform to the protocol

func (*Blakimoto) SetFakeDelay

func (blakimoto *Blakimoto) SetFakeDelay(d time.Duration)

SetFakeDelay sets the delay duration for ModeFake

func (*Blakimoto) SetThreads

func (blakimoto *Blakimoto) 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 (*Blakimoto) Threads

func (blakimoto *Blakimoto) Threads() int

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

func (*Blakimoto) VerifyHeader

func (b *Blakimoto) VerifyHeader(header, parent types.Header, seal bool) error

VerifyHeader checks whether a header conforms to the consensus rules

func (*Blakimoto) VerifySeal

func (b *Blakimoto) VerifySeal(header types.Header) error

VerifySeal checks whether the given block satisfies the PoW difficulty requirements.

type Config

type Config struct {
	PowMode Mode
}

Config are the configuration parameters of the blakimoto.

type Mode

type Mode uint

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

const (
	// ModeNormal refers to normal mode
	ModeNormal Mode = iota
	// ModeTest refers to test mode
	ModeTest
)

Jump to

Keyboard shortcuts

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