types

package
v0.0.29 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2022 License: LGPL-3.0 Imports: 23 Imported by: 3

Documentation

Index

Constants

View Source
const (
	// LockPeriodInEpoch is the number of epochs a undelegated token needs to be before it's released to the delegator's balance
	LockPeriodInEpoch = 7
	// LockPeriodInEpochV2 there is no extended locking time besides the current epoch time.
	LockPeriodInEpochV2 = 0
)
View Source
const (
	MaxNameLength            = 140
	MaxIdentityLength        = 140
	MaxWebsiteLength         = 140
	MaxSecurityContactLength = 140
	MaxDetailsLength         = 280
	BLSVerificationStr       = "harmony-one"
	TenThousand              = 10000
	APRHistoryLength         = 30
	SigningHistoryLength     = 30
)

Define validator staking related const

View Source
const MaxBLSPerValidator = 106

MaxBLSPerValidator ..

Variables

View Source
var (

	// ErrInvalidSelfDelegation ..
	ErrInvalidSelfDelegation = errors.New(
		"self delegation can not be less than min_self_delegation",
	)

	// ErrExcessiveBLSKeys ..
	ErrExcessiveBLSKeys = errors.New("more slot keys provided than allowed")
)
View Source
var (
	// ErrInvalidSig is a bad signature
	ErrInvalidSig = errors.New("invalid transaction v, r, s values")
)
View Source
var (

	// ErrInvalidStakingKind given when caller gives bad staking message kind
	ErrInvalidStakingKind = errors.New("bad staking kind")
)

Functions

func MarshalValidator

func MarshalValidator(validator Validator) ([]byte, error)

MarshalValidator marshals the validator object

func RLPDecodeStakeMsg

func RLPDecodeStakeMsg(payload []byte, d Directive) (interface{}, error)

RLPDecodeStakeMsg ..

func Sender

func Sender(signer Signer, tx *StakingTransaction) (common.Address, error)

Sender returns the address derived from the signature (V, R, S) using secp256k1 elliptic curve and an error if it failed deriving or upon an incorrect signature.

Sender may cache the address, allowing it to be used regardless of signing method. The cache is invalidated if the cached signer does not match the signer used in the current call.

func UpdateValidatorFromEditMsg

func UpdateValidatorFromEditMsg(validator *Validator, edit *EditValidator, epoch *big.Int) error

UpdateValidatorFromEditMsg updates validator from EditValidator message

func VerifyBLSKey

func VerifyBLSKey(pubKey *bls.SerializedPublicKey, pubKeySig *bls.SerializedSignature) error

VerifyBLSKey checks if the public BLS key matches the BLS signature

func VerifyBLSKeys

func VerifyBLSKeys(pubKeys []bls.SerializedPublicKey, pubKeySigs []bls.SerializedSignature) error

VerifyBLSKeys checks if the public BLS key at index i of pubKeys matches the BLS key signature at index i of pubKeysSigs.

Types

type APREntry

type APREntry struct {
	Epoch *big.Int    `json:"epoch"`
	Value numeric.Dec `json:"apr"`
}

APREntry ..

type AccumulatedOverLifetime

type AccumulatedOverLifetime struct {
	BlockReward *big.Int            `json:"reward-accumulated"`
	Signing     counters            `json:"blocks"`
	APR         numeric.Dec         `json:"apr"`
	EpochAPRs   []APREntry          `json:"epoch-apr"`
	EpochBlocks []EpochSigningEntry `json:"epoch-blocks"`
}

AccumulatedOverLifetime ..

type CollectRewards

type CollectRewards struct {
	DelegatorAddress common.Address `json:"delegator_address"`
}

CollectRewards - type for collecting token rewards

func (CollectRewards) Copy

func (v CollectRewards) Copy() StakeMsg

Copy returns a deep copy of the CollectRewards as a StakeMsg interface

func (CollectRewards) Equals

func (v CollectRewards) Equals(s CollectRewards) bool

Equals returns if v and s are equal

func (CollectRewards) Type

func (v CollectRewards) Type() Directive

Type of CollectRewards

type Commission

type Commission struct {
	CommissionRates
	UpdateHeight *big.Int `json:"update-height"`
}

Commission defines a commission parameters for a given validator.

type CommissionRates

type CommissionRates struct {
	// the commission rate charged to delegators, as a fraction
	Rate numeric.Dec `json:"rate"`
	// maximum commission rate which validator can ever charge, as a fraction
	MaxRate numeric.Dec `json:"max-rate"`
	// maximum increase of the validator commission every epoch, as a fraction
	MaxChangeRate numeric.Dec `json:"max-change-rate"`
}

CommissionRates defines the initial commission rates to be used for creating a validator.

func (CommissionRates) Copy

func (cr CommissionRates) Copy() CommissionRates

Copy deep copies the staking.CommissionRates

type Computed

type Computed struct {
	Signed            *big.Int    `json:"current-epoch-signed"`
	ToSign            *big.Int    `json:"current-epoch-to-sign"`
	BlocksLeftInEpoch uint64      `json:"-"`
	Percentage        numeric.Dec `json:"current-epoch-signing-percentage"`
	IsBelowThreshold  bool        `json:"-"`
}

Computed represents current epoch availability measures, mostly for RPC

func NewComputed

func NewComputed(
	signed, toSign *big.Int,
	blocksLeft uint64,
	percent numeric.Dec,
	isBelowNow bool) *Computed

NewComputed ..

func (Computed) String

func (c Computed) String() string

type CreateValidator

type CreateValidator struct {
	ValidatorAddress   common.Address `json:"validator-address"`
	Description        `json:"description"`
	CommissionRates    `json:"commission"`
	MinSelfDelegation  *big.Int                  `json:"min-self-delegation"`
	MaxTotalDelegation *big.Int                  `json:"max-total-delegation"`
	SlotPubKeys        []bls.SerializedPublicKey `json:"slot-pub-keys"`
	SlotKeySigs        []bls.SerializedSignature `json:"slot-key-sigs"`
	Amount             *big.Int                  `json:"amount"`
}

CreateValidator - type for creating a new validator

func (CreateValidator) Copy

func (v CreateValidator) Copy() StakeMsg

Copy returns a deep copy of the CreateValidator as a StakeMsg interface

func (CreateValidator) Type

func (v CreateValidator) Type() Directive

Type of CreateValidator

type CurrentEpochPerformance

type CurrentEpochPerformance struct {
	CurrentSigningPercentage Computed `json:"current-epoch-signing-percent"`
	Epoch                    uint64   `json:"epoch"`
	Block                    uint64   `json:"block"`
}

CurrentEpochPerformance represents validator performance in the context of whatever current epoch is

type Delegate

type Delegate struct {
	DelegatorAddress common.Address `json:"delegator_address"`
	ValidatorAddress common.Address `json:"validator_address"`
	Amount           *big.Int       `json:"amount"`
}

Delegate - type for delegating to a validator

func (Delegate) Copy

func (v Delegate) Copy() StakeMsg

Copy returns a deep copy of the Delegate as a StakeMsg interface

func (Delegate) Equals

func (v Delegate) Equals(s Delegate) bool

Equals returns if v and s are equal

func (Delegate) Type

func (v Delegate) Type() Directive

Type of Delegate

type Delegation

type Delegation struct {
	DelegatorAddress common.Address
	Amount           *big.Int
	Reward           *big.Int
	Undelegations    Undelegations
}

Delegation represents the bond with tokens held by an account. It is owned by one delegator, and is associated with the voting power of one validator.

func NewDelegation

func NewDelegation(delegatorAddr common.Address,
	amount *big.Int) Delegation

NewDelegation creates a new delegation object

func SetDifference

func SetDifference(xs, ys []Delegation) []Delegation

SetDifference ..

func (*Delegation) DeleteEntry

func (d *Delegation) DeleteEntry(epoch *big.Int)

DeleteEntry - delete an entry from the undelegation Opimize it

func (Delegation) Hash

func (d Delegation) Hash() common.Hash

Hash is a New256 hash of an RLP encoded Delegation

func (Delegation) MarshalJSON

