minerva

package
v0.0.0-...-bef2b3c Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2021 License: GPL-3.0 Imports: 23 Imported by: 0

README

A brief introduction to TrueChain 2.0 Consensus

Documentation

Overview

Package minerva implements the TrueChain consensus engine.

Index

Constants

This section is empty.

Variables

View Source
var (

	//ErrRewardedBlock is returned if a block to import is already rewarded.
	ErrRewardedBlock = errors.New("block already rewarded")
	ErrRewardEnd     = errors.New("Reward end")
)

Various error messages to mark blocks invalid. These should be private to prevent engine specific errors from being referenced in the remainder of the codebase, inherently breaking if the engine is swapped out. Please put common error types into the consensus package.

View Source
var (
	Big1e16 = big.NewInt(1e16) // 0.01 unit

	//BaseBig ...
	BaseBig = big.NewInt(1e18)

	//NetworkFragmentsNuber The number of main network fragments is currently fixed at 1
	NetworkFragmentsNuber = 1

	NewRewardBegin       = 53550
	RewardEndSnailHeight = 1000000
)
View Source
var ErrInvalidDumpMagic = errors.New("invalid dump magic")

ErrInvalidDumpMagic errorinfo

Functions

func GetBlockReward

func GetBlockReward(num uint64) *big.Int

GetBlockReward Reward for block allocation

func LogPrint

func LogPrint(info string, addr common.Address, amount *big.Int)

LogPrint log debug

Types

type Config

type Config struct {
	PowMode Mode
}

Config are the configuration parameters of the minerva.

type ConstSqrt

type ConstSqrt struct {
	Num  int     `json:"num"`
	Sqrt float64 `json:"sqrt"`
}

ConstSqrt ...

type Minerva

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

Minerva consensus

func New

func New(config Config) *Minerva

New creates a full sized minerva hybrid consensus scheme.

func NewFakeDelayer

func NewFakeDelayer(delay time.Duration) *Minerva

NewFakeDelayer creates a minerva 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) *Minerva

NewFakeFailer creates a minerva 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() *Minerva

NewFaker creates a minerva 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() *Minerva

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

func NewShared

func NewShared() *Minerva

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

func NewTester

func NewTester() *Minerva

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

func (*Minerva) APIs

func (m *Minerva) APIs(chain consensus.ChainReader) []rpc.API

func (*Minerva) Author

func (m *Minerva) Author(header *types.Header) (common.Address, error)

Author implements consensus.Engine, returning the header's coinbase as the proof-of-work verified author of the block.

func (*Minerva) Finalize

func (m *Minerva) Finalize(chain consensus.ChainReader, header *types.Header, state *state.StateDB,
	txs []*types.Transaction, receipts []*types.Receipt, feeAmount *big.Int) (*types.Block, *types.ChainReward, error)

Finalize implements consensus.Engine, accumulating the block fruit and uncle rewards, setting the final state and assembling the block.

func (*Minerva) FinalizeCommittee

func (m *Minerva) FinalizeCommittee(block *types.Block) error

FinalizeCommittee upddate current committee state

func (*Minerva) GetElection

func (m *Minerva) GetElection() consensus.CommitteeElection

GetElection return election

func (*Minerva) Prepare

func (m *Minerva) Prepare(chain consensus.ChainReader, header *types.Header) error

Prepare implements consensus.Engine, initializing the difficulty field of a header to conform to the minerva protocol. The changes are done inline.

func (*Minerva) SetElection

func (m *Minerva) SetElection(e consensus.CommitteeElection)

SetElection Append interface CommitteeElection after instantiation

func (*Minerva) SetThreads

func (m *Minerva) 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 (*Minerva) Threads

func (m *Minerva) Threads() int

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

func (*Minerva) VerifyHeader

func (m *Minerva) VerifyHeader(chain consensus.ChainReader, header *types.Header) error

VerifyHeader checks whether a header conforms to the consensus rules of the stock TrueChain m engine.

func (*Minerva) VerifyHeaders

func (m *Minerva) VerifyHeaders(chain consensus.ChainReader, headers []*types.Header,
	seals []bool) (chan<- struct{}, <-chan error)

VerifyHeaders is similar to VerifyHeader, but verifies a batch of headers concurrently. The method returns a quit channel to abort the operations and a results channel to retrieve the async verifications.

func (*Minerva) VerifySigns

func (m *Minerva) VerifySigns(fastnumber *big.Int, fastHash common.Hash, signs []*types.PbftSign) error

VerifySigns check the sings included in fast block or fruit

func (*Minerva) VerifySwitchInfo

func (m *Minerva) VerifySwitchInfo(fastnumber *big.Int, info []*types.CommitteeMember) error

VerifySwitchInfo verify the switch info of Committee

type Mode

type Mode uint

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

const (
	ModeNormal Mode = iota
	ModeShared
	ModeTest
	ModeFake
	ModeFullFake
)

constant

Jump to

Keyboard shortcuts

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