stake

package
v1.0.1-rc6-dev-review3 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2019 License: GPL-3.0 Imports: 22 Imported by: 5

Documentation

Index

Constants

View Source
const (
	SOLO_RATE  = 3
	TOTAL_RATE = 4

	MaxVoteCount   = 3
	ValidVoteCount = 2
)
View Source
const MaxLevel = 32
View Source
const Probability = 0.25 // 基于时间与空间综合 best practice 值, 越上层概率越小

Variables

View Source
var (
	ShareDB     = consensus.DBObj{"STAKE$SHARE$"}
	StakePoolDB = consensus.DBObj{"STAKE$POOL$"}
)

Functions

func CalcHash256PRNGIV

func CalcHash256PRNGIV(seed []byte) common.Hash

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 GetBlockRecords(getter serodb.Getter, blockHash common.Hash, blockNumber uint64) (shares []*Share, pools []*StakePool)

func GetLockingBlockNum

func GetLockingBlockNum() uint64

func GetPoolValueThreshold

func GetPoolValueThreshold() *big.Int

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

func (node *SNode) MiddleOrder(state State)

func (*SNode) Print

func (node *SNode) Print(state State)

type STree

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

func NewTree

func NewTree(state State) *STree

func (*STree) MiddleOrder

func (tree *STree) MiddleOrder()

type Share

type Share struct {
	PKr             c_type.PKr
	VotePKr         c_type.PKr
	TransactionHash common.Hash
	PoolId          *common.Hash `rlp:"nil"`
	Value           *big.Int     `rlp:"nil"`
	BlockNumber     uint64
	InitNum         uint32
	Fee             uint16

	Num         uint32
	WillVoteNum uint32
	Status      Status
	Income      *big.Int `rlp:"nil"`
	Profit      *big.Int `rlp:"nil"`
	LastPayTime uint64
}

func GetShare

func GetShare(getter serodb.Getter, hash common.Hash) *Share

func GetShareByBlockNumber

func GetShareByBlockNumber(getter serodb.Getter, id common.Hash, blockHash common.Hash, blockNumber uint64) *Share

func GetSharesByBlock

func GetSharesByBlock(getter serodb.Getter, blockHash common.Hash, blockNumber uint64) (shares []*Share)

func SeleteBlockShare

func SeleteBlockShare(getter serodb.Getter, block common.Hash) (idx []uint32, shares []*Share)

func (*Share) CopyFrom

func (s *Share) CopyFrom(ret consensus.CItem)

func (*Share) CopyTo

func (s *Share) CopyTo() (ret consensus.CItem)

func (*Share) Id

func (s *Share) Id() []byte

func (*Share) State

func (s *Share) State() []byte

type StakePool

type StakePool struct {
	PKr             c_type.PKr
	VotePKr         c_type.PKr
	BlockNumber     uint64
	TransactionHash common.Hash
	Amount          *big.Int `rlp:"nil"`
	Fee             uint16

	CurrentShareNum uint32
	WishVoteNum     uint32
	ChoicedShareNum uint32
	MissedVoteNum   uint32
	ExpireNum       uint32

	Income      *big.Int `rlp:"nil"`
	Profit      *big.Int `rlp:"nil"`
	LastPayTime uint64
	Closed      bool
}

func GetStakePoolByBlockNumber

func GetStakePoolByBlockNumber(getter serodb.Getter, id common.Hash, blockHash common.Hash, blockNumber uint64) *StakePool

func (*StakePool) CanBeVote

func (self *StakePool) CanBeVote() bool

func (*StakePool) CopyFrom

func (s *StakePool) CopyFrom(ret consensus.CItem)

func (*StakePool) CopyTo

func (s *StakePool) CopyTo() (ret consensus.CItem)

func (*StakePool) Id

func (s *StakePool) Id() []byte

func (*StakePool) State

func (s *StakePool) State() []byte

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 (self *StakeState) CaleAvgPrice(amount *big.Int) (uint32, *big.Int, *big.Int)

func (*StakeState) CheckVotes

func (self *StakeState) CheckVotes(block *types.Block, bc blockChain) error

func (*StakeState) CurrentPrice

func (self *StakeState) CurrentPrice() *big.Int

func (*StakeState) GetShare

func (self *StakeState) GetShare(key common.Hash) *Share

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 (self *StakeState) RecordVotes(batch serodb.Batch, block *types.Block) error

func (*StakeState) SeleteShare

func (self *StakeState) SeleteShare(seed common.Hash) (ints []uint32, shares []*Share, err error)

func (*StakeState) SetStakeState

func (self *StakeState) SetStakeState(key common.Hash, value common.Hash)

func (*StakeState) ShareSize

func (self *StakeState) ShareSize() uint32

func (*StakeState) StakeCurrentReward

func (self *StakeState) StakeCurrentReward(blockNumber *big.Int) (soloRewards *big.Int, totalRewards *big.Int)

func (*StakeState) SumAmount

func (self *StakeState) SumAmount(n int64) *big.Int

type State

type State interface {
	SetStakeState(key common.Hash, value common.Hash)
	GetStakeState(key common.Hash) common.Hash
}

type Status

type Status int8
const (
	STATUS_VALID     Status = 0
	STATUS_OUTOFDATE Status = 1
	STATUS_FINISHED  Status = 2
)

Jump to

Keyboard shortcuts

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