types

package
v1.10.2 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2021 License: MIT Imports: 23 Imported by: 5

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 added in v1.3.0

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

MarshalValidator marshals the validator object

func RLPDecodeStakeMsg added in v1.3.0

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 added in v1.3.0

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

UpdateValidatorFromEditMsg updates validator from EditValidator message

func VerifyBLSKey added in v1.3.2

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

VerifyBLSKey checks if the public BLS key matches the BLS signature

func VerifyBLSKeys added in v1.3.2

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 added in v1.10.0

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

APREntry ..

type AccumulatedOverLifetime added in v1.3.6

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 added in v1.3.0

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

CollectRewards - type for collecting token rewards

func (CollectRewards) Copy added in v1.3.0

func (v CollectRewards) Copy() StakeMsg

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

func (CollectRewards) Type added in v1.3.0

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 added in v1.3.11

func (cr CommissionRates) Copy() CommissionRates

Copy deep copies the staking.CommissionRates

type Computed added in v1.3.4

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 added in v1.3.5

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

NewComputed ..

func (Computed) String added in v1.3.5

func (c Computed) String() string

type CreateValidator added in v1.3.0

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 added in v1.3.0

func (v CreateValidator) Copy() StakeMsg

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

func (CreateValidator) Type added in v1.3.0

func (v CreateValidator) Type() Directive

Type of CreateValidator

type CurrentEpochPerformance added in v1.3.5

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

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 added in v1.3.0

func (v Delegate) Copy() StakeMsg

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

func (Delegate) Type added in v1.3.0

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 added in v1.3.3

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

SetDifference ..

func (*Delegation) DeleteEntry added in v1.3.0

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

DeleteEntry - delete an entry from the undelegation Opimize it

func (Delegation) Hash added in v1.3.3

func (d Delegation) Hash() common.Hash

Hash is a New256 hash of an RLP encoded Delegation

func (Delegation) MarshalJSON added in v1.3.3

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

MarshalJSON ..

func (*Delegation) RemoveUnlockedUndelegations added in v1.3.0

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

RemoveUnlockedUndelegations removes all fully unlocked undelegations and returns the total sum

func (Delegation) String

func (d Delegation) String() string

func (*Delegation) TotalInUndelegation added in v1.3.0

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

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

func (*Delegation) Undelegate added in v1.3.0

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

Undelegate - append entry to the undelegation

type DelegationIndex added in v1.3.0

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 added in v1.3.5

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 added in v1.3.0

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 added in v1.3.0

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 added in v1.3.0

func (v EditValidator) Copy() StakeMsg

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

func (EditValidator) Type added in v1.3.0

func (v EditValidator) Type() Directive

Type of EditValidator

type EpochSigningEntry added in v1.10.0

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

EpochSigningEntry ..

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 added in v1.3.0

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 added in v1.3.0

Copy returns a copy of the transaction.

func (*StakingTransaction) Cost added in v1.3.2

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

Cost ..

func (*StakingTransaction) Data added in v1.3.2

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 added in v1.10.1

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

From returns the sender address of the transaction

func (*StakingTransaction) GasLimit added in v1.10.1

func (tx *StakingTransaction) GasLimit() uint64

GasLimit returns gas of StakingTransaction.

func (*StakingTransaction) GasPrice added in v1.3.2

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 added in v1.10.2

func (tx *StakingTransaction) IsEthCompatible() bool

IsEthCompatible returns whether the txn is ethereum compatible

func (*StakingTransaction) Nonce added in v1.3.0

func (tx *StakingTransaction) Nonce() uint64

Nonce returns nonce of staking tx

func (*StakingTransaction) Protected added in v1.3.2

func (tx *StakingTransaction) Protected() bool

Protected ..

func (*StakingTransaction) RLPEncodeStakeMsg added in v1.3.0

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

RLPEncodeStakeMsg ..

func (*StakingTransaction) RawSignatureValues added in v1.3.0

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

RawSignatureValues return raw signature values.

func (*StakingTransaction) SenderAddress added in v1.3.0

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

SenderAddress returns the address of staking transaction sender

func (*StakingTransaction) ShardID added in v1.3.2

func (tx *StakingTransaction) ShardID() uint32

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

func (*StakingTransaction) Size added in v1.3.2

Size ..

func (*StakingTransaction) StakingMessage added in v1.3.0

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

StakingMessage returns the stake message of staking transaction

func (*StakingTransaction) StakingType added in v1.3.0

func (tx *StakingTransaction) StakingType() Directive

StakingType returns the type of staking transaction

func (*StakingTransaction) To added in v1.3.2

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

To ..

func (*StakingTransaction) ToShardID added in v1.10.1

func (tx *StakingTransaction) ToShardID() uint32

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

func (*StakingTransaction) Value added in v1.3.2

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 added in v1.3.0

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

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

func (StakingTransactions) Len added in v1.3.0

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 added in v1.3.0

func (v Undelegate) Copy() StakeMsg

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

func (Undelegate) Type added in v1.3.0

func (v Undelegate) Type() Directive

Type of Undelegate

type Undelegation added in v1.3.0

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

Undelegation represents one undelegation entry

type Undelegations added in v1.3.3

type Undelegations []Undelegation

Undelegations ..

func (Undelegations) String added in v1.3.3

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 added in v1.3.0

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

CreateValidatorFromNewMsg creates validator from NewValidator message

func UnmarshalValidator added in v1.3.0

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

UnmarshalValidator unmarshal binary into Validator object

func (*Validator) SanityCheck added in v1.3.2

func (v *Validator) SanityCheck() error

SanityCheck checks basic requirements of a validator

func (Validator) String added in v1.3.0

func (v Validator) String() string

String returns a human readable string representation of a validator.

type ValidatorRPCEnhanced added in v1.10.0

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 added in v1.3.8

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

ValidatorSnapshot contains validator snapshot and the corresponding epoch

type ValidatorSnapshotReader added in v1.3.3

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

ValidatorSnapshotReader ..

type ValidatorStats added in v1.3.0

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 added in v1.3.5

func NewEmptyStats() *ValidatorStats

NewEmptyStats ..

func (ValidatorStats) String added in v1.3.5

func (s ValidatorStats) String() string

type ValidatorWrapper added in v1.3.0

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 added in v1.3.3

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

MarshalJSON ..

func (*ValidatorWrapper) SanityCheck added in v1.3.0

func (w *ValidatorWrapper) SanityCheck() error

SanityCheck checks the basic requirements

func (ValidatorWrapper) String added in v1.3.3

func (w ValidatorWrapper) String() string

func (*ValidatorWrapper) TotalDelegation added in v1.3.0

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

TotalDelegation - return the total amount of token in delegation

type VoteWithCurrentEpochEarning added in v1.3.7

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