minerva

package
v0.0.0-...-15e8d78 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2023 License: GPL-3.0, GPL-3.0 Imports: 30 Imported by: 0

Documentation

Overview

Package minerva implements the abeychain hybrid consensus engine.

Index

Constants

View Source
const DATALENGTH = 2048 //2048 520
View Source
const DGSTSIZE = 32
View Source
const HEADSIZE = 32
View Source
const OFF_CYCLE_LEN = 8192 //8192  2080
View Source
const OFF_SKIP_LEN = 32768 //32768  8230
View Source
const OFF_STATR = 12 //in advance updata the algorithm
View Source
const PMTSIZE = 4
View Source
const SKIP_CYCLE_LEN = 2048 //2048 520
View Source
const STARTUPDATENUM = 10240 //10240  2600
View Source
const TBLSIZE = 16
View Source
const UPDATABLOCKLENGTH = 12000 //12000  3000

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 (

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

	//MiningConstant Mining constant is 20
	MiningConstant = 20

	//SqrtMin pbft and miner allocation constant
	//Generating formula :TestOutSqrt
	SqrtMin = 25

	//SqrtMax ...
	SqrtMax              = 6400
	MaxReduce            = 20
	NewRewardCoinForPow  = new(big.Int).Mul(big.NewInt(3560), BaseBig)
	RewardReduceInterval = 210000
	NewRewardCoinForPos  = new(big.Int).Mul(big.NewInt(570), BaseBig)
)
View Source
var ErrInvalidDumpMagic = errors.New("invalid dump magic")

ErrInvalidDumpMagic errorinfo

View Source
var SqrtArray = []float64{} /* 6401 elements not displayed */

Calculation method Assuming that the number of shards is i, the formula is: Sqrt(i) / (Sqrt(i) + MiningConstant) For detailed generation, see the TestOutSqrt method in Consensus testing.

Functions

func CalcDifficulty

func CalcDifficulty(config *params.ChainConfig, time uint64, parents []*types.SnailHeader) *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 CalcFruitDifficulty

func CalcFruitDifficulty(config *params.ChainConfig, time uint64, fastTime uint64, pointer *types.SnailHeader) *big.Int

CalcFruitDifficulty is the Fruit difficulty adjustment algorithm need calc fruit difficulty each new fruit

func GetBlockReward

func GetBlockReward(num *big.Int) (committee, minerBlock, minerFruit *big.Int)

GetBlockReward Reward for block allocation

func GetParents

func GetParents(chain consensus.SnailChainReader, header *types.SnailHeader) []*types.SnailHeader

GetParents the calc different need parents

func GetRewardForPow

func GetRewardForPow(height *big.Int) (minerBlock, minerFruit *big.Int)

func LogPrint

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

LogPrint log debug

func MatMuliple

func MatMuliple(input []uint64, output []uint64, pmat []uint64) int

func NewDataset

func NewDataset(epoch uint64) interface{}

newDataset creates a new truehash mining dataset

func SeedHash

func SeedHash(block uint64) []byte

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

func TruehashLight

func TruehashLight(dataset []uint64, hash []byte, nonce uint64) ([]byte, []byte)

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

type ConstSqrt

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

ConstSqrt ...

type Dataset

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

dataset wraps an truehash dataset with some metadata to allow easier concurrent use.

func (*Dataset) Generate

func (d *Dataset) Generate(epoch uint64, headershash *[STARTUPDATENUM][]byte)

generate ensures that the dataset content is generated before use.

func (*Dataset) GetDataSet

func (d *Dataset) GetDataSet() []uint64

func (*Dataset) GetDataSetEpoch

func (d *Dataset) GetDataSetEpoch() uint64

func (*Dataset) GetDatasetSeedhash

func (d *Dataset) GetDatasetSeedhash(dataset []uint64) string

func (*Dataset) Hash

func (d *Dataset) Hash() common.Hash

func (*Dataset) UpdateTBL

func (d *Dataset) UpdateTBL(offset [OFF_SKIP_LEN]int, skip [OFF_SKIP_LEN]int, plookupTbl []uint64) []uint64

UpdateTBL Update dataset information

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

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

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) AuthorSnail

func (m *Minerva) AuthorSnail(header *types.SnailHeader) (common.Address, error)

AuthorSnail return Snail mine coinbase

func (*Minerva) CalcFruitDifficulty

func (m *Minerva) CalcFruitDifficulty(chain consensus.SnailChainReader, time uint64, fastTime uint64, pointer *types.SnailHeader) *big.Int

CalcFruitDifficulty is Calc the Fruit difficulty again and compare the header diff

func (*Minerva) CalcSnailDifficulty

