staking

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2019 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CandidatePrefixStr      = "Can"
	CanPowerPrefixStr       = "Power"
	UnStakeCountKeyStr      = "UnStakeCount"
	UnStakeItemKeyStr       = "UnStakeItem"
	DelegatePrefixStr       = "Del"
	UnDelegateCountKeyStr   = "UnDelCount"
	UnDelegateItemKeyStr    = "UnDelItem"
	EpochIndexKeyStr        = "EpochIndex"
	EpochValArrPrefixStr    = "EpochValArr"
	RoundIndexKeyStr        = "RoundIndex"
	RoundValArrPrefixStr    = "RoundValArr"
	AccountStakeRcPrefixStr = "AccStakeRc"
	PPOSHASHStr             = "PPOS_HASH"
)
View Source
const (
	/**
	######   ######   ######   ######
	#	  THE CANDIDATE  STATUS     #
	######   ######   ######   ######
	*/
	Invalided     = 1 << iota // 0001: The current candidate withdraws from the staking qualification (Active OR Passive)
	LowRatio                  // 0010: The candidate was low package ratio AND no delete
	NotEnough                 // 0100: The current candidate's von does not meet the minimum staking threshold
	DuplicateSign             // 1000: The Duplicate package or Duplicate sign
	LowRatioDel               // 0001,0000: The lowRatio AND must delete
	Withdrew                  // 0010,0000: The Active withdrew
	Valided       = 0         // 0000: The current candidate is in force
	NotExist      = 1 << 31   // 1000,xxxx,... : The candidate is not exist
)
View Source
const (
	MaxExternalIdLen = 70
	MaxNodeNameLen   = 30
	MaxWebsiteLen    = 140
	MaxDetailsLen    = 280
)
View Source
const SWeightItem = 4

Variables

View Source
var (
	CandidateKeyPrefix   = []byte(CandidatePrefixStr)
	CanPowerKeyPrefix    = []byte(CanPowerPrefixStr)
	UnStakeCountKey      = []byte(UnStakeCountKeyStr)
	UnStakeItemKey       = []byte(UnStakeItemKeyStr)
	DelegateKeyPrefix    = []byte(DelegatePrefixStr)
	UnDelegateCountKey   = []byte(UnDelegateCountKeyStr)
	UnDelegateItemKey    = []byte(UnDelegateItemKeyStr)
	EpochIndexKey        = []byte(EpochIndexKeyStr)
	EpochValArrPrefix    = []byte(EpochValArrPrefixStr)
	RoundIndexKey        = []byte(RoundIndexKeyStr)
	RoundValArrPrefix    = []byte(RoundValArrPrefixStr)
	AccountStakeRcPrefix = []byte(AccountStakeRcPrefixStr)
	PPOSHASHKey          = []byte(PPOSHASHStr)
)

Functions

func CandidateKeyByAddr

func CandidateKeyByAddr(addr common.Address) []byte

func CandidateKeyByNodeId

func CandidateKeyByNodeId(nodeId discover.NodeID) ([]byte, error)

func CandidateKeyByPubKey

func CandidateKeyByPubKey(p ecdsa.PublicKey) []byte

func CandidateKeyBySuffix

func CandidateKeyBySuffix(addr []byte) []byte

func CompareDefault

func CompareDefault(removes NeedRemoveCans, left, right *Validator) int

NOTE: Sort By Default

When sorting is done by default, it is slashed and is sorted to the end.

The priorities just like that: Slashing > ProgramVersion > Shares > BlockNumber > TxIndex

Slashing: From no to yes ProgramVersion: From big to small Shares: From big to small BlockNumber: From small to big TxIndex: From small to big

Compare Left And Right 1: Left > Right 0: Left == Right -1:Left < Right

func CompareForDel

func CompareForDel(removes NeedRemoveCans, left, right *Validator) int

NOTE: These are sorted by priority that will be removed

When sorting is done by delete slashing, it is slashed and is sorted to the front.

The priorities just like that: Invalid > ProgramVersion > validaotorTerm > Shares > BlockNumber > TxIndex

What is the invalid ? That are DuplicateSign and lowRatio&invalid and lowVersion and withdrew&NotInEpochValidators

Invalid Status: From invalid to valid ProgramVersion: From small to big validaotorTerm: From big to small Shares: From small to big BlockNumber: From big to small TxIndex: From big to small

Compare Left And Right 1: Left > Right 0: Left == Right -1:Left < Right

func CompareForStore

func CompareForStore(_ NeedRemoveCans, left, right *Validator) int

NOTE: Sort when doing storage

The priorities just like that: (No shares) ProgramVersion > validaotorTerm > BlockNumber > TxIndex

Compare Left And Right 1: Left > Right 0: Left == Right -1:Left < Right

func GetAccountStakeRcKey

func GetAccountStakeRcKey(addr common.Address) []byte

func GetDelegateKey

func GetDelegateKey(delAddr common.Address, nodeId discover.NodeID, stakeBlockNumber uint64) []byte

func GetDelegateKeyBySuffix

func GetDelegateKeyBySuffix(suffix []byte) []byte

func GetEpochIndexKey

func GetEpochIndexKey() []byte

func GetEpochValArrKey

func GetEpochValArrKey(start, end uint64) []byte

func GetPPOSHASHKey

func GetPPOSHASHKey() []byte

func GetRoundIndexKey

func GetRoundIndexKey() []byte

func GetRoundValArrKey

func GetRoundValArrKey(start, end uint64) []byte

func GetUnDelegateCountKey

func GetUnDelegateCountKey(epoch uint64) []byte

func GetUnDelegateItemKey

func GetUnDelegateItemKey(epoch, index uint64) []byte

func GetUnStakeCountKey

func GetUnStakeCountKey(epoch uint64) []byte

func GetUnStakeItemKey

func GetUnStakeItemKey(epoch, index uint64) []byte

func Is_DuplicateSign

func Is_DuplicateSign(status uint32) bool

func Is_Invalid

func Is_Invalid(status uint32) bool

func Is_Invalid_DuplicateSign

func Is_Invalid_DuplicateSign(status uint32) bool

func Is_Invalid_LowRatio

func Is_Invalid_LowRatio(status uint32) bool

func Is_Invalid_LowRatioDel

func Is_Invalid_LowRatioDel(status uint32) bool

func Is_Invalid_LowRatio_NotEnough

func Is_Invalid_LowRatio_NotEnough(status uint32) bool

func Is_Invalid_NotEnough

func Is_Invalid_NotEnough(status uint32) bool

func Is_Invalid_Withdrew

func Is_Invalid_Withdrew(status uint32) bool

func Is_LowRatio

func Is_LowRatio(status uint32) bool

func Is_LowRatioDel

func Is_LowRatioDel(status uint32) bool

func Is_LowRatio_NotEnough

func Is_LowRatio_NotEnough(status uint32) bool

func Is_NotEnough

func Is_NotEnough(status uint32) bool

func Is_PureInvalid

func Is_PureInvalid(status uint32) bool

func Is_PureLowRatio

func Is_PureLowRatio(status uint32) bool

func Is_PureLowRatioDel

func Is_PureLowRatioDel(status uint32) bool

func Is_PureNotEnough

func Is_PureNotEnough(status uint32) bool

func Is_PureWithdrew

func Is_PureWithdrew(status uint32) bool

func Is_Valid

func Is_Valid(status uint32) bool

func Is_Withdrew

func Is_Withdrew(status uint32) bool

func TallyPowerKey

func TallyPowerKey(shares *big.Int, stakeBlockNum uint64, stakeTxIndex, programVersion uint32) []byte

need to add ProgramVersion

Types

type Candidate

type Candidate struct {
	NodeId discover.NodeID
	// bls public key
	BlsPubKey bls.PublicKey
	// The account used to initiate the staking
	StakingAddress common.Address
	// The account receive the block rewards and the staking rewards
	BenefitAddress common.Address
	// The tx index at the time of staking
	StakingTxIndex uint32
	// The version of the node program
	// (Store Large Verson: the 2.1.x large version is 2.1.0)
	ProgramVersion uint32
	// The candidate status
	// Reference `THE CANDIDATE  STATUS`
	Status uint32
	// The epoch number at staking or edit
	StakingEpoch uint32
	// Block height at the time of staking
	StakingBlockNum uint64
	// All vons of staking and delegated
	Shares *big.Int
	// The staking von  is circulating for effective epoch (in effect)
	Released *big.Int
	// The staking von  is circulating for hesitant epoch (in hesitation)
	ReleasedHes *big.Int
	// The staking von  is RestrictingPlan for effective epoch (in effect)
	RestrictingPlan *big.Int
	// The staking von  is RestrictingPlan for hesitant epoch (in hesitation)
	RestrictingPlanHes *big.Int

	// Node desc
	Description
}

The Candidate info

func (*Candidate) String

func (can *Candidate) String() string

type CandidateHex

type CandidateHex struct {
	NodeId             discover.NodeID
	BlsPubKey          bls.PublicKey
	StakingAddress     common.Address
	BenefitAddress     common.Address
	StakingTxIndex     uint32
	ProgramVersion     uint32
	Status             uint32
	StakingEpoch       uint32
	StakingBlockNum    uint64
	Shares             *hexutil.Big
	Released           *hexutil.Big
	ReleasedHes        *hexutil.Big
	RestrictingPlan    *hexutil.Big
	RestrictingPlanHes *hexutil.Big
	Description
}

Display amount field using 0x hex

func (*CandidateHex) String

func (can *CandidateHex) String() string

type CandidateHexQueue

type CandidateHexQueue []*CandidateHex

type CandidateMap

type CandidateMap map[discover.NodeID]*Candidate

type CandidateQueue

type CandidateQueue []*Candidate

type DelRelatedQueue

type DelRelatedQueue = []*DelegateRelated

type DelegateRelated

type DelegateRelated struct {
	Addr            common.Address
	NodeId          discover.NodeID
	StakingBlockNum uint64
}

func (*DelegateRelated) String

func (dr *DelegateRelated) String() string

type Delegation

type Delegation struct {
	// The epoch number at delegate or edit
	DelegateEpoch uint32
	// The delegate von  is circulating for effective epoch (in effect)
	Released *big.Int
	// The delegate von  is circulating for hesitant epoch (in hesitation)
	ReleasedHes *big.Int
	// The delegate von  is RestrictingPlan for effective epoch (in effect)
	RestrictingPlan *big.Int
	// The delegate von  is RestrictingPlan for hesitant epoch (in hesitation)
	RestrictingPlanHes *big.Int
	// Total amount in all cancellation plans
	Reduction *big.Int
}

the Delegate information

func (*Delegation) String

func (del *Delegation) String() string

type DelegationEx

type DelegationEx struct {
	Addr            common.Address
	NodeId          discover.NodeID
	StakingBlockNum uint64
	DelegationHex
}

func (*DelegationEx) String

func (dex *DelegationEx) String() string

type DelegationHex

type DelegationHex struct {
	// The epoch number at delegate or edit
	DelegateEpoch uint32
	// The delegate von  is circulating for effective epoch (in effect)
	Released *hexutil.Big
	// The delegate von  is circulating for hesitant epoch (in hesitation)
	ReleasedHes *hexutil.Big
	// The delegate von  is RestrictingPlan for effective epoch (in effect)
	RestrictingPlan *hexutil.Big
	// The delegate von  is RestrictingPlan for hesitant epoch (in hesitation)
	RestrictingPlanHes *hexutil.Big
	// Total amount in all cancellation plans
	Reduction *hexutil.Big
}

func (*DelegationHex) String

func (delHex *DelegationHex) String() string

type Description

