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 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 SeedHash(block uint64) []byte
- type Config
- type ConstSqrt
- 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(block uint64) common.Hash
- func (m *Minerva) Finalize(chain consensus.ChainReader, header *types.Header, state *state.StateDB, ...) (*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) 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) 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) SetThreads(threads int)
- func (m *Minerva) Threads() int
- func (m *Minerva) UpdateTBL(offset [OFF_SKIP_LEN]int, skip [OFF_SKIP_LEN]int, plookupTbl []uint64) []uint64
- func (m *Minerva) VerifyFreshness(chain consensus.SnailChainReader, fruit, block *types.SnailHeader, ...) error
- func (m *Minerva) VerifyHeader(chain consensus.ChainReader, header *types.Header, seal bool) 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) 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 ( //SnailBlockRewardsInitial Snail block rewards initial 116.48733*10^18 SnailBlockRewardsInitial = new(big.Int).Mul(big.NewInt(11648733), big.NewInt(1e13)) //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 //SnailBlockBodyFruitInitial Snail block body fruit initial 30*10^15 SnailBlockBodyFruitInitial = new(big.Int).Mul(big.NewInt(30), big.NewInt(1e15)) //SnailBlockRewardsFruitRatio Snail block rewards fruit ratio 10% SnailBlockRewardsFruitRatio = 0.1 //CommitteesCount Number of committees CommitteesCount = new(big.Int).SetInt64(1) //MinerCount Miner quantity MinerCount = new(big.Int).SetInt64(1) )
var ErrInvalidDumpMagic = errors.New("invalid dump magic")
ErrInvalidDumpMagic errorinfo
var (
FrontierBlockReward = big.NewInt(5e+18) // Block reward in wei for successfully mining a block
)
Minerva protocol constants.
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 GetParents ¶
func GetParents(chain consensus.SnailChainReader, header *types.SnailHeader) []*types.SnailHeader
GetParents the calc different need parents
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 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) 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, error)
Finalize implements consensus.Engine, accumulating the block fruit and uncle rewards, setting the final state and assembling the block.
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) 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) 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) 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) UpdateTBL ¶
func (m *Minerva) UpdateTBL(offset [OFF_SKIP_LEN]int, skip [OFF_SKIP_LEN]int, plookupTbl []uint64) []uint64
UpdateTBL Update dataset information
func (*Minerva) VerifyFreshness ¶
func (m *Minerva) VerifyFreshness(chain consensus.SnailChainReader, fruit, block *types.SnailHeader, 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.