func (m *Minerva) CalcSnailDifficulty(chain consensus.SnailChainReader, time uint64, parents []*types.SnailHeader) *big.Int

CalcSnailDifficulty 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 (*Minerva) ConSeal

func (m *Minerva) ConSeal(chain consensus.SnailChainReader, block *types.SnailBlock, stop <-chan struct{}, send chan *types.SnailBlock)

ConSeal implements consensus.Engine, attempting to find a nonce that satisfies the block's difficulty requirements.

func (*Minerva) DataSetHash

func (m *Minerva) DataSetHash(epoch uint64) string

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) FinalizeSnail

func (m *Minerva) FinalizeSnail(chain consensus.SnailChainReader, header *types.SnailHeader,
	uncles []*types.SnailHeader, fruits []*types.SnailBlock, signs []*types.PbftSign) (*types.SnailBlock, error)

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

func (*Minerva) GetDifficulty

func (m *Minerva) GetDifficulty(header *types.SnailHeader, isFruit bool) (*big.Int, *big.Int)

GetDifficulty get difficulty by header

func (*Minerva) GetElection

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

GetElection return election

func (*Minerva) GetRewardContentBySnailNumber

func (m *Minerva) GetRewardContentBySnailNumber(sBlock *types.SnailBlock) *types.SnailRewardContenet

GetRewardContentBySnailNumber retrieves SnailRewardContenet by snail block.

func (*Minerva) Hashrate

func (m *Minerva) Hashrate() float64

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

func (*Minerva) NewTestData

func (m *Minerva) NewTestData(block uint64)

NewTestData Method test usage

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) PrepareSnail

func (m *Minerva) PrepareSnail(fastchain consensus.ChainReader, chain consensus.SnailChainReader, header *types.SnailHeader) error

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

func (*Minerva) PrepareSnailWithParent

func (m *Minerva) PrepareSnailWithParent(fastchain consensus.ChainReader, chain consensus.SnailChainReader, header *types.SnailHeader, parents []*types.SnailHeader) error

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

func (*Minerva) Seal

func (m *Minerva) Seal(chain consensus.SnailChainReader, block *types.SnailBlock, stop <-chan struct{}) (*types.SnailBlock, error)

Seal implements consensus.Engine, attempting to find a nonce that satisfies the block's difficulty requirements.

func (*Minerva) SetElection

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

SetElection Append interface CommitteeElection after instantiation

func (*Minerva) SetSnailChainReader

func (m *Minerva) SetSnailChainReader(scr consensus.SnailChainReader)

SetSnailChainReader Append interface SnailChainReader after instantiations

func (*Minerva) SetSnailHeaderHash

func (m *Minerva) SetSnailHeaderHash(db abeydb.Database)

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) ValidateFruitHeader

func (m *Minerva) ValidateFruitHeader(block *types.SnailHeader, fruit *types.SnailHeader, chain consensus.SnailChainReader, fastchain consensus.ChainReader, checkpoint uint64) error

ValidateFruitHeader is to verify if the fruit is legal

func (*Minerva) ValidateRewarded

func (m *Minerva) ValidateRewarded(number uint64, hash common.Hash, fastchain consensus.ChainReader) error

ValidateRewarded verify whether the block has been rewarded.

func (*Minerva) VerifyFreshness

func (m *Minerva) VerifyFreshness(chain consensus.SnailChainReader, fruit *types.SnailHeader, headerNumber *big.Int, canonical bool) error

VerifyFreshness the fruit have fresh is 17 blocks

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 Abeychain 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) VerifySnailHeader

func (m *Minerva) VerifySnailHeader(chain consensus.SnailChainReader, fastchain consensus.ChainReader, header *types.SnailHeader, seal bool, isFruit bool) error

VerifySnailHeader verify snail Header number

func (*Minerva) VerifySnailHeaders

func (m *Minerva) VerifySnailHeaders(chain consensus.SnailChainReader, headers []*types.SnailHeader,
	seals []bool) (chan<- struct{}, <-chan error)

VerifySnailHeaders verify snail headers

func (*Minerva) VerifySnailSeal

func (m *Minerva) VerifySnailSeal(chain consensus.SnailChainReader, header *types.SnailHeader, isFruit bool) error

VerifySnailSeal implements consensus.Engine, checking whether the given block satisfies the PoW difficulty requirements.

func (*Minerva) VerifySnailSeal2

func (m *Minerva) VerifySnailSeal2(hight *big.Int, nonce string, headNoNoncehash string, ftarg *big.Int, btarg *big.Int, haveFruits bool) (bool, bool, []byte)

VerifySnailSeal2 implements consensus.Engine, checking whether the given block satisfies the PoW difficulty requirements.

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