types

package
v0.4.4-p1 Latest Latest
Warning

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

Go to latest
Published: May 23, 2022 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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) DecodeMsg

func (z *Epoch) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (*Epoch) EncodeMsg

func (z *Epoch) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (*Epoch) MarshalMsg

func (z *Epoch) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (*Epoch) Msgsize

func (z *Epoch) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*Epoch) UnmarshalMsg

func (z *Epoch) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

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() any

func (*NominationHeap) Push added in v0.4.0

func (h *NominationHeap) Push(x any)

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) 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:

  1. retire itself with no pending reward
  2. 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 GetActiveValidators(vals []*Validator, 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 GetUpdateValidatorSet added in v0.4.3

func GetUpdateValidatorSet(currentValidators, newValidators []*Validator) []*Validator

func (*Validator) DecodeMsg

func (z *Validator) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (*Validator) EncodeMsg

func (z *Validator) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (*Validator) MarshalMsg

func (z *Validator) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (*Validator) Msgsize

func (z *Validator) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*Validator) UnmarshalMsg

func (z *Validator) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

Jump to

Keyboard shortcuts

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