types

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2021 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

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

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

DecodeMsg implements msgp.Decodable

func (*BCHBlock) EncodeMsg

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

EncodeMsg implements msgp.Encodable

func (*BCHBlock) Equal

func (b *BCHBlock) Equal(o *BCHBlock) bool

not check Nominations

func (*BCHBlock) MarshalMsg

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

MarshalMsg implements msgp.Marshaler

func (*BCHBlock) Msgsize

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

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

func (*BCHBlock) UnmarshalMsg

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

UnmarshalMsg implements msgp.Unmarshaler

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 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
	GetEpochs(start, end uint64) []*Epoch
}

These functions must be provided by a client connecting to a Bitcoin Cash's fullnode

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:

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