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 ActivatedValidatorIndices(epoch primitives.Epoch, validators []*ethpb.Validator) []primitives.ValidatorIndex
- func EjectedValidatorIndices(epoch primitives.Epoch, validators []*ethpb.Validator) ([]primitives.ValidatorIndex, error)
- func ExitedValidatorIndices(epoch primitives.Epoch, validators []*ethpb.Validator) ([]primitives.ValidatorIndex, error)
- func InitiateValidatorExit(ctx context.Context, s state.BeaconState, idx primitives.ValidatorIndex, ...) (state.BeaconState, primitives.Epoch, error)
- func MaxExitEpochAndChurn(s state.BeaconState) (maxExitEpoch primitives.Epoch, churn uint64)
- func SlashValidator(ctx context.Context, s state.BeaconState, slashedIdx primitives.ValidatorIndex) (state.BeaconState, error)
- func SlashedValidatorIndices(epoch primitives.Epoch, validators []*ethpb.Validator) []primitives.ValidatorIndex
- func SlashingParamsPerVersion(v int) (slashingQuotient, proposerRewardQuotient, whistleblowerRewardQuotient uint64, ...)
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 ActivatedValidatorIndices ¶
func ActivatedValidatorIndices(epoch primitives.Epoch, validators []*ethpb.Validator) []primitives.ValidatorIndex
ActivatedValidatorIndices determines the indices activated during the given epoch.
func EjectedValidatorIndices ¶
func EjectedValidatorIndices(epoch primitives.Epoch, validators []*ethpb.Validator) ([]primitives.ValidatorIndex, error)
EjectedValidatorIndices returns the indices of validators who were ejected during the specified epoch.
A validator is considered ejected during an epoch if: - Their ExitEpoch equals the epoch. - Their EffectiveBalance is less than or equal to the EjectionBalance threshold.
This function simplifies the ejection determination by directly checking the validator's ExitEpoch and EffectiveBalance, avoiding the complexities and potential inaccuracies of calculating withdrawable epochs.
func ExitedValidatorIndices ¶
func ExitedValidatorIndices(epoch primitives.Epoch, validators []*ethpb.Validator) ([]primitives.ValidatorIndex, error)
ExitedValidatorIndices returns the indices of validators who exited during the specified epoch.
A validator is considered to have exited during an epoch if their ExitEpoch equals the epoch and excludes validators that have been ejected. This function simplifies the exit determination by directly checking the validator's ExitEpoch, avoiding the complexities and potential inaccuracies of calculating withdrawable epochs.
func InitiateValidatorExit ¶
func InitiateValidatorExit(ctx context.Context, s state.BeaconState, idx primitives.ValidatorIndex, exitQueueEpoch primitives.Epoch, churn uint64) (state.BeaconState, primitives.Epoch, 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 MaxExitEpochAndChurn ¶
func MaxExitEpochAndChurn(s state.BeaconState) (maxExitEpoch primitives.Epoch, churn uint64)
MaxExitEpochAndChurn returns the maximum non-FAR_FUTURE_EPOCH exit epoch and the number of them
func SlashValidator ¶
func SlashValidator( ctx context.Context, s state.BeaconState, slashedIdx primitives.ValidatorIndex) (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 SlashedValidatorIndices ¶
func SlashedValidatorIndices(epoch primitives.Epoch, validators []*ethpb.Validator) []primitives.ValidatorIndex
SlashedValidatorIndices determines the indices slashed during the given epoch.
func SlashingParamsPerVersion ¶ added in v5.1.0
func SlashingParamsPerVersion(v int) (slashingQuotient, proposerRewardQuotient, whistleblowerRewardQuotient uint64, err error)
SlashingParamsPerVersion returns the slashing parameters for the given state version.
Types ¶
This section is empty.