func (d Delegation) MarshalJSON() ([]byte, error)

MarshalJSON ..

func (*Delegation) RemoveUnlockedUndelegations

func (d *Delegation) RemoveUnlockedUndelegations(
	curEpoch, lastEpochInCommittee *big.Int, lockPeriod int, noEarlyUnlock bool,
) *big.Int

RemoveUnlockedUndelegations removes all fully unlocked undelegations and returns the total sum

func (Delegation) String

func (d Delegation) String() string

func (*Delegation) TotalInUndelegation

func (d *Delegation) TotalInUndelegation() *big.Int

TotalInUndelegation - return the total amount of token in undelegation (locking period)

func (*Delegation) Undelegate

func (d *Delegation) Undelegate(epoch *big.Int, amt *big.Int) error

Undelegate - append entry to the undelegation

type DelegationIndex

type DelegationIndex struct {
	ValidatorAddress common.Address
	Index            uint64
	BlockNum         *big.Int
}

DelegationIndex stored the index of a delegation in the validator's delegation list

type DelegationIndexes

type DelegationIndexes []DelegationIndex

DelegationIndexes is a slice of DelegationIndex

type Delegations

type Delegations []Delegation

Delegations ..

func (Delegations) String

func (d Delegations) String() string

String ..

type Description

type Description struct {
	Name            string `json:"name"`             // name
	Identity        string `json:"identity"`         // optional identity signature (ex. UPort or Keybase)
	Website         string `json:"website"`          // optional website link
	SecurityContact string `json:"security-contact"` // optional security contact info
	Details         string `json:"details"`          // optional details
}

Description - some possible IRL connections

func UpdateDescription

func UpdateDescription(d1, d2 Description) (Description, error)

UpdateDescription returns a new Description object with d1 as the base and the fields that's not empty in d2 updated accordingly. An error is returned if the resulting description fields have invalid length.

func (Description) EnsureLength

func (d Description) EnsureLength() (Description, error)

EnsureLength ensures the length of a validator's description.

type Directive

type Directive byte

Directive says what kind of payload follows

const (
	// DirectiveCreateValidator ...
	DirectiveCreateValidator Directive = iota
	// DirectiveEditValidator ...
	DirectiveEditValidator
	// DirectiveDelegate ...
	DirectiveDelegate
	// DirectiveUndelegate ...
	DirectiveUndelegate
	// DirectiveCollectRewards ...
	DirectiveCollectRewards
)

func (Directive) String

func (d Directive) String() string

type EIP155Signer

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

EIP155Signer implements Signer using the EIP155 rules.

func NewEIP155Signer

func NewEIP155Signer(chainID *big.Int) EIP155Signer

NewEIP155Signer creates a EIP155Signer given chainID.

func (EIP155Signer) Equal

func (s EIP155Signer) Equal(s2 Signer) bool

Equal checks if the given EIP155Signer is equal to another Signer.

func (EIP155Signer) Hash

Hash returns the hash to be signed by the sender. It does not uniquely identify the transaction.

func (EIP155Signer) Sender

Sender returns the sender address of the given signer.

func (EIP155Signer) SignatureValues

func (s EIP155Signer) SignatureValues(
	tx *StakingTransaction, sig []byte,
) (R, S, V *big.Int, err error)

SignatureValues returns signature values. This signature needs to be in the [R || S || V] format where V is 0 or 1.

type EditValidator

type EditValidator struct {
	ValidatorAddress   common.Address `json:"validator-address"`
	Description        `json:"description"`
	CommissionRate     *numeric.Dec             `json:"commission-rate" rlp:"nil"`
	MinSelfDelegation  *big.Int                 `json:"min-self-delegation" rlp:"nil"`
	MaxTotalDelegation *big.Int                 `json:"max-total-delegation" rlp:"nil"`
	SlotKeyToRemove    *bls.SerializedPublicKey `json:"slot-key-to_remove" rlp:"nil"`
	SlotKeyToAdd       *bls.SerializedPublicKey `json:"slot-key-to_add" rlp:"nil"`
	SlotKeyToAddSig    *bls.SerializedSignature `json:"slot-key-to-add-sig" rlp:"nil"`
	EPOSStatus         effective.Eligibility    `json:"epos-eligibility-status"`
}

