Documentation
¶
Overview ¶
Package validators contains libraries to shuffle validators and retrieve active validator indices from a given slot or an attestation. It also provides helper functions to locate validator based on pubic key.
Index ¶
- Variables
- func InitiateValidatorExit(ctx context.Context, s state.BeaconState, idx primitives.ValidatorIndex, ...) (state.BeaconState, error)
- func InitiateValidatorExitForTotalBal(ctx context.Context, s state.BeaconState, idx primitives.ValidatorIndex, ...) (state.BeaconState, error)
- func SlashValidator(ctx context.Context, s state.BeaconState, slashedIdx primitives.ValidatorIndex, ...) (state.BeaconState, error)
- func SlashingParamsPerVersion(v int) (slashingQuotient, proposerRewardQuotient, whistleblowerRewardQuotient uint64, ...)
- type ExitInfo
Constants ¶
This section is empty.
Variables ¶
var ErrValidatorAlreadyExited = errors.New("validator already exited")
ErrValidatorAlreadyExited is an error raised when trying to process an exit of an already exited validator
Functions ¶
func InitiateValidatorExit ¶
func InitiateValidatorExit( ctx context.Context, s state.BeaconState, idx primitives.ValidatorIndex, exitInfo *ExitInfo, ) (state.BeaconState, error)
InitiateValidatorExit takes in validator index and updates validator with correct voluntary exit parameters. Note: As of Electra, the exitQueueEpoch and churn parameters are unused.
Spec pseudocode definition:
def initiate_validator_exit(state: BeaconState, index: ValidatorIndex) -> None:
"""
Initiate the exit of the validator with index ``index``.
"""
# Return if validator already initiated exit
validator = state.validators[index]
if validator.exit_epoch != FAR_FUTURE_EPOCH:
return
# Compute exit queue epoch [Modified in Electra:EIP7251]
exit_queue_epoch = compute_exit_epoch_and_update_churn(state, validator.effective_balance)
# Set validator exit epoch and withdrawable epoch
validator.exit_epoch = exit_queue_epoch
validator.withdrawable_epoch = Epoch(validator.exit_epoch + MIN_VALIDATOR_WITHDRAWABILITY_DELAY)
func InitiateValidatorExitForTotalBal ¶
func InitiateValidatorExitForTotalBal( ctx context.Context, s state.BeaconState, idx primitives.ValidatorIndex, exitInfo *ExitInfo, totalActiveBalance primitives.Gwei, ) (state.BeaconState, error)
InitiateValidatorExitForTotalBal has the same functionality as InitiateValidatorExit, the only difference being how total active balance is obtained. In InitiateValidatorExit it is calculated inside the function and in InitiateValidatorExitForTotalBal it's a function argument.
func SlashValidator ¶
func SlashValidator( ctx context.Context, s state.BeaconState, slashedIdx primitives.ValidatorIndex, exitInfo *ExitInfo, ) (state.BeaconState, error)
SlashValidator slashes the malicious validator's balance and awards the whistleblower's balance. Note: This implementation does not handle an optional whistleblower index. The whistleblower index is always the proposer index.
Spec pseudocode definition:
def slash_validator(state: BeaconState,
slashed_index: ValidatorIndex,
whistleblower_index: ValidatorIndex=None) -> None:
"""
Slash the validator with index ``slashed_index``.
"""
epoch = get_current_epoch(state)
initiate_validator_exit(state, slashed_index)
validator = state.validators[slashed_index]
validator.slashed = True
validator.withdrawable_epoch = max(validator.withdrawable_epoch, Epoch(epoch + EPOCHS_PER_SLASHINGS_VECTOR))
state.slashings[epoch % EPOCHS_PER_SLASHINGS_VECTOR] += validator.effective_balance
slashing_penalty = validator.effective_balance // MIN_SLASHING_PENALTY_QUOTIENT_EIP7251 # [Modified in EIP7251]
decrease_balance(state, slashed_index, slashing_penalty)
# Apply proposer and whistleblower rewards
proposer_index = get_beacon_proposer_index(state)
if whistleblower_index is None:
whistleblower_index = proposer_index
whistleblower_reward = Gwei(
validator.effective_balance // WHISTLEBLOWER_REWARD_QUOTIENT_ELECTRA) # [Modified in EIP7251]
proposer_reward = Gwei(whistleblower_reward * PROPOSER_WEIGHT // WEIGHT_DENOMINATOR)
increase_balance(state, proposer_index, proposer_reward)
increase_balance(state, whistleblower_index, Gwei(whistleblower_reward - proposer_reward))
func SlashingParamsPerVersion ¶
func SlashingParamsPerVersion(v int) (slashingQuotient, proposerRewardQuotient, whistleblowerRewardQuotient uint64, err error)
SlashingParamsPerVersion returns the slashing parameters for the given state version.
Types ¶
type ExitInfo ¶
type ExitInfo struct {
HighestExitEpoch primitives.Epoch
Churn uint64
TotalActiveBalance uint64
}
ExitInfo provides information about validator exits in the state.
func ExitInformation ¶
func ExitInformation(s state.BeaconState) *ExitInfo
ExitInformation returns information about validator exits.