type Description struct {
	// External Id for the third party to pull the node description (with length limit)
	ExternalId string
	// The Candidate Node's Name  (with a length limit)
	NodeName string
	// The third-party home page of the node (with a length limit)
	Website string
	// Description of the node (with a length limit)
	Details string
}

func (*Description) CheckLength

func (desc *Description) CheckLength() error

type NeedRemoveCans

type NeedRemoveCans map[discover.NodeID]*Candidate

type StakingDB

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

func NewStakingDB

func NewStakingDB() *StakingDB

func (*StakingDB) AddAccountStakeRc

func (db *StakingDB) AddAccountStakeRc(blockHash common.Hash, addr common.Address) error

add the account staking Reference Count

func (*StakingDB) AddUnDelegateItemStore

func (db *StakingDB) AddUnDelegateItemStore(blockHash common.Hash, delAddr common.Address, nodeId discover.NodeID,
	epoch, stakeBlockNumber uint64, amount *big.Int) error

func (*StakingDB) AddUnStakeItemStore

func (db *StakingDB) AddUnStakeItemStore(blockHash common.Hash, epoch uint64, canAddr common.Address, stakeBlockNumber uint64) error

func (*StakingDB) DelCanPowerStore

func (db *StakingDB) DelCanPowerStore(blockHash common.Hash, can *Candidate) error

func (*StakingDB) DelCandidateStore

func (db *StakingDB) DelCandidateStore(blockHash common.Hash, addr common.Address) error

func (*StakingDB) DelDelegateStore

func (db *StakingDB) DelDelegateStore(blockHash common.Hash, delAddr common.Address, nodeId discover.NodeID,
	stakeBlockNumber uint64) error

func (*StakingDB) DelDelegateStoreBySuffix

func (db *StakingDB) DelDelegateStoreBySuffix(blockHash common.Hash, suffix []byte) error

func (*StakingDB) DelEpochValListByBlockHash

func (db *StakingDB) DelEpochValListByBlockHash(blockHash common.Hash, start, end uint64) error

func (*StakingDB) DelRoundValListByBlockHash

func (db *StakingDB) DelRoundValListByBlockHash(blockHash common.Hash, start, end uint64) error

func (*StakingDB) DelUnDelegateCountStore

func (db *StakingDB) DelUnDelegateCountStore(blockHash common.Hash, epoch uint64) error

func (*StakingDB) DelUnDelegateItemStore

func (db *StakingDB) DelUnDelegateItemStore(blockHash common.Hash, epoch, index uint64) error

func (*StakingDB) DelUnStakeCountStore

func (db *StakingDB) DelUnStakeCountStore(blockHash common.Hash, epoch uint64) error

func (*StakingDB) DelUnStakeItemStore

func (db *StakingDB) DelUnStakeItemStore(blockHash common.Hash, epoch, index uint64) error

func (*StakingDB) GetCandidateStore

func (db *StakingDB) GetCandidateStore(blockHash common.Hash, addr common.Address) (*Candidate, error)

func (*StakingDB) GetCandidateStoreByIrr

func (db *StakingDB) GetCandidateStoreByIrr(addr common.Address) (*Candidate, error)

func (*StakingDB) GetCandidateStoreByIrrWithSuffix

func (db *StakingDB) GetCandidateStoreByIrrWithSuffix(suffix []byte) (*Candidate, error)

func (*StakingDB) GetCandidateStoreWithSuffix

func (db *StakingDB) GetCandidateStoreWithSuffix(blockHash common.Hash, suffix []byte) (*Candidate, error)

func (*StakingDB) GetDelegateStore

func (db *StakingDB) GetDelegateStore(blockHash common.Hash, delAddr common.Address, nodeId discover.NodeID, stakeBlockNumber uint64) (*Delegation, error)

func (*StakingDB) GetDelegateStoreByIrr

func (db *StakingDB) GetDelegateStoreByIrr(delAddr common.Address, nodeId discover.NodeID, stakeBlockNumber uint64) (*Delegation, error)

func (*StakingDB) GetDelegateStoreBySuffix

