Documentation ¶
Index ¶
- Variables
- type BCHBlock
- func (z *BCHBlock) DecodeMsg(dc *msgp.Reader) (err error)
- func (z *BCHBlock) EncodeMsg(en *msgp.Writer) (err error)
- func (b *BCHBlock) Equal(o *BCHBlock) bool
- func (z *BCHBlock) MarshalMsg(b []byte) (o []byte, err error)
- func (z *BCHBlock) Msgsize() (s int)
- func (z *BCHBlock) UnmarshalMsg(bts []byte) (o []byte, err error)
- type Epoch
- type Nomination
- 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 RpcClient
- 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 ¶
This section is empty.
Variables ¶
var ( CreateValidatorCoinLtInitAmount = errors.New("Validator's staking coin less than init amount") ValidatorAddressAlreadyExists = errors.New("Validator's address already exists") ValidatorPubkeyAlreadyExists = errors.New("Validator's pubkey already exists") )
var MaxActiveValidatorNum = 30
Functions ¶
This section is empty.
Types ¶
type BCHBlock ¶
type BCHBlock struct { Height int64 Timestamp int64 HashId [32]byte ParentBlk [32]byte Nominations []Nomination }
This struct contains the useful information of a BCH block
func (*BCHBlock) MarshalMsg ¶
MarshalMsg implements msgp.Marshaler
type Epoch ¶
type Epoch struct { StartHeight int64 EndTime int64 Duration int64 ValMapByPubkey map[[32]byte]*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 PendingReward ¶
type PendingReward struct { Address [20]byte `msgp:"address"` // Validator's operator address in moeing 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 RpcClient ¶
type RpcClient interface { GetLatestHeight() int64 GetBlockByHeight(height int64) *BCHBlock GetBlockByHash(hash [32]byte) *BCHBlock }
These functions must be provided by a client connecting to a Bitcoin Cash's fullnode
type StakingInfo ¶
type StakingInfo struct { CurrEpochNum int64 `msgp:"curr_epoch_num"` Validators []*Validator `msgp:"validators"` 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 vote 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 moeing 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 (*Validator) MarshalMsg ¶
MarshalMsg implements msgp.Marshaler