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, noEarlyUnlock bool) *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 ¶
MarshalValidator marshals the validator object
func RLPDecodeStakeMsg ¶
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 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 ¶
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
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
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
type CurrentEpochPerformance ¶
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 (*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) 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 ¶
Undelegate - append entry to the undelegation
type DelegationIndex ¶
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 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 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 ¶
func (v EditValidator) Copy() StakeMsg
Copy returns a deep copy of the EditValidator as a StakeMsg interface
type EpochSigningEntry ¶
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 ¶
func (tx *StakingTransaction) Copy() *StakingTransaction
Copy returns a copy of the transaction.
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) RLPEncodeStakeMsg ¶
func (tx *StakingTransaction) RLPEncodeStakeMsg() (by []byte, err error)
RLPEncodeStakeMsg ..
func (*StakingTransaction) RawSignatureValues ¶
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) ShardID ¶
func (tx *StakingTransaction) ShardID() uint32
ShardID returns which shard id this transaction was signed for, implicitly shard 0.
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) ToShardID ¶
func (tx *StakingTransaction) ToShardID() uint32
ToShardID returns which shard id this transaction was signed for, implicitly shard 0.
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.
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
type Undelegation ¶
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 ¶
func CreateValidatorFromNewMsg( val *CreateValidator, blockNum, epoch *big.Int, ) (*Validator, error)
CreateValidatorFromNewMsg creates validator from NewValidator message
func UnmarshalValidator ¶
UnmarshalValidator unmarshal binary into Validator object
func (*Validator) SanityCheck ¶
SanityCheck checks basic requirements 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
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 (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 ..