Documentation ¶
Overview ¶
Package minerva implements the truechain hybrid consensus engine.
Index ¶
- Constants
- Variables
- func CalcDifficulty(config *params.ChainConfig, time uint64, parents []*types.SnailHeader) *big.Int
- func CalcFruitDifficulty(config *params.ChainConfig, time uint64, fastTime uint64, ...) *big.Int
- func GetBlockReward(num *big.Int) (committee, minerBlock, minerFruit *big.Int, e error)
- func GetBlockReward3(num *big.Int) (committee, minerBlock, minerFruit, developercoin *big.Int, e error)
- func GetParents(chain consensus.SnailChainReader, header *types.SnailHeader) []*types.SnailHeader
- func LogPrint(info string, addr common.Address, amount *big.Int)
- func MatMuliple(input []uint64, output []uint64, pmat []uint64) int
- func NewDataset(epoch uint64) interface{}
- func SeedHash(block uint64) []byte
- func TruehashLight(dataset []uint64, hash []byte, nonce uint64) ([]byte, []byte)
- type Config
- type ConstSqrt
- type Dataset
- func (d *Dataset) Generate(epoch uint64, headershash *[STARTUPDATENUM][]byte)
- func (d *Dataset) GetDataSet() []uint64
- func (d *Dataset) GetDataSetEpoch() uint64
- func (d *Dataset) GetDatasetSeedhash(dataset []uint64) string
- func (d *Dataset) Hash() common.Hash
- func (d *Dataset) UpdateTBL(offset [OFF_SKIP_LEN]int, skip [OFF_SKIP_LEN]int, plookupTbl []uint64) []uint64
- type Minerva
- func (m *Minerva) APIs(chain consensus.ChainReader) []rpc.API
- func (m *Minerva) Author(header *types.Header) (common.Address, error)
- func (m *Minerva) AuthorSnail(header *types.SnailHeader) (common.Address, error)
- func (m *Minerva) CalcFruitDifficulty(chain consensus.SnailChainReader, time uint64, fastTime uint64, ...) *big.Int
- func (m *Minerva) CalcSnailDifficulty(chain consensus.SnailChainReader, time uint64, parents []*types.SnailHeader) *big.Int
- func (m *Minerva) ConSeal(chain consensus.SnailChainReader, block *types.SnailBlock, ...)
- func (m *Minerva) DataSetHash(epoch uint64) string
- func (m *Minerva) Finalize(chain consensus.ChainReader, header *types.Header, state *state.StateDB, ...) (*types.Block, *types.ChainReward, error)
- func (m *Minerva) FinalizeCommittee(block *types.Block) error
- func (m *Minerva) FinalizeSnail(chain consensus.SnailChainReader, header *types.SnailHeader, ...) (*types.SnailBlock, error)
- func (m *Minerva) GetDifficulty(header *types.SnailHeader, isFruit bool) (*big.Int, *big.Int)
- func (m *Minerva) GetElection() consensus.CommitteeElection
- func (m *Minerva) GetRewardContentBySnailNumber(sBlock *types.SnailBlock) *types.SnailRewardContenet
- func (m *Minerva) Hashrate() float64
- func (m *Minerva) NewTestData(block uint64)
- func (m *Minerva) Prepare(chain consensus.ChainReader, header *types.Header) error
- func (m *Minerva) PrepareSnail(fastchain consensus.ChainReader, chain consensus.SnailChainReader, ...) error
- func (m *Minerva) PrepareSnailWithParent(fastchain consensus.ChainReader, chain consensus.SnailChainReader, ...) error
- func (m *Minerva) Seal(chain consensus.SnailChainReader, block *types.SnailBlock, ...) (*types.SnailBlock, error)
- func (m *Minerva) SetElection(e consensus.CommitteeElection)
- func (m *Minerva) SetSnailChainReader(scr consensus.SnailChainReader)
- func (m *Minerva) SetSnailHeaderHash(db etruedb.Database)
- func (m *Minerva) SetThreads(threads int)
- func (m *Minerva) Threads() int
- func (m *Minerva) ValidateFruitHeader(block *types.SnailHeader, fruit *types.SnailHeader, ...) error
- func (m *Minerva) ValidateRewarded(number uint64, hash common.Hash, fastchain consensus.ChainReader) error
- func (m *Minerva) VerifyFreshness(chain consensus.SnailChainReader, fruit *types.SnailHeader, ...) error
- func (m *Minerva) VerifyHeader(chain consensus.ChainReader, header *types.Header) error
- func (m *Minerva) VerifyHeaders(chain consensus.ChainReader, headers []*types.Header, seals []bool) (chan<- struct{}, <-chan error)
- func (m *Minerva) VerifySigns(fastnumber *big.Int, fastHash common.Hash, signs []*types.PbftSign) error
- func (m *Minerva) VerifySnailHeader(chain consensus.SnailChainReader, fastchain consensus.ChainReader, ...) error
- func (m *Minerva) VerifySnailHeaders(chain consensus.SnailChainReader, headers []*types.SnailHeader, seals []bool) (chan<- struct{}, <-chan error)
- func (m *Minerva) VerifySnailSeal(chain consensus.SnailChainReader, header *types.SnailHeader, isFruit bool) error
- func (m *Minerva) VerifySnailSeal2(hight *big.Int, nonce string, headNoNoncehash string, ftarg *big.Int, ...) (bool, bool, []byte)
- func (m *Minerva) VerifySwitchInfo(fastnumber *big.Int, info []*types.CommitteeMember) error
- type Mode
Constants ¶
const DATALENGTH = 2048 //2048 520
const DGSTSIZE = 32
const HEADSIZE = 32
const OFF_CYCLE_LEN = 8192 //8192 2080
const OFF_SKIP_LEN = 32768 //32768 8230
const OFF_STATR = 12 //in advance updata the algorithm
const PMTSIZE = 4
const SKIP_CYCLE_LEN = 2048 //2048 520
const STARTUPDATENUM = 10240 //10240 2600
const TBLSIZE = 16
const UPDATABLOCKLENGTH = 12000 //12000 3000
Variables ¶
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.
var ( //SnailBlockRewardsBase Snail block rewards base value is 115.555555555555 * 10^12 SnailBlockRewardsBase = 115555555555555 // Big1e6 up to wei SnailBlockRewardsBase * this is wei Big1e6 = big.NewInt(1e6) // SnailBlockRewardsChangeInterval Snail block rewards change interval 4500 blocks SnailBlockRewardsChangeInterval = 4500 // SnailBlockRewardsChangePercentage snall block rewards change interval decrease %2 SnailBlockRewardsChangePercentage = 2 //BaseBig ... BaseBig = big.NewInt(1e18) //NetworkFragmentsNuber The number of main network fragments is currently fixed at 1 NetworkFragmentsNuber = 1 //MiningConstant Mining constant is 20 MiningConstant = 20 //SqrtMin pbft and miner allocation constant //Generating formula :TestOutSqrt SqrtMin = 25 //SqrtMax ... SqrtMax = 6400 RewardMinerDecayEpoch = 50000 NewRewardBegin = 53550 NewRewardCoin = new(big.Int).Mul(big.NewInt(80), BaseBig) RewardEndSnailHeight = 1000000 )
var ErrInvalidDumpMagic = errors.New("invalid dump magic")
ErrInvalidDumpMagic errorinfo
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 ¶ added in v1.1.1
GetBlockReward Reward for block allocation
func GetBlockReward3 ¶
func GetParents ¶
func GetParents(chain consensus.SnailChainReader, header *types.SnailHeader) []*types.SnailHeader
GetParents the calc different need parents
func NewDataset ¶ added in v0.10.2
func NewDataset(epoch uint64) interface{}
newDataset creates a new truehash mining dataset
Types ¶
type Config ¶
type Config struct { CacheDir string CachesInMem int CachesOnDisk int DatasetDir string DatasetsInMem int DatasetsOnDisk int PowMode Mode Tip9 uint64 }
Config are the configuration parameters of the minerva.
type Dataset ¶ added in v0.10.2
type Dataset struct {
// contains filtered or unexported fields
}
dataset wraps an truehash dataset with some metadata to allow easier concurrent use.
func (*Dataset) Generate ¶ added in v0.10.2
func (d *Dataset) Generate(epoch uint64, headershash *[STARTUPDATENUM][]byte)
generate ensures that the dataset content is generated before use.
func (*Dataset) GetDataSet ¶ added in v0.10.2
func (*Dataset) GetDataSetEpoch ¶ added in v0.10.2
func (*Dataset) GetDatasetSeedhash ¶ added in v1.1.1
func (*Dataset) UpdateTBL ¶ added in v0.10.2
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 NewFakeDelayer ¶
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 ¶
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 ¶
Author implements consensus.Engine, returning the header's coinbase as the proof-of-work verified author of the block.
func (*Minerva) AuthorSnail ¶
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 (*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 ¶ added in v0.10.1
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 ¶
GetDifficulty get difficulty by header
func (*Minerva) GetElection ¶
func (m *Minerva) GetElection() consensus.CommitteeElection
GetElection return election
func (*Minerva) GetRewardContentBySnailNumber ¶ added in v1.0.2
func (m *Minerva) GetRewardContentBySnailNumber(sBlock *types.SnailBlock) *types.SnailRewardContenet
GetRewardContentBySnailNumber retrieves SnailRewardContenet by snail block.
func (*Minerva) Hashrate ¶
Hashrate implements PoW, returning the measured rate of the search invocations per second over the last minute.
func (*Minerva) NewTestData ¶
NewTestData Method test usage
func (*Minerva) Prepare ¶
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 ¶ added in v1.1.1
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 (*Minerva) SetThreads ¶
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 ¶
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 ¶
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) 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 ¶ added in v0.10.1
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 ¶
VerifySwitchInfo verify the switch info of Committee