epoch

package
v5.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 8, 2024 License: GPL-3.0 Imports: 15 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func ProcessEffectiveBalanceUpdates

func ProcessEffectiveBalanceUpdates(st state.BeaconState) (state.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

func ProcessEth1DataReset(state state.BeaconState) (state.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 state.BeaconState) (state.BeaconState, error)

ProcessFinalUpdates processes the final updates during epoch processing.

func ProcessHistoricalDataUpdate

func ProcessHistoricalDataUpdate(state state.BeaconState) (state.BeaconState, error)

ProcessHistoricalDataUpdate processes the updates to historical data during epoch processing. From Capella onward, per spec,state's historical summaries are updated instead of historical roots.

func ProcessParticipationRecordUpdates

func ProcessParticipationRecordUpdates(state state.BeaconState) (state.BeaconState, error)

ProcessParticipationRecordUpdates rotates current/previous epoch attestations during epoch processing.

nolint:dupword 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

func ProcessRandaoMixesReset(state state.BeaconState) (state.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(ctx context.Context, st state.BeaconState) (state.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(st state.BeaconState, slashingMultiplier uint64) (state.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

func ProcessSlashingsReset(state state.BeaconState) (state.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)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL