Documentation ¶
Index ¶
- Constants
- Variables
- type Epoch
- type Nomination
- type NominationHeap
- func (z *NominationHeap) DecodeMsg(dc *msgp.Reader) (err error)
- func (z NominationHeap) EncodeMsg(en *msgp.Writer) (err error)
- func (h NominationHeap) Len() int
- func (h NominationHeap) Less(i, j int) bool
- func (z NominationHeap) MarshalMsg(b []byte) (o []byte, err error)
- func (z NominationHeap) Msgsize() (s int)
- func (h *NominationHeap) Pop() interface{}
- func (h *NominationHeap) Push(x interface{})
- func (h NominationHeap) Swap(i, j int)
- func (z *NominationHeap) UnmarshalMsg(bts []byte) (o []byte, err error)
- type PendingReward
- func (z *PendingReward) DecodeMsg(dc *msgp.Reader) (err error)
- func (z *PendingReward) EncodeMsg(en *msgp.Writer) (err error)
- func (z *PendingReward) MarshalMsg(b []byte) (o []byte, err error)
- func (z *PendingReward) Msgsize() (s int)
- func (z *PendingReward) UnmarshalMsg(bts []byte) (o []byte, err error)
- type StakingInfo
- func (si *StakingInfo) AddValidator(addr [20]byte, pubkey [32]byte, intro string, stakedCoins [32]byte, ...) error
- func (si *StakingInfo) ClearRewardsOf(addr [20]byte) (totalCleared *uint256.Int)
- func (z *StakingInfo) DecodeMsg(dc *msgp.Reader) (err error)
- func (z *StakingInfo) EncodeMsg(en *msgp.Writer) (err error)
- func (si *StakingInfo) GetActiveValidators(minStakedCoins *uint256.Int) []*Validator
- func (si *StakingInfo) GetCurrRewardMapByAddr() map[[20]byte]*PendingReward
- func (si *StakingInfo) GetUselessValidators() map[[20]byte]struct{}
- func (si *StakingInfo) GetValMapByAddr() map[[20]byte]*Validator
- func (si *StakingInfo) GetValMapByPubkey() map[[32]byte]*Validator
- func (si *StakingInfo) GetValidatorByAddr(addr [20]byte) *Validator
- func (si *StakingInfo) GetValidatorByPubkey(pubkey [32]byte) *Validator
- func (z *StakingInfo) MarshalMsg(b []byte) (o []byte, err error)
- func (z *StakingInfo) Msgsize() (s int)
- func (z *StakingInfo) UnmarshalMsg(bts []byte) (o []byte, err error)
- type Validator
Constants ¶
const MaxActiveValidatorNum = 30
Variables ¶
var ( ValidatorAddressAlreadyExists = errors.New("Validator's address already exists") ValidatorPubkeyAlreadyExists = errors.New("Validator's pubkey already exists") )
Functions ¶
This section is empty.
Types ¶
type Epoch ¶
type Epoch struct { Number int64 StartHeight int64 EndTime int64 Nominations []*Nomination }
An epoch elects several validators in NumBlocksInEpoch blocks
func (*Epoch) MarshalMsg ¶
MarshalMsg implements msgp.Marshaler
type Nomination ¶
type Nomination struct { Pubkey [32]byte // The validator's ED25519 pubkey used in tendermint NominatedCount int64 }
Currently the first Vout in a coinbase transaction can nominate one validator with one vote In the future it maybe extend to nominate multiple validators with different weights
func (*Nomination) DecodeMsg ¶
func (z *Nomination) DecodeMsg(dc *msgp.Reader) (err error)
DecodeMsg implements msgp.Decodable
func (*Nomination) EncodeMsg ¶
func (z *Nomination) EncodeMsg(en *msgp.Writer) (err error)
EncodeMsg implements msgp.Encodable
func (*Nomination) MarshalMsg ¶
func (z *Nomination) MarshalMsg(b []byte) (o []byte, err error)
MarshalMsg implements msgp.Marshaler
func (*Nomination) Msgsize ¶
func (z *Nomination) Msgsize() (s int)
Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message
func (*Nomination) UnmarshalMsg ¶
func (z *Nomination) UnmarshalMsg(bts []byte) (o []byte, err error)
UnmarshalMsg implements msgp.Unmarshaler
type NominationHeap ¶ added in v0.4.0
type NominationHeap []*Nomination
An NominationHeap is a max-heap of *Nomination
func (*NominationHeap) DecodeMsg ¶ added in v0.4.0
func (z *NominationHeap) DecodeMsg(dc *msgp.Reader) (err error)
DecodeMsg implements msgp.Decodable
func (NominationHeap) EncodeMsg ¶ added in v0.4.0
func (z NominationHeap) EncodeMsg(en *msgp.Writer) (err error)
EncodeMsg implements msgp.Encodable
func (NominationHeap) Len ¶ added in v0.4.0
func (h NominationHeap) Len() int
func (NominationHeap) Less ¶ added in v0.4.0
func (h NominationHeap) Less(i, j int) bool
func (NominationHeap) MarshalMsg ¶ added in v0.4.0
func (z NominationHeap) MarshalMsg(b []byte) (o []byte, err error)
MarshalMsg implements msgp.Marshaler
func (NominationHeap) Msgsize ¶ added in v0.4.0
func (z NominationHeap) Msgsize() (s int)
Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message
func (*NominationHeap) Pop ¶ added in v0.4.0
func (h *NominationHeap) Pop() interface{}
func (*NominationHeap) Push ¶ added in v0.4.0
func (h *NominationHeap) Push(x interface{})
func (NominationHeap) Swap ¶ added in v0.4.0
func (h NominationHeap) Swap(i, j int)
func (*NominationHeap) UnmarshalMsg ¶ added in v0.4.0
func (z *NominationHeap) UnmarshalMsg(bts []byte) (o []byte, err error)
UnmarshalMsg implements msgp.Unmarshaler
type PendingReward ¶
type PendingReward struct { Address [20]byte `msgp:"address"` // Validator's operator address in smartbch chain EpochNum int64 `msgp:"epoch_num"` // During which epoch were the rewards got? Amount [32]byte `msgp:"amount"` // amount of rewards }
Because EpochCountBeforeRewardMature >= 1, some rewards will be pending for a while before mature
func (*PendingReward) DecodeMsg ¶
func (z *PendingReward) DecodeMsg(dc *msgp.Reader) (err error)
DecodeMsg implements msgp.Decodable
func (*PendingReward) EncodeMsg ¶
func (z *PendingReward) EncodeMsg(en *msgp.Writer) (err error)
EncodeMsg implements msgp.Encodable
func (*PendingReward) MarshalMsg ¶
func (z *PendingReward) MarshalMsg(b []byte) (o []byte, err error)
MarshalMsg implements msgp.Marshaler
func (*PendingReward) Msgsize ¶
func (z *PendingReward) Msgsize() (s int)
Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message
func (*PendingReward) UnmarshalMsg ¶
func (z *PendingReward) UnmarshalMsg(bts []byte) (o []byte, err error)
UnmarshalMsg implements msgp.Unmarshaler
type StakingInfo ¶
type StakingInfo struct { GenesisMainnetBlockHeight int64 `msgp:"genesis_mainnet_block_height"` CurrEpochNum int64 `msgp:"curr_epoch_num"` Validators []*Validator `msgp:"validators"` ValidatorsUpdate []*Validator `msgp:"validators_update"` PendingRewards []*PendingReward `msgp:"pending_rewards"` }
This struct is stored in the world state. All the staking-related operations manipulate it.
func (*StakingInfo) AddValidator ¶
func (si *StakingInfo) AddValidator(addr [20]byte, pubkey [32]byte, intro string, stakedCoins [32]byte, rewardTo [20]byte) error
Append new entry to si.Validators. Pubkey and Address must be unique.
func (*StakingInfo) ClearRewardsOf ¶
func (si *StakingInfo) ClearRewardsOf(addr [20]byte) (totalCleared *uint256.Int)
Clear all the pending rewards belonging to an validator. Return the accumulated cleared amount.
func (*StakingInfo) DecodeMsg ¶
func (z *StakingInfo) DecodeMsg(dc *msgp.Reader) (err error)
DecodeMsg implements msgp.Decodable
func (*StakingInfo) EncodeMsg ¶
func (z *StakingInfo) EncodeMsg(en *msgp.Writer) (err error)
EncodeMsg implements msgp.Encodable
func (*StakingInfo) GetActiveValidators ¶
func (si *StakingInfo) GetActiveValidators(minStakedCoins *uint256.Int) []*Validator
Returns current validators on duty, who must have enough coins staked and be not in a retiring process only update validator voting power on switchEpoch
func (*StakingInfo) GetCurrRewardMapByAddr ¶
func (si *StakingInfo) GetCurrRewardMapByAddr() map[[20]byte]*PendingReward
Get the pending rewards which are got in current epoch
func (*StakingInfo) GetUselessValidators ¶
func (si *StakingInfo) GetUselessValidators() map[[20]byte]struct{}
Get useless validators who have zero voting power and no pending reward entries there has two scenario one validator may be useless:
- retire itself with no pending reward
- inactive validator with no vote power and pending reward in prev epoch, which may escape slash if it votes nothing after double sign !!! maybe there should have more epoch not one.
func (*StakingInfo) GetValMapByAddr ¶
func (si *StakingInfo) GetValMapByAddr() map[[20]byte]*Validator
Change si.Validators into a map with addresses as keys
func (*StakingInfo) GetValMapByPubkey ¶
func (si *StakingInfo) GetValMapByPubkey() map[[32]byte]*Validator
Change si.Validators into a map with pubkeys as keys
func (*StakingInfo) GetValidatorByAddr ¶
func (si *StakingInfo) GetValidatorByAddr(addr [20]byte) *Validator
Find a validator with matching address
func (*StakingInfo) GetValidatorByPubkey ¶
func (si *StakingInfo) GetValidatorByPubkey(pubkey [32]byte) *Validator
Find a validator with matching pubkey
func (*StakingInfo) MarshalMsg ¶
func (z *StakingInfo) MarshalMsg(b []byte) (o []byte, err error)
MarshalMsg implements msgp.Marshaler
func (*StakingInfo) Msgsize ¶
func (z *StakingInfo) Msgsize() (s int)
Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message
func (*StakingInfo) UnmarshalMsg ¶
func (z *StakingInfo) UnmarshalMsg(bts []byte) (o []byte, err error)
UnmarshalMsg implements msgp.Unmarshaler
type Validator ¶
type Validator struct { Address [20]byte `msgp:"address"` // Validator's address in smartbch chain Pubkey [32]byte `msgp:"pubkey"` // Validator's pubkey for tendermint RewardTo [20]byte `msgp:"reward_to"` // where validator's reward goes into VotingPower int64 `msgp:"voting_power"` Introduction string `msgp:"introduction"` // a short introduction StakedCoins [32]byte `msgp:"staked_coins"` IsRetiring bool `msgp:"is_retiring"` // whether this validator is in a retiring process }
func GetActiveValidators ¶ added in v0.3.0
func (*Validator) MarshalMsg ¶
MarshalMsg implements msgp.Marshaler