stake

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2020 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
)

Variables

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

Functions

func BlockShareNum

func BlockShareNum(getter serodb.Getter, block common.Hash) (num uint64)

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

func GetPosRewardBySize

func GetPosRewardBySize(size uint64, blockNumber int64) (soloRewards *big.Int, totalRewards *big.Int)

func InitAVLTree

func InitAVLTree(state State)

Types

type AVLTree

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

func Copy

func Copy(state State, old *AVLTree) *AVLTree

func CopyFromOldV0

func CopyFromOldV0(old *STree) *AVLTree

func CopyFromOldV1

func CopyFromOldV1(old *STree) *AVLTree

func NewAVLTree

func NewAVLTree(state State) *AVLTree

func (*AVLTree) Delete

func (tree *AVLTree) Delete(key common.Hash, num uint32) *Node

func (*AVLTree) FindByIndex

func (tree *AVLTree) FindByIndex(index uint32) (*Node, error)

func (*AVLTree) GetNode

func (tree *AVLTree) GetNode(nodeHash common.Hash) *Node

func (*AVLTree) Insert

func (tree *AVLTree) Insert(node *Node)

func (*AVLTree) Midtraverse

func (tree *AVLTree) Midtraverse()

func (*AVLTree) Size

func (tree *AVLTree) Size() uint32

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 ITree

type ITree interface {
	Insert(*Node)
	Delete(nodeHash common.Hash, num uint32) *Node
	FindByIndex(index uint32) (*Node, error)

	Midtraverse()
	// GetNode(nodeHash common.Hash) *Node
	Size() uint32
}

func NewTree

func NewTree(state State, blockNumber uint64) ITree

type Node

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

func (*Node) Print

func (node *Node) Print()

type STree

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

func (*STree) Delete

func (tree *STree) Delete(nodeHash common.Hash, num uint32) *Node

func (*STree) FindByIndex

func (tree *STree) FindByIndex(index uint32) (*Node, error)

func (*STree) Insert

func (tree *STree) Insert(node *Node)

func (*STree) Lasttraverse

func (tree *STree) Lasttraverse(node *Node, handle func(*Node))

func (*STree) Midtraverse

func (tree *STree) Midtraverse()

func (*STree) Size

func (tree *STree) Size() uint32

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, blockNumber uint64) (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