Documentation ¶
Index ¶
- Constants
- Variables
- func CalcHash256PRNGIV(seed []byte) common.Hash
- func FindShareIdxs(size uint32, n uint16, prng *Hash256PRNG) ([]uint32, error)
- func GetBlockRecords(getter serodb.Getter, blockHash common.Hash, blockNumber uint64) (shares []*Share, pools []*StakePool)
- func GetLockingBlockNum() uint64
- func GetPoolValueThreshold() *big.Int
- type Hash256PRNG
- type SNode
- type STree
- type Share
- type StakePool
- type StakeState
- func (self *StakeState) AddPendingShare(share *Share)
- func (self *StakeState) AddStakePool(pool *StakePool)
- func (self *StakeState) CaleAvgPrice(amount *big.Int) (uint32, *big.Int, *big.Int)
- func (self *StakeState) CheckVotes(block *types.Block, bc blockChain) error
- func (self *StakeState) CurrentPrice() *big.Int
- func (self *StakeState) GetShare(key common.Hash) *Share
- func (self *StakeState) GetStakePool(poolId common.Hash) *StakePool
- func (self *StakeState) GetStakeState(key common.Hash) common.Hash
- func (self *StakeState) NeedTwoVote(num uint64) bool
- func (self *StakeState) ProcessBeforeApply(bc blockChain, header *types.Header) (err error)
- func (self *StakeState) RecordVotes(batch serodb.Batch, block *types.Block) error
- func (self *StakeState) SeleteShare(seed common.Hash) (ints []uint32, shares []*Share, err error)
- func (self *StakeState) SetStakeState(key common.Hash, value common.Hash)
- func (self *StakeState) ShareSize() uint32
- func (self *StakeState) StakeCurrentReward(blockNumber *big.Int) (soloRewards *big.Int, totalRewards *big.Int)
- func (self *StakeState) SumAmount(n int64) *big.Int
- type State
- type Status
Constants ¶
const ( SOLO_RATE = 3 TOTAL_RATE = 4 MaxVoteCount = 3 ValidVoteCount = 2 )
const MaxLevel = 32
const Probability = 0.25 // 基于时间与空间综合 best practice 值, 越上层概率越小
Variables ¶
var ( StakePoolDB = consensus.DBObj{"STAKE$POOL$"} )
Functions ¶
func CalcHash256PRNGIV ¶
CalcHash256PRNGIV calculates and returns the initialization vector for a given seed. This can be used in conjunction with the NewHash256PRNGFromIV function to arrive at the same values that are produced when calling NewHash256PRNG with the seed.
func FindShareIdxs ¶
func FindShareIdxs(size uint32, n uint16, prng *Hash256PRNG) ([]uint32, error)
FindShareIdxs is the exported version of findShareIdxs used for testing.
func GetBlockRecords ¶
func GetLockingBlockNum ¶
func GetLockingBlockNum() uint64
func GetPoolValueThreshold ¶
Types ¶
type Hash256PRNG ¶
type Hash256PRNG struct {
// contains filtered or unexported fields
}
Hash256PRNG is a determinstic pseudorandom number generator that uses a 256-bit secure hashing function to generate random uint32s starting from an initial seed.
func NewHash256PRNG ¶
func NewHash256PRNG(seed []byte) *Hash256PRNG
NewHash256PRNG returns a deterministic pseudorandom number generator that uses a 256-bit secure hashing function to generate random uint32s given a seed.
func NewHash256PRNGFromIV ¶
func NewHash256PRNGFromIV(iv common.Hash) *Hash256PRNG
NewHash256PRNGFromIV returns a deterministic pseudorandom number generator that uses a 256-bit secure hashing function to generate random uint32s given an initialization vector. The CalcHash256PRNGIV can be used to calculate an initialization vector for a given seed such that the generator will produce the same values as if NewHash256PRNG were called with the same seed. This allows callers to cache and reuse the initialization vector for a given seed to avoid recomputation.
func (*Hash256PRNG) Hash256Rand ¶
func (hp *Hash256PRNG) Hash256Rand() uint32
Hash256Rand returns a uint32 random number using the pseudorandom number generator and updates the state.
func (*Hash256PRNG) StateHash ¶
func (hp *Hash256PRNG) StateHash() common.Hash
StateHash returns a hash referencing the current state the deterministic PRNG.
type SNode ¶
type SNode struct {
// contains filtered or unexported fields
}
func (*SNode) MiddleOrder ¶
type STree ¶
type STree struct {
// contains filtered or unexported fields
}
func (*STree) MiddleOrder ¶
func (tree *STree) MiddleOrder()
type StakePool ¶
type StakeState ¶
type StakeState struct {
// contains filtered or unexported fields
}
func NewStakeState ¶
func NewStakeState(statedb *state.StateDB) *StakeState
func (*StakeState) AddPendingShare ¶
func (self *StakeState) AddPendingShare(share *Share)
func (*StakeState) AddStakePool ¶
func (self *StakeState) AddStakePool(pool *StakePool)
func (*StakeState) CaleAvgPrice ¶
func (*StakeState) CheckVotes ¶
func (self *StakeState) CheckVotes(block *types.Block, bc blockChain) error
func (*StakeState) CurrentPrice ¶
func (self *StakeState) CurrentPrice() *big.Int
func (*StakeState) GetStakePool ¶
func (self *StakeState) GetStakePool(poolId common.Hash) *StakePool
func (*StakeState) GetStakeState ¶
func (self *StakeState) GetStakeState(key common.Hash) common.Hash
func (*StakeState) NeedTwoVote ¶
func (self *StakeState) NeedTwoVote(num uint64) bool
func (*StakeState) ProcessBeforeApply ¶
func (self *StakeState) ProcessBeforeApply(bc blockChain, header *types.Header) (err error)
func (*StakeState) RecordVotes ¶
func (*StakeState) SeleteShare ¶
func (*StakeState) SetStakeState ¶
func (self *StakeState) SetStakeState(key common.Hash, value common.Hash)
func (*StakeState) ShareSize ¶
func (self *StakeState) ShareSize() uint32