Documentation ¶
Index ¶
- Constants
- Variables
- func MarshalValidator(validator Validator) ([]byte, error)
- func RLPDecodeStakeMsg(payload []byte, d Directive) (interface{}, error)
- func Sender(signer Signer, tx *StakingTransaction) (common.Address, error)
- func UpdateValidatorFromEditMsg(validator *Validator, edit *EditValidator, epoch *big.Int) error
- func VerifyBLSKey(pubKey *bls.SerializedPublicKey, pubKeySig *bls.SerializedSignature) error
- func VerifyBLSKeys(pubKeys []bls.SerializedPublicKey, pubKeySigs []bls.SerializedSignature) error
- type APREntry
- type AccumulatedOverLifetime
- type CollectRewards
- type Commission
- type CommissionRates
- type Computed
- type CreateValidator
- type CurrentEpochPerformance
- type Delegate
- type Delegation
- func (d *Delegation) DeleteEntry(epoch *big.Int)
- func (d Delegation) Hash() common.Hash
- func (d Delegation) MarshalJSON() ([]byte, error)
- func (d *Delegation) RemoveUnlockedUndelegations(curEpoch, lastEpochInCommittee *big.Int, lockPeriod int) *big.Int
- func (d Delegation) String() string
- func (d *Delegation) TotalInUndelegation() *big.Int
- func (d *Delegation) Undelegate(epoch *big.Int, amt *big.Int) error
- type DelegationIndex
- type DelegationIndexes
- type Delegations
- type Description
- type Directive
- type EIP155Signer
- type EditValidator
- type EpochSigningEntry
- type Signer
- type StakeMsg
- type StakeMsgFulfiller
- type StakingTransaction
- func (tx *StakingTransaction) ChainID() *big.Int
- func (tx *StakingTransaction) Copy() *StakingTransaction
- func (tx *StakingTransaction) Cost() (*big.Int, error)
- func (tx *StakingTransaction) Data() []byte
- func (tx *StakingTransaction) DecodeRLP(s *rlp.Stream) error
- func (tx *StakingTransaction) EncodeRLP(w io.Writer) error
- func (tx *StakingTransaction) From() *atomic.Value
- func (tx *StakingTransaction) GasLimit() uint64
- func (tx *StakingTransaction) GasPrice() *big.Int
- func (tx *StakingTransaction) Hash() common.Hash
- func (tx *StakingTransaction) IsEthCompatible() bool
- func (tx *StakingTransaction) Nonce() uint64
- func (tx *StakingTransaction) Protected() bool
- func (tx *StakingTransaction) RLPEncodeStakeMsg() (by []byte, err error)
- func (tx *StakingTransaction) RawSignatureValues() (*big.Int, *big.Int, *big.Int)
- func (tx *StakingTransaction) SenderAddress() (common.Address, error)
- func (tx *StakingTransaction) ShardID() uint32
- func (tx *StakingTransaction) Size() common.StorageSize
- func (tx *StakingTransaction) StakingMessage() interface{}
- func (tx *StakingTransaction) StakingType() Directive
- func (tx *StakingTransaction) To() *common.Address
- func (tx *StakingTransaction) ToShardID() uint32
- func (tx *StakingTransaction) Value() *big.Int
- func (tx *StakingTransaction) WithSignature(signer Signer, sig []byte) (*StakingTransaction, error)
- type StakingTransactions
- type Undelegate
- type Undelegation
- type Undelegations
- type Validator
- type ValidatorRPCEnhanced
- type ValidatorSnapshot
- type ValidatorSnapshotReader
- type ValidatorStats
- type ValidatorWrapper
- type VoteWithCurrentEpochEarning
Constants ¶
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 )
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
const MaxBLSPerValidator = 106
MaxBLSPerValidator ..
Variables ¶
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") )
var ( // ErrInvalidSig is a bad signature ErrInvalidSig = errors.New("invalid transaction v, r, s values") )
var ( // ErrInvalidStakingKind given when caller gives bad staking message kind ErrInvalidStakingKind = errors.New("bad staking kind") )
Functions ¶
func MarshalValidator ¶ added in v1.3.0
MarshalValidator marshals the validator object
func RLPDecodeStakeMsg ¶ added in v1.3.0
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 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
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
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
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
Undelegate - append entry to the undelegation
type DelegationIndex ¶ added in v1.3.0
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 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 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 ¶
func (s EIP155Signer) Hash(tx *StakingTransaction) common.Hash
Hash returns the hash to be signed by the sender. It does not uniquely identify the transaction.
func (EIP155Signer) Sender ¶
func (s EIP155Signer) Sender(tx *StakingTransaction) (common.Address, error)
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
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 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 ¶
func Sign(tx *StakingTransaction, s Signer, prv *ecdsa.PrivateKey) (*StakingTransaction, error)
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
func (tx *StakingTransaction) Copy() *StakingTransaction
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
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
func (tx *StakingTransaction) Size() common.StorageSize
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.
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
type Undelegation ¶ added in v1.3.0
Undelegation represents one undelegation entry
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
UnmarshalValidator unmarshal binary into Validator object
func (*Validator) SanityCheck ¶ added in v1.3.2
SanityCheck checks basic requirements 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 (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 ..