Validator
A validator component is created when the create_validator()
method is called on the consensus manager component. It is a component of the validator native blueprint.
It contains methods that allow validators to perform special actions, such as staking to themselves, registering to become a live validator, modifying validator-specific configuration (such as the fee factor), and more.
It also contains public methods callable by anyone. These methods are primarily used to add stake as a delegator, claim staking rewards, and so on.
We cover the most crucial publicly accessible methods here. We have, however, audited the validator-only methods and ensured that they behave as specified.
Method: stake()
The method signature is stake(xrd_bucket: Bucket, api: &mut Y)
.
This method is used by delegators to stake their XRD to the validator that this method is called on.
The method first ensures that validators are accepting delegated stake, as that is a configurable option (i.e., validators can choose not to allow others to stake onto them).
The method then takes the amount of XRD in the xrd_bucket
argument, inserts it into the validator's staked XRD vault, and then returns a corresponding amount of stake units in a bucket. The stake units signify that this delegator has an amount of stake on this validator.
The consensus-manager component's state is then updated with the new details of the validator (such as the updated total stake).
Method: unstake()
The method signature is unstake(stake_unit_bucket: Bucket, api: &mut Y)
.
This method is used by delegators to unstake their XRD from the validator that this method is called on.
The stake_unit_bucket
argument is the bucket of stake unit resources that are returned when the stake()
method is called. A nonfungible token is returned to the user, and the corresponding XRD amount is locked into a specific vault. This XRD amount can be claimed later on by the delegator after num_unstake_epochs
epochs have passed. The nonfungible token must be used to claim the XRD.
The consensus-manager component's state is then also updated.
Method: claim()
The method signature is claim_xrd(bucket: Bucket, api: &mut Y)
.
This method is used by delegators to claim their unstaked XRD after num_unstake_epochs
have passed. The bucket
argument contains the unstake nonfungible token that is returned when the unstake()
method is called.
The nonfungible token is burned, and there are checks to ensure that the caller is not attempting to claim nonexisting unstaked funds or unstaked funds that have not been unstaked for a sufficient amount of time.