EditValidator - type for edit existing validator

func (EditValidator) Copy

func (v EditValidator) Copy() StakeMsg

Copy returns a deep copy of the EditValidator as a StakeMsg interface

func (EditValidator) Type

func (v EditValidator) Type() Directive

Type of EditValidator

type EpochSigningEntry

type EpochSigningEntry struct {
	Epoch  *big.Int `json:"epoch"`
	Blocks counters `json:"blocks"`
}

EpochSigningEntry ..

type MigrationMsg

type MigrationMsg struct {
	From common.Address `json:"from" rlp:"nil"`
	To   common.Address `json:"to" rlp:"nil"`
}

Migration Msg - type for switching delegation from one user to next

func (MigrationMsg) Copy

func (v MigrationMsg) Copy() MigrationMsg

func (MigrationMsg) Equals

func (v MigrationMsg) Equals(s MigrationMsg) bool

type Signer

type Signer interface {
	// Sender returns the sender address of the transaction.
	Sender(tx *StakingTransaction) (common.Address, error)
	// SignatureValues returns the raw R, S, V values corresponding to the
	// given signature.
	SignatureValues(tx *StakingTransaction, sig []byte) (r, s, v *big.Int, err error)
	// Hash returns the hash to be signed.
	Hash(tx *StakingTransaction) common.Hash
	// Equal returns true if the given signer is the same as the receiver.
	Equal(s Signer) bool
}

Signer encapsulates transaction signature handling. Note that this interface is not a stable API and may change at any time to accommodate new protocol rules.

type StakeMsg

type StakeMsg interface {
	Type() Directive
	Copy() StakeMsg
}

StakeMsg defines the interface of Stake Message

type StakeMsgFulfiller

type StakeMsgFulfiller func() (Directive, interface{})

StakeMsgFulfiller is signature of callback intended to produce the StakeMsg

type StakingTransaction

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

StakingTransaction is a record captuing all staking operations

func NewStakingTransaction

func NewStakingTransaction(
	nonce, gasLimit uint64, gasPrice *big.Int, f StakeMsgFulfiller,
) (*StakingTransaction, error)

NewStakingTransaction produces a new staking transaction record

func Sign

Sign signs the stake using the given signer and private key

func (*StakingTransaction) ChainID

func (tx *StakingTransaction) ChainID() *big.Int

ChainID is what chain this staking transaction for

func (*StakingTransaction) Copy

Copy returns a copy of the transaction.

func (*StakingTransaction) Cost

func (tx *StakingTransaction) Cost() (*big.Int, error)

Cost ..

func (*StakingTransaction) Data

func (tx *StakingTransaction) Data() []byte

Data ..

func (*StakingTransaction) DecodeRLP

func (tx *StakingTransaction) DecodeRLP(s *rlp.Stream) error

DecodeRLP implements rlp.Decoder

func (*StakingTransaction) EncodeRLP

func (tx *StakingTransaction) EncodeRLP(w io.Writer) error

EncodeRLP implements rlp.Encoder

func (*StakingTransaction) From

func (tx *StakingTransaction) From() *atomic.Value

From returns the sender address of the transaction

func (*StakingTransaction) GasLimit

func (tx *StakingTransaction) GasLimit() uint64

GasLimit returns gas of StakingTransaction.

func (*StakingTransaction) GasPrice

func (tx *StakingTransaction) GasPrice() *big.Int

GasPrice returns price of StakingTransaction.

func (*StakingTransaction) Hash

func (tx *StakingTransaction) Hash() common.Hash

Hash hashes the RLP encoding of tx. It uniquely identifies the transaction.

func (*StakingTransaction) IsEthCompatible

func (tx *StakingTransaction) IsEthCompatible() bool

IsEthCompatible returns whether the txn is ethereum compatible

func (*StakingTransaction) Nonce

func (tx *StakingTransaction) Nonce() uint64

Nonce returns nonce of staking tx

