Documentation ¶
Index ¶
- Variables
- func CanDelegate(current, pending []DelegatorAndID, new *txs.AddDelegatorTx, ...) (bool, error)
- type Chain
- type CurrentStakers
- type CurrentValidator
- type DelegatorAndID
- type Diff
- type PendingStakers
- type Stakers
- type State
- type SubnetValidatorAndID
- type UTXOAdder
- type UTXODeleter
- type UTXOGetter
- type ValidatorAndID
- type ValidatorModifications
- type ValidatorReward
- type ValidatorWeightDiff
Constants ¶
This section is empty.
Variables ¶
View Source
var (
ErrDelegatorSubset = errors.New("delegator's time range must be a subset of the validator's time range")
)
View Source
var (
ErrNotEnoughValidators = errors.New("not enough validators")
)
Functions ¶
func CanDelegate ¶
func CanDelegate( current, pending []DelegatorAndID, new *txs.AddDelegatorTx, currentStake, maximumStake uint64, ) (bool, error)
CanDelegate returns if the [new] delegator can be added to a validator who has [current] and [pending] delegators. [currentStake] is the current amount of stake on the validator, include the [current] delegators. [maximumStake] is the maximum amount of stake that can be on the validator at any given time. It is assumed that the validator without adding [new] does not violate [maximumStake].
Types ¶
type Chain ¶
type Chain interface { Stakers UTXOAdder UTXOGetter UTXODeleter GetTimestamp() time.Time SetTimestamp(tm time.Time) GetCurrentSupply() uint64 SetCurrentSupply(cs uint64) GetRewardUTXOs(txID ids.ID) ([]*avax.UTXO, error) AddRewardUTXO(txID ids.ID, utxo *avax.UTXO) GetSubnets() ([]*txs.Tx, error) AddSubnet(createSubnetTx *txs.Tx) GetChains(subnetID ids.ID) ([]*txs.Tx, error) AddChain(createChainTx *txs.Tx) GetTx(txID ids.ID) (*txs.Tx, status.Status, error) AddTx(tx *txs.Tx, status status.Status) }
Chain collects all methods to manage the state of the chain for block execution.
type CurrentStakers ¶
type CurrentStakers interface { // The NextStaker value returns the next staker that is going to be removed // using a RewardValidatorTx. Therefore, only AddValidatorTxs and // AddDelegatorTxs will be returned. AddSubnetValidatorTxs are removed using // AdvanceTimestampTxs. GetNextStaker() (addStakerTx *txs.Tx, potentialReward uint64, err error) GetStaker(txID ids.ID) (tx *txs.Tx, potentialReward uint64, err error) GetValidator(nodeID ids.NodeID) (CurrentValidator, error) UpdateStakers( addValidators []*ValidatorReward, addDelegators []*ValidatorReward, addSubnetValidators []*txs.Tx, numTxsToRemove int, ) (CurrentStakers, error) DeleteNextStaker() (CurrentStakers, error) // Stakers returns the current stakers on the network sorted in order of the // order of their future removal from the validator set. Stakers() []*txs.Tx Apply(State) // Return the current validator set of [subnetID]. ValidatorSet(subnetID ids.ID) (validators.Set, error) }
type CurrentValidator ¶
type CurrentValidator interface { ValidatorModifications // return txs.AddValidatorTx content along with // the ID of its txs.Tx AddValidatorTx() (*txs.AddValidatorTx, ids.ID) // Weight of delegations to this validator. Doesn't include the stake // provided by this validator. DelegatorWeight() uint64 PotentialReward() uint64 }
type DelegatorAndID ¶
type DelegatorAndID struct { Tx *txs.AddDelegatorTx TxID ids.ID }
type Diff ¶
func NewDiff ¶
func NewDiff( parentState Chain, current CurrentStakers, pending PendingStakers, ) Diff
type PendingStakers ¶
type PendingStakers interface { GetValidatorTx(nodeID ids.NodeID) (addStakerTx *txs.AddValidatorTx, txID ids.ID, err error) GetValidator(nodeID ids.NodeID) ValidatorModifications AddStaker(addStakerTx *txs.Tx) PendingStakers DeleteStakers(numToRemove int) PendingStakers // Stakers returns the list of pending validators in order of their removal // from the pending staker set Stakers() []*txs.Tx Apply(State) }
PendingStakers manages the set of stakers (both validators and delegators) that are slated to start staking in the future.
type Stakers ¶
type Stakers interface { SetCurrentStakers(cs CurrentStakers) CurrentStakers() CurrentStakers SetPendingStakers(ps PendingStakers) PendingStakers() PendingStakers // GetNextStakerChangeTime returns the next time that a staker set change // should occur. GetNextStakerChangeTime() (time.Time, error) }
func NewStakers ¶
func NewStakers(current CurrentStakers, pending PendingStakers) Stakers
type State ¶
type State interface { Chain uptime.State avax.UTXOReader // TODO: remove ShouldInit and DoneInit and perform them in New ShouldInit() (bool, error) DoneInit() error GetLastAccepted() ids.ID SetLastAccepted(ids.ID) AddCurrentStaker(tx *txs.Tx, potentialReward uint64) DeleteCurrentStaker(tx *txs.Tx) AddPendingStaker(tx *txs.Tx) DeletePendingStaker(tx *txs.Tx) GetValidatorWeightDiffs(height uint64, subnetID ids.ID) (map[ids.NodeID]*ValidatorWeightDiff, error) // Return the maximum amount of stake on a node (including delegations) at // any given time between [startTime] and [endTime] given that: // * The amount of stake on the node right now is [currentStake] // * The delegations currently on this node are [current] // * [current] is sorted in order of increasing delegation end time. // * The stake delegated in [current] are already included in [currentStake] // * [startTime] is in the future, and [endTime] > [startTime] // * The delegations that will be on this node in the future are [pending] // * The start time of all delegations in [pending] are in the future // * [pending] is sorted in order of increasing delegation start time MaxStakeAmount( subnetID ids.ID, nodeID ids.NodeID, startTime time.Time, endTime time.Time, ) (uint64, error) // SyncGenesis initializes the state with the genesis state. SyncGenesis(genesisBlkID ids.ID, genesisState *genesis.State) error // Load pulls data previously stored on disk that is expected to be in // memory. Load() error Write(height uint64) error Close() error }
func New ¶
func New( baseDB database.Database, metrics prometheus.Registerer, cfg *config.Config, ctx *snow.Context, localStake prometheus.Gauge, totalStake prometheus.Gauge, rewards reward.Calculator, ) (State, error)
type SubnetValidatorAndID ¶
type SubnetValidatorAndID struct { Tx *txs.AddSubnetValidatorTx TxID ids.ID }
type UTXODeleter ¶
type ValidatorAndID ¶
type ValidatorAndID struct { Tx *txs.AddValidatorTx TxID ids.ID }
type ValidatorModifications ¶
type ValidatorModifications interface { Delegators() []DelegatorAndID SubnetValidators() map[ids.ID]SubnetValidatorAndID }
type ValidatorReward ¶
type ValidatorWeightDiff ¶
Click to show internal directories.
Click to hide internal directories.