func (db *StakingDB) GetDelegateStoreBySuffix(blockHash common.Hash, keySuffix []byte) (*Delegation, error)

func (*StakingDB) GetEpochValIndexByBlockHash

func (db *StakingDB) GetEpochValIndexByBlockHash(blockHash common.Hash) (ValArrIndexQueue, error)

func (*StakingDB) GetEpochValIndexByIrr

func (db *StakingDB) GetEpochValIndexByIrr() (ValArrIndexQueue, error)

func (*StakingDB) GetEpochValListByBlockHash

func (db *StakingDB) GetEpochValListByBlockHash(blockHash common.Hash, start, end uint64) (ValidatorQueue, error)

func (*StakingDB) GetEpochValListByIrr

func (db *StakingDB) GetEpochValListByIrr(start, end uint64) (ValidatorQueue, error)

func (*StakingDB) GetLastKVHash

func (db *StakingDB) GetLastKVHash(blockHash common.Hash) []byte

func (*StakingDB) GetRoundValIndexByBlockHash

func (db *StakingDB) GetRoundValIndexByBlockHash(blockHash common.Hash) (ValArrIndexQueue, error)

func (*StakingDB) GetRoundValIndexByIrr

func (db *StakingDB) GetRoundValIndexByIrr() (ValArrIndexQueue, error)

func (*StakingDB) GetRoundValListByBlockHash

func (db *StakingDB) GetRoundValListByBlockHash(blockHash common.Hash, start, end uint64) (ValidatorQueue, error)

func (*StakingDB) GetRoundValListByIrr

func (db *StakingDB) GetRoundValListByIrr(start, end uint64) (ValidatorQueue, error)

func (*StakingDB) GetUnDelegateCountStore

func (db *StakingDB) GetUnDelegateCountStore(blockHash common.Hash, epoch uint64) (uint64, error)

func (*StakingDB) GetUnDelegateItemStore

func (db *StakingDB) GetUnDelegateItemStore(blockHash common.Hash, epoch, index uint64) (*UnDelegateItem, error)

func (*StakingDB) GetUnStakeCountStore

func (db *StakingDB) GetUnStakeCountStore(blockHash common.Hash, epoch uint64) (uint64, error)

func (*StakingDB) GetUnStakeItemStore

func (db *StakingDB) GetUnStakeItemStore(blockHash common.Hash, epoch, index uint64) (*UnStakeItem, error)

func (*StakingDB) HasAccountStakeRc

func (db *StakingDB) HasAccountStakeRc(blockHash common.Hash, addr common.Address) (bool, error)

check the account staking Reference Count

func (*StakingDB) IteratorCandidatePowerByBlockHash

func (db *StakingDB) IteratorCandidatePowerByBlockHash(blockHash common.Hash, ranges int) iterator.Iterator

func (*StakingDB) IteratorDelegateByBlockHashWithAddr

func (db *StakingDB) IteratorDelegateByBlockHashWithAddr(blockHash common.Hash, addr common.Address, ranges int) iterator.Iterator

func (*StakingDB) SetCanPowerStore

func (db *StakingDB) SetCanPowerStore(blockHash common.Hash, addr common.Address, can *Candidate) error

func (*StakingDB) SetCandidateStore

func (db *StakingDB) SetCandidateStore(blockHash common.Hash, addr common.Address, can *Candidate) error

func (*StakingDB) SetDelegateStore

func (db *StakingDB) SetDelegateStore(blockHash common.Hash, delAddr common.Address, nodeId discover.NodeID,
	stakeBlockNumber uint64, del *Delegation) error

func (*StakingDB) SetDelegateStoreBySuffix

func (db *StakingDB) SetDelegateStoreBySuffix(blockHash common.Hash, suffix []byte, del *Delegation) error

func (*StakingDB) SetEpochValIndex

func (db *StakingDB) SetEpochValIndex(blockHash common.Hash, indexArr ValArrIndexQueue) error

func (*StakingDB) SetEpochValList