func (*StakingTransaction) Protected

func (tx *StakingTransaction) Protected() bool

Protected ..

func (*StakingTransaction) RLPEncodeStakeMsg

func (tx *StakingTransaction) RLPEncodeStakeMsg() (by []byte, err error)

RLPEncodeStakeMsg ..

func (*StakingTransaction) RawSignatureValues

func (tx *StakingTransaction) RawSignatureValues() (*big.Int, *big.Int, *big.Int)

RawSignatureValues return raw signature values.

func (*StakingTransaction) SenderAddress

func (tx *StakingTransaction) SenderAddress() (common.Address, error)

SenderAddress returns the address of staking transaction sender

func (*StakingTransaction) SetRawSignature

func (tx *StakingTransaction) SetRawSignature(v, r, s *big.Int)

func (*StakingTransaction) ShardID

func (tx *StakingTransaction) ShardID() uint32

ShardID returns which shard id this transaction was signed for, implicitly shard 0.

func (*StakingTransaction) Size

Size ..

func (*StakingTransaction) StakingMessage

func (tx *StakingTransaction) StakingMessage() interface{}

StakingMessage returns the stake message of staking transaction

func (*StakingTransaction) StakingType

func (tx *StakingTransaction) StakingType() Directive

StakingType returns the type of staking transaction

func (*StakingTransaction) To

func (tx *StakingTransaction) To() *common.Address

To ..

func (*StakingTransaction) ToShardID

func (tx *StakingTransaction) ToShardID() uint32

ToShardID returns which shard id this transaction was signed for, implicitly shard 0.

func (*StakingTransaction) Value

func (tx *StakingTransaction) Value() *big.Int

Value ..

func (*StakingTransaction) WithSignature

func (tx *StakingTransaction) WithSignature(signer Signer, sig []byte) (*StakingTransaction, error)

WithSignature returns a new transaction with the given signature.

type StakingTransactions

type StakingTransactions []*StakingTransaction

StakingTransactions is a stake slice type for basic sorting.

func (StakingTransactions) GetRlp

func (s StakingTransactions) GetRlp(i int) []byte

GetRlp implements Rlpable and returns the i'th element of s in rlp.

func (StakingTransactions) Len

func (s StakingTransactions) Len() int

Len ..

type Undelegate

type Undelegate struct {
	DelegatorAddress common.Address `json:"delegator_address"`
	ValidatorAddress common.Address `json:"validator_address"`
	Amount           *big.Int       `json:"amount"`
}

Undelegate - type for removing delegation responsibility

func (Undelegate) Copy

func (v Undelegate) Copy() StakeMsg

Copy returns a deep copy of the Undelegate as a StakeMsg interface

func (Undelegate) Equals

func (v Undelegate) Equals(s Undelegate) bool

Equals returns if v and s are equal

func (Undelegate) Type

func (v Undelegate) Type() Directive

Type of Undelegate

type Undelegation

type Undelegation struct {
	Amount *big.Int `json:"amount"`
	Epoch  *big.Int `json:"epoch"`
}

Undelegation represents one undelegation entry

type Undelegations

type Undelegations []Undelegation

Undelegations ..

func (Undelegations) String

func (u Undelegations) String() string

String ..

type Validator

type Validator struct {
	// ECDSA address of the validator
	Address common.Address `json:"address"`
	// The BLS public key of the validator for consensus
	SlotPubKeys []bls.SerializedPublicKey `json:"bls-public-keys"`
	// The number of the last epoch this validator is
	// selected in committee (0 means never selected)
	LastEpochInCommittee *big.Int `json:"last-epoch-in-committee"`
	// validator's self declared minimum self delegation
	MinSelfDelegation *big.Int `json:"min-self-delegation"`
	// maximum total delegation allowed
	MaxTotalDelegation *big.Int `json:"max-total-delegation"`
	// Is the validator active in participating
	// committee selection process or not
	Status effective.Eligibility `json:"-"`
	// commission parameters
	Commission
	// description for the validator
	Description
	// CreationHeight is the height of creation
	CreationHeight *big.Int `json:"creation-height"`
}

