Documentation ¶
Overview ¶
Package epoch contains epoch processing libraries according to spec, able to process new balance for validators, justify and finalize new check points, and shuffle validators to different slots and shards.
Index ¶
- func AttestingBalance(state iface.ReadOnlyBeaconState, atts []*pb.PendingAttestation) (uint64, error)
- func BaseReward(state iface.ReadOnlyBeaconState, index types.ValidatorIndex) (uint64, error)
- func ProcessEffectiveBalanceUpdates(state iface.BeaconState) (iface.BeaconState, error)
- func ProcessEth1DataReset(state iface.BeaconState) (iface.BeaconState, error)
- func ProcessFinalUpdates(state iface.BeaconState) (iface.BeaconState, error)
- func ProcessHistoricalRootsUpdate(state iface.BeaconState) (iface.BeaconState, error)
- func ProcessParticipationRecordUpdates(state iface.BeaconState) (iface.BeaconState, error)
- func ProcessRandaoMixesReset(state iface.BeaconState) (iface.BeaconState, error)
- func ProcessRegistryUpdates(state iface.BeaconState) (iface.BeaconState, error)
- func ProcessSlashings(state iface.BeaconState) (iface.BeaconState, error)
- func ProcessSlashingsReset(state iface.BeaconState) (iface.BeaconState, error)
- func UnslashedAttestingIndices(state iface.ReadOnlyBeaconState, atts []*pb.PendingAttestation) ([]types.ValidatorIndex, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AttestingBalance ¶
func AttestingBalance(state iface.ReadOnlyBeaconState, atts []*pb.PendingAttestation) (uint64, error)
AttestingBalance returns the total balance from all the attesting indices.
WARNING: This method allocates a new copy of the attesting validator indices set and is considered to be very memory expensive. Avoid using this unless you really need to get attesting balance from attestations.
Spec pseudocode definition:
def get_attesting_balance(state: BeaconState, attestations: Sequence[PendingAttestation]) -> Gwei: """ Return the combined effective balance of the set of unslashed validators participating in ``attestations``. Note: ``get_total_balance`` returns ``EFFECTIVE_BALANCE_INCREMENT`` Gwei minimum to avoid divisions by zero. """ return get_total_balance(state, get_unslashed_attesting_indices(state, attestations))
func BaseReward ¶
func BaseReward(state iface.ReadOnlyBeaconState, index types.ValidatorIndex) (uint64, error)
BaseReward takes state and validator index and calculate individual validator's base reward quotient.
Note: Adjusted quotient is calculated of base reward because it's too inefficient to repeat the same calculation for every validator versus just doing it once.
Spec pseudocode definition:
def get_base_reward(state: BeaconState, index: ValidatorIndex) -> Gwei: total_balance = get_total_active_balance(state) effective_balance = state.validators[index].effective_balance return Gwei(effective_balance * BASE_REWARD_FACTOR // integer_squareroot(total_balance) // BASE_REWARDS_PER_EPOCH)
func ProcessEffectiveBalanceUpdates ¶ added in v1.3.7
func ProcessEffectiveBalanceUpdates(state iface.BeaconState) (iface.BeaconState, error)
ProcessEffectiveBalanceUpdates processes effective balance updates during epoch processing.
Spec pseudocode definition:
def process_effective_balance_updates(state: BeaconState) -> None: # Update effective balances with hysteresis for index, validator in enumerate(state.validators): balance = state.balances[index] HYSTERESIS_INCREMENT = uint64(EFFECTIVE_BALANCE_INCREMENT // HYSTERESIS_QUOTIENT) DOWNWARD_THRESHOLD = HYSTERESIS_INCREMENT * HYSTERESIS_DOWNWARD_MULTIPLIER UPWARD_THRESHOLD = HYSTERESIS_INCREMENT * HYSTERESIS_UPWARD_MULTIPLIER if ( balance + DOWNWARD_THRESHOLD < validator.effective_balance or validator.effective_balance + UPWARD_THRESHOLD < balance ): validator.effective_balance = min(balance - balance % EFFECTIVE_BALANCE_INCREMENT, MAX_EFFECTIVE_BALANCE)
func ProcessEth1DataReset ¶ added in v1.3.7
func ProcessEth1DataReset(state iface.BeaconState) (iface.BeaconState, error)
ProcessEth1DataReset processes updates to ETH1 data votes during epoch processing.
Spec pseudocode definition:
def process_eth1_data_reset(state: BeaconState) -> None: next_epoch = Epoch(get_current_epoch(state) + 1) # Reset eth1 data votes if next_epoch % EPOCHS_PER_ETH1_VOTING_PERIOD == 0: state.eth1_data_votes = []
func ProcessFinalUpdates ¶
func ProcessFinalUpdates(state iface.BeaconState) (iface.BeaconState, error)
ProcessFinalUpdates processes the final updates during epoch processing.
func ProcessHistoricalRootsUpdate ¶ added in v1.3.7
func ProcessHistoricalRootsUpdate(state iface.BeaconState) (iface.BeaconState, error)
ProcessHistoricalRootsUpdate processes the updates to historical root accumulator during epoch processing.
Spec pseudocode definition:
def process_historical_roots_update(state: BeaconState) -> None: # Set historical root accumulator next_epoch = Epoch(get_current_epoch(state) + 1) if next_epoch % (SLOTS_PER_HISTORICAL_ROOT // SLOTS_PER_EPOCH) == 0: historical_batch = HistoricalBatch(block_roots=state.block_roots, state_roots=state.state_roots) state.historical_roots.append(hash_tree_root(historical_batch))
func ProcessParticipationRecordUpdates ¶ added in v1.3.7
func ProcessParticipationRecordUpdates(state iface.BeaconState) (iface.BeaconState, error)
ProcessParticipationRecordUpdates rotates current/previous epoch attestations during epoch processing.
Spec pseudocode definition:
def process_participation_record_updates(state: BeaconState) -> None: # Rotate current/previous epoch attestations state.previous_epoch_attestations = state.current_epoch_attestations state.current_epoch_attestations = []
func ProcessRandaoMixesReset ¶ added in v1.3.7
func ProcessRandaoMixesReset(state iface.BeaconState) (iface.BeaconState, error)
ProcessRandaoMixesReset processes the final updates to RANDAO mix during epoch processing.
Spec pseudocode definition:
def process_randao_mixes_reset(state: BeaconState) -> None: current_epoch = get_current_epoch(state) next_epoch = Epoch(current_epoch + 1) # Set randao mix state.randao_mixes[next_epoch % EPOCHS_PER_HISTORICAL_VECTOR] = get_randao_mix(state, current_epoch)
func ProcessRegistryUpdates ¶
func ProcessRegistryUpdates(state iface.BeaconState) (iface.BeaconState, error)
ProcessRegistryUpdates rotates validators in and out of active pool. the amount to rotate is determined churn limit.
Spec pseudocode definition:
def process_registry_updates(state: BeaconState) -> None: # Process activation eligibility and ejections for index, validator in enumerate(state.validators): if is_eligible_for_activation_queue(validator): validator.activation_eligibility_epoch = get_current_epoch(state) + 1 if is_active_validator(validator, get_current_epoch(state)) and validator.effective_balance <= EJECTION_BALANCE: initiate_validator_exit(state, ValidatorIndex(index)) # Queue validators eligible for activation and not yet dequeued for activation activation_queue = sorted([ index for index, validator in enumerate(state.validators) if is_eligible_for_activation(state, validator) # Order by the sequence of activation_eligibility_epoch setting and then index ], key=lambda index: (state.validators[index].activation_eligibility_epoch, index)) # Dequeued validators for activation up to churn limit for index in activation_queue[:get_validator_churn_limit(state)]: validator = state.validators[index] validator.activation_epoch = compute_activation_exit_epoch(get_current_epoch(state))
func ProcessSlashings ¶
func ProcessSlashings(state iface.BeaconState) (iface.BeaconState, error)
ProcessSlashings processes the slashed validators during epoch processing,
def process_slashings(state: BeaconState) -> None: epoch = get_current_epoch(state) total_balance = get_total_active_balance(state) adjusted_total_slashing_balance = min(sum(state.slashings) * PROPORTIONAL_SLASHING_MULTIPLIER, total_balance) for index, validator in enumerate(state.validators): if validator.slashed and epoch + EPOCHS_PER_SLASHINGS_VECTOR // 2 == validator.withdrawable_epoch: increment = EFFECTIVE_BALANCE_INCREMENT # Factored out from penalty numerator to avoid uint64 overflow penalty_numerator = validator.effective_balance // increment * adjusted_total_slashing_balance penalty = penalty_numerator // total_balance * increment decrease_balance(state, ValidatorIndex(index), penalty)
func ProcessSlashingsReset ¶ added in v1.3.7
func ProcessSlashingsReset(state iface.BeaconState) (iface.BeaconState, error)
ProcessSlashingsReset processes the total slashing balances updates during epoch processing.
Spec pseudocode definition:
def process_slashings_reset(state: BeaconState) -> None: next_epoch = Epoch(get_current_epoch(state) + 1) # Reset slashings state.slashings[next_epoch % EPOCHS_PER_SLASHINGS_VECTOR] = Gwei(0)
func UnslashedAttestingIndices ¶ added in v1.0.0
func UnslashedAttestingIndices(state iface.ReadOnlyBeaconState, atts []*pb.PendingAttestation) ([]types.ValidatorIndex, error)
UnslashedAttestingIndices returns all the attesting indices from a list of attestations, it sorts the indices and filters out the slashed ones.
Spec pseudocode definition:
def get_unslashed_attesting_indices(state: BeaconState, attestations: Sequence[PendingAttestation]) -> Set[ValidatorIndex]: output = set() # type: Set[ValidatorIndex] for a in attestations: output = output.union(get_attesting_indices(state, a.data, a.aggregation_bits)) return set(filter(lambda index: not state.validators[index].slashed, output))
Types ¶
This section is empty.
Directories ¶
Path | Synopsis |
---|---|
Package precompute provides gathering of nicely-structured data important to feed into epoch processing, such as attesting records and balances, for faster computation.
|
Package precompute provides gathering of nicely-structured data important to feed into epoch processing, such as attesting records and balances, for faster computation. |