func (db *StakingDB) SetEpochValList(blockHash common.Hash, start, end uint64, valArr ValidatorQueue) error

func (*StakingDB) SetRoundValIndex

func (db *StakingDB) SetRoundValIndex(blockHash common.Hash, indexArr ValArrIndexQueue) error

func (*StakingDB) SetRoundValList

func (db *StakingDB) SetRoundValList(blockHash common.Hash, start, end uint64, valArr ValidatorQueue) error

func (*StakingDB) SubAccountStakeRc

func (db *StakingDB) SubAccountStakeRc(blockHash common.Hash, addr common.Address) error

sub the account staking Reference Count

type UnDelegateItem

type UnDelegateItem struct {
	// this is the `delegateAddress` + `nodeAddress` + `stakeBlockNumber`
	KeySuffix []byte
	Amount    *big.Int
}

type UnStakeItem

type UnStakeItem struct {
	// this is the nodeAddress
	KeySuffix       []byte
	StakingBlockNum uint64
}

type ValArrIndex

type ValArrIndex struct {
	Start uint64
	End   uint64
}

type ValArrIndexQueue

type ValArrIndexQueue []*ValArrIndex

func (ValArrIndexQueue) ConstantAppend

func (queue ValArrIndexQueue) ConstantAppend(index *ValArrIndex, size int) (*ValArrIndex, ValArrIndexQueue)

type Validator

type Validator struct {
	NodeAddress common.Address
	NodeId      discover.NodeID
	// bls public key
	BlsPubKey bls.PublicKey
	// The weight snapshot
	// NOTE:
	// converted from the weight snapshot of Candidate, they array order is:
	//
	// programVersion, candidate.shares, stakingBlocknum, stakingTxindex
	//
	// They origin type is: uint32, *big.int, uint64, uint32
	StakingWeight [SWeightItem]string
	// Validator's term in the consensus round
	ValidatorTerm uint32
}

the Validator info They are Simplified Candidate They are consensus nodes and Epoch nodes snapshot

func (*Validator) GetProgramVersion

func (val *Validator) GetProgramVersion() (uint32, error)

func (*Validator) GetShares

func (val *Validator) GetShares() (*big.Int, error)

func (*Validator) GetStakingBlockNumber

func (val *Validator) GetStakingBlockNumber() (uint64, error)

func (*Validator) GetStakingTxIndex

func (val *Validator) GetStakingTxIndex() (uint32, error)

func (*Validator) String

func (val *Validator) String() string

type ValidatorArray

type ValidatorArray struct {
	// the round start blockNumber or epoch start blockNumber
	Start uint64
	// the round end blockNumber or epoch blockNumber
	End uint64
	// the round validators or epoch validators
	Arr ValidatorQueue
}

some consensus round validators or current epoch validators

type ValidatorEx

type ValidatorEx struct {
	//NodeAddress common.Address
	NodeId discover.NodeID
	// bls public key
	BlsPubKey bls.PublicKey
	// The account used to initiate the staking
	StakingAddress common.Address
	// The account receive the block rewards and the staking rewards
	BenefitAddress common.Address
	// The tx index at the time of staking
	StakingTxIndex uint32
	// The version of the node process
	ProgramVersion uint32
	// Block height at the time of staking
	StakingBlockNum uint64
	// All vons of staking and delegated
	//Shares *big.Int
	Shares *hexutil.Big
	// Node desc
	Description
	// this is the term of validator in consensus round
	// [0, N]
	ValidatorTerm uint32
}

func (*ValidatorEx) String

func (vex *ValidatorEx) String() string

type ValidatorExQueue

type ValidatorExQueue = []*ValidatorEx

type ValidatorQueue

type ValidatorQueue []*Validator

func (ValidatorQueue) ValidatorSort

func (arr ValidatorQueue) ValidatorSort(removes NeedRemoveCans,
	compare func(slashs NeedRemoveCans, c, can *Validator) int)

Jump to

Keyboard shortcuts

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