Validator - data fields for a validator

func CreateValidatorFromNewMsg

func CreateValidatorFromNewMsg(
	val *CreateValidator, blockNum, epoch *big.Int,
) (*Validator, error)

CreateValidatorFromNewMsg creates validator from NewValidator message

func UnmarshalValidator

func UnmarshalValidator(by []byte) (Validator, error)

UnmarshalValidator unmarshal binary into Validator object

func (*Validator) SanityCheck

func (v *Validator) SanityCheck() error

SanityCheck checks basic requirements of a validator

func (Validator) String

func (v Validator) String() string

String returns a human readable string representation of a validator.

type ValidatorRPCEnhanced

type ValidatorRPCEnhanced struct {
	Wrapper              ValidatorWrapper         `json:"validator"`
	Performance          *CurrentEpochPerformance `json:"current-epoch-performance"`
	ComputedMetrics      *ValidatorStats          `json:"metrics"`
	TotalDelegated       *big.Int                 `json:"total-delegation"`
	CurrentlyInCommittee bool                     `json:"currently-in-committee"`
	EPoSStatus           string                   `json:"epos-status"`
	EPoSWinningStake     *numeric.Dec             `json:"epos-winning-stake"`
	BootedStatus         *string                  `json:"booted-status"`
	ActiveStatus         string                   `json:"active-status"`
	Lifetime             *AccumulatedOverLifetime `json:"lifetime"`
}

ValidatorRPCEnhanced contains extra information for RPC consumer

type ValidatorSnapshot

type ValidatorSnapshot struct {
	Validator *ValidatorWrapper
	Epoch     *big.Int
}

ValidatorSnapshot contains validator snapshot and the corresponding epoch

func (ValidatorSnapshot) RawStakePerSlot

func (snapshot ValidatorSnapshot) RawStakePerSlot() numeric.Dec

RawStakePerSlot return raw stake of each slot key. If HIP16 was activated at that apoch, it only calculate raw stake for keys not exceed the slotsLimit.

type ValidatorSnapshotReader

type ValidatorSnapshotReader interface {
	ReadValidatorSnapshotAtEpoch(
		epoch *big.Int,
		addr common.Address,
	) (*ValidatorSnapshot, error)
}

ValidatorSnapshotReader ..

type ValidatorStats

type ValidatorStats struct {
	// APRs is the APR history containing APR's of epochs
	APRs []APREntry `json:"-"`
	// TotalEffectiveStake is the total effective stake this validator has
	TotalEffectiveStake numeric.Dec `json:"-"`
	// MetricsPerShard ..
	MetricsPerShard []VoteWithCurrentEpochEarning `json:"by-bls-key"`
	// BootedStatus
	BootedStatus effective.BootedStatus `json:"-"`
}

ValidatorStats to record validator's performance and history records

func NewEmptyStats

func NewEmptyStats() *ValidatorStats

NewEmptyStats ..

func (ValidatorStats) String

func (s ValidatorStats) String() string

type ValidatorWrapper

type ValidatorWrapper struct {
	Validator
	Delegations Delegations
	//
	Counters counters `json:"-"`
	// All the rewarded accumulated so far
	BlockReward *big.Int `json:"-"`
}

ValidatorWrapper contains validator, its delegation information

func (ValidatorWrapper) MarshalJSON

func (w ValidatorWrapper) MarshalJSON() ([]byte, error)

MarshalJSON ..

func (*ValidatorWrapper) SanityCheck

func (w *ValidatorWrapper) SanityCheck() error

SanityCheck checks the basic requirements

func (ValidatorWrapper) String

func (w ValidatorWrapper) String() string

func (*ValidatorWrapper) TotalDelegation

func (w *ValidatorWrapper) TotalDelegation() *big.Int

TotalDelegation - return the total amount of token in delegation

type VoteWithCurrentEpochEarning

type VoteWithCurrentEpochEarning struct {
	Vote   votepower.VoteOnSubcomittee `json:"key"`
	Earned *big.Int                    `json:"earned-reward"`
}

VoteWithCurrentEpochEarning ..

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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