From f4c215c5e6d181a0cc75a2d52cbcbf8c61c86e84 Mon Sep 17 00:00:00 2001 From: Etan Kissling Date: Wed, 10 May 2023 04:31:23 +0200 Subject: [PATCH] cleanup `state_transition_epoch` and bump to v1.3.0 (#4922) * cleanup `state_transition_epoch` and bump to v1.3.0 More v1.3.0 consensus-specs bumps, focused on `state_transition_epoch`. Also fixed `current_epoch` spurious style check warning, and cleanup. * Update beacon_chain/spec/state_transition_epoch.nim --- beacon_chain/spec/state_transition_epoch.nim | 152 +++++++++---------- 1 file changed, 75 insertions(+), 77 deletions(-) diff --git a/beacon_chain/spec/state_transition_epoch.nim b/beacon_chain/spec/state_transition_epoch.nim index 5a737d119..a67a634c7 100644 --- a/beacon_chain/spec/state_transition_epoch.nim +++ b/beacon_chain/spec/state_transition_epoch.nim @@ -6,7 +6,7 @@ # at your option. This file may not be copied, modified, or distributed except according to those terms. # State transition - epoch processing, as described in -# https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.5/specs/phase0/beacon-chain.md#epoch-processing +# https://github.com/ethereum/consensus-specs/blob/v1.3.0/specs/phase0/beacon-chain.md#epoch-processing # https://github.com/ethereum/consensus-specs/blob/v1.3.0/specs/altair/beacon-chain.md#epoch-processing # https://github.com/ethereum/consensus-specs/blob/v1.3.0/specs/bellatrix/beacon-chain.md#epoch-processing # https://github.com/ethereum/consensus-specs/blob/v1.3.0/specs/capella/beacon-chain.md#epoch-processing @@ -41,7 +41,7 @@ export extras, phase0, altair logScope: topics = "consens" # Accessors that implement the max condition in `get_total_balance`: -# https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.5/specs/phase0/beacon-chain.md#get_total_balance +# https://github.com/ethereum/consensus-specs/blob/v1.3.0/specs/phase0/beacon-chain.md#get_total_balance template current_epoch*(v: TotalBalances): Gwei = max(EFFECTIVE_BALANCE_INCREMENT, v.current_epoch_raw) template previous_epoch*(v: TotalBalances): Gwei = @@ -156,7 +156,7 @@ func process_attestations*( if v.flags.contains RewardFlags.isPreviousEpochHeadAttester: info.balances.previous_epoch_head_attesters_raw += validator_balance -# https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.3/specs/phase0/beacon-chain.md#helpers +# https://github.com/ethereum/consensus-specs/blob/v1.3.0/specs/phase0/beacon-chain.md#helpers # get_eligible_validator_indices func is_eligible_validator*(validator: RewardStatus): bool = validator.flags.contains(RewardFlags.isActiveInPreviousEpoch) or @@ -175,8 +175,7 @@ func is_eligible_validator*(validator: ParticipationInfo): bool = from ./datatypes/deneb import BeaconState -# https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.3/specs/altair/beacon-chain.md#get_unslashed_participating_indices -# https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.5/specs/phase0/beacon-chain.md#get_total_balance +# https://github.com/ethereum/consensus-specs/blob/v1.3.0/specs/altair/beacon-chain.md#get_unslashed_participating_indices func get_unslashed_participating_balances*( state: altair.BeaconState | bellatrix.BeaconState | capella.BeaconState | deneb.BeaconState): UnslashedParticipatingBalances = @@ -244,7 +243,7 @@ func is_unslashed_participating_index( has_flag(epoch_participation[].item(validator_index), flag_index) and not state.validators[validator_index].slashed -# https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.5/specs/phase0/beacon-chain.md#justification-and-finalization +# https://github.com/ethereum/consensus-specs/blob/v1.3.0/specs/phase0/beacon-chain.md#justification-and-finalization type FinalityState = object slot: Slot current_epoch_ancestor_root: Eth2Digest @@ -312,7 +311,7 @@ proc weigh_justification_and_finalization( ## state.justification_bits[1:] = state.justification_bits[:-1] ## state.justification_bits[0] = 0b0 - # https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.5/specs/phase0/beacon-chain.md#misc + # https://github.com/ethereum/consensus-specs/blob/v1.3.0/specs/phase0/beacon-chain.md#misc const JUSTIFICATION_BITS_LENGTH = 4 state.justification_bits = JustificationBits( @@ -389,7 +388,7 @@ proc weigh_justification_and_finalization( current_epoch = current_epoch, checkpoint = shortLog(state.finalized_checkpoint) -# https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.3/specs/phase0/beacon-chain.md#justification-and-finalization +# https://github.com/ethereum/consensus-specs/blob/v1.3.0/specs/phase0/beacon-chain.md#justification-and-finalization proc process_justification_and_finalization*( state: var phase0.BeaconState, balances: TotalBalances, flags: UpdateFlags = {}) = @@ -425,10 +424,10 @@ proc compute_unrealized_finality*( justified: finalityState.current_justified_checkpoint, finalized: finalityState.finalized_checkpoint) -# https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.3/specs/altair/beacon-chain.md#justification-and-finalization +# https://github.com/ethereum/consensus-specs/blob/v1.3.0/specs/altair/beacon-chain.md#justification-and-finalization proc process_justification_and_finalization*( - state: var (altair.BeaconState | bellatrix.BeaconState | capella.BeaconState | - deneb.BeaconState), + state: var (altair.BeaconState | bellatrix.BeaconState | + capella.BeaconState | deneb.BeaconState), balances: UnslashedParticipatingBalances, flags: UpdateFlags = {}) = # Initial FFG checkpoint values have a `0x00` stub for `root`. @@ -461,7 +460,7 @@ proc compute_unrealized_finality*( justified: finalityState.current_justified_checkpoint, finalized: finalityState.finalized_checkpoint) -# https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.3/specs/phase0/beacon-chain.md#helpers +# https://github.com/ethereum/consensus-specs/blob/v1.3.0/specs/phase0/beacon-chain.md#helpers func get_base_reward_sqrt*(state: phase0.BeaconState, index: ValidatorIndex, total_balance_sqrt: auto): Gwei = # Spec function recalculates total_balance every time, which creates an @@ -509,7 +508,7 @@ func get_attestation_component_delta(is_unslashed_attester: bool, else: RewardDelta(penalties: base_reward) -# https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.3/specs/phase0/beacon-chain.md#components-of-attestation-deltas +# https://github.com/ethereum/consensus-specs/blob/v1.3.0/specs/phase0/beacon-chain.md#components-of-attestation-deltas func get_source_delta*(validator: RewardStatus, base_reward: uint64, balances: TotalBalances, @@ -587,8 +586,9 @@ func get_inactivity_penalty_delta*(validator: RewardStatus, delta -# https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.3/specs/phase0/beacon-chain.md#get_attestation_deltas -func get_attestation_deltas(state: phase0.BeaconState, info: var phase0.EpochInfo) = +# https://github.com/ethereum/consensus-specs/blob/v1.3.0/specs/phase0/beacon-chain.md#get_attestation_deltas +func get_attestation_deltas( + state: phase0.BeaconState, info: var phase0.EpochInfo) = ## Update rewards with attestation reward/penalty deltas for each validator. let @@ -631,7 +631,7 @@ func get_attestation_deltas(state: phase0.BeaconState, info: var phase0.EpochInf info.validators[proposer_index].delta.add( proposer_delta.get()[1]) -# https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.3/specs/altair/beacon-chain.md#get_base_reward +# https://github.com/ethereum/consensus-specs/blob/v1.3.0/specs/altair/beacon-chain.md#get_base_reward func get_base_reward_increment*( state: altair.BeaconState | bellatrix.BeaconState | capella.BeaconState | deneb.BeaconState, @@ -642,7 +642,7 @@ func get_base_reward_increment*( state.validators[index].effective_balance div EFFECTIVE_BALANCE_INCREMENT increments * base_reward_per_increment -# https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.3/specs/altair/beacon-chain.md#get_flag_index_deltas +# https://github.com/ethereum/consensus-specs/blob/v1.3.0/specs/altair/beacon-chain.md#get_flag_index_deltas func get_flag_index_reward*( state: altair.BeaconState | bellatrix.BeaconState | capella.BeaconState | deneb.BeaconState, @@ -661,8 +661,9 @@ func get_unslashed_participating_increment*( info: altair.EpochInfo | bellatrix.BeaconState, flag_index: int): Gwei = info.balances.previous_epoch[flag_index] div EFFECTIVE_BALANCE_INCREMENT -# https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.3/specs/altair/beacon-chain.md#get_flag_index_deltas -func get_active_increments*(info: altair.EpochInfo | bellatrix.BeaconState): Gwei = +# https://github.com/ethereum/consensus-specs/blob/v1.3.0/specs/altair/beacon-chain.md#get_flag_index_deltas +func get_active_increments*( + info: altair.EpochInfo | bellatrix.BeaconState): Gwei = info.balances.current_epoch div EFFECTIVE_BALANCE_INCREMENT # https://github.com/ethereum/consensus-specs/blob/v1.3.0/specs/altair/beacon-chain.md#get_flag_index_deltas @@ -710,7 +711,7 @@ iterator get_flag_index_deltas*( else: (vidx, RewardDelta(rewards: 0.Gwei, penalties: 0.Gwei)) -# https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.3/specs/altair/beacon-chain.md#modified-get_inactivity_penalty_deltas +# https://github.com/ethereum/consensus-specs/blob/v1.3.0/specs/altair/beacon-chain.md#modified-get_inactivity_penalty_deltas iterator get_inactivity_penalty_deltas*( cfg: RuntimeConfig, state: altair.BeaconState, info: altair.EpochInfo): (ValidatorIndex, Gwei) = @@ -756,7 +757,7 @@ iterator get_inactivity_penalty_deltas*( state.inactivity_scores[vidx] yield (vidx, Gwei(penalty_numerator div penalty_denominator)) -# https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.3/specs/phase0/beacon-chain.md#rewards-and-penalties-1 +# https://github.com/ethereum/consensus-specs/blob/v1.3.0/specs/phase0/beacon-chain.md#rewards-and-penalties-1 func process_rewards_and_penalties*( state: var phase0.BeaconState, info: var phase0.EpochInfo) = # No rewards are applied at the end of `GENESIS_EPOCH` because rewards are @@ -779,13 +780,12 @@ func process_rewards_and_penalties*( decrease_balance(balance, v.delta.penalties) state.balances.asSeq()[idx] = balance -# https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.3/specs/altair/beacon-chain.md#rewards-and-penalties +# https://github.com/ethereum/consensus-specs/blob/v1.3.0/specs/altair/beacon-chain.md#rewards-and-penalties func process_rewards_and_penalties*( cfg: RuntimeConfig, state: var (altair.BeaconState | bellatrix.BeaconState | capella.BeaconState | deneb.BeaconState), - info: var altair.EpochInfo) - = + info: var altair.EpochInfo) = if get_current_epoch(state) == GENESIS_EPOCH: return @@ -816,7 +816,7 @@ func process_rewards_and_penalties*( decrease_balance(balance, info.validators[vidx].delta.penalties) state.balances.asSeq()[vidx] = balance -# https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.3/specs/phase0/beacon-chain.md#registry-updates +# https://github.com/ethereum/consensus-specs/blob/v1.3.0/specs/phase0/beacon-chain.md#registry-updates func process_registry_updates*( cfg: RuntimeConfig, state: var ForkyBeaconState, cache: var StateCache): Result[void, cstring] = @@ -869,8 +869,8 @@ func process_registry_updates*( ok() -# https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.3/specs/phase0/beacon-chain.md#slashings -# https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.3/specs/altair/beacon-chain.md#slashings +# https://github.com/ethereum/consensus-specs/blob/v1.3.0/specs/phase0/beacon-chain.md#slashings +# https://github.com/ethereum/consensus-specs/blob/v1.3.0/specs/altair/beacon-chain.md#slashings # https://github.com/ethereum/consensus-specs/blob/v1.3.0/specs/bellatrix/beacon-chain.md#slashings func get_adjusted_total_slashing_balance*( state: ForkyBeaconState, total_balance: Gwei): Gwei = @@ -888,26 +888,26 @@ func get_adjusted_total_slashing_balance*( {.fatal: "process_slashings: incorrect BeaconState type".} min(sum(state.slashings.data) * multiplier, total_balance) -# https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.5/specs/phase0/beacon-chain.md#slashings -# https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.3/specs/altair/beacon-chain.md#slashings +# https://github.com/ethereum/consensus-specs/blob/v1.3.0/specs/phase0/beacon-chain.md#slashings +# https://github.com/ethereum/consensus-specs/blob/v1.3.0/specs/altair/beacon-chain.md#slashings # https://github.com/ethereum/consensus-specs/blob/v1.3.0/specs/bellatrix/beacon-chain.md#slashings func slashing_penalty_applies*(validator: Validator, epoch: Epoch): bool = validator.slashed and epoch + EPOCHS_PER_SLASHINGS_VECTOR div 2 == validator.withdrawable_epoch -# https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.3/specs/phase0/beacon-chain.md#slashings +# https://github.com/ethereum/consensus-specs/blob/v1.3.0/specs/phase0/beacon-chain.md#slashings # https://github.com/ethereum/consensus-specs/blob/v1.3.0/specs/altair/beacon-chain.md#slashings # https://github.com/ethereum/consensus-specs/blob/v1.3.0/specs/bellatrix/beacon-chain.md#slashings func get_slashing_penalty*(validator: Validator, adjusted_total_slashing_balance, total_balance: Gwei): Gwei = - const increment = EFFECTIVE_BALANCE_INCREMENT # Factored out from penalty - # numerator to avoid uint64 overflow + # Factored out from penalty numerator to avoid uint64 overflow + const increment = EFFECTIVE_BALANCE_INCREMENT let penalty_numerator = validator.effective_balance div increment * adjusted_total_slashing_balance penalty_numerator div total_balance * increment -# https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.5/specs/phase0/beacon-chain.md#slashings +# https://github.com/ethereum/consensus-specs/blob/v1.3.0/specs/phase0/beacon-chain.md#slashings # https://github.com/ethereum/consensus-specs/blob/v1.3.0/specs/altair/beacon-chain.md#slashings # https://github.com/ethereum/consensus-specs/blob/v1.3.0/specs/bellatrix/beacon-chain.md#slashings func process_slashings*(state: var ForkyBeaconState, total_balance: Gwei) = @@ -923,7 +923,7 @@ func process_slashings*(state: var ForkyBeaconState, total_balance: Gwei) = validator[], adjusted_total_slashing_balance, total_balance) decrease_balance(state, vidx, penalty) -# https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.3/specs/phase0/beacon-chain.md#eth1-data-votes-updates +# https://github.com/ethereum/consensus-specs/blob/v1.3.0/specs/phase0/beacon-chain.md#eth1-data-votes-updates func process_eth1_data_reset*(state: var ForkyBeaconState) = let next_epoch = get_current_epoch(state) + 1 @@ -931,7 +931,7 @@ func process_eth1_data_reset*(state: var ForkyBeaconState) = if next_epoch mod EPOCHS_PER_ETH1_VOTING_PERIOD == 0: state.eth1_data_votes = default(type state.eth1_data_votes) -# https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.3/specs/phase0/beacon-chain.md#effective-balances-updates +# https://github.com/ethereum/consensus-specs/blob/v1.3.0/specs/phase0/beacon-chain.md#effective-balances-updates func process_effective_balance_updates*(state: var ForkyBeaconState) = # Update effective balances with hysteresis for vidx in state.validators.vindices: @@ -953,14 +953,14 @@ func process_effective_balance_updates*(state: var ForkyBeaconState) = if new_effective_balance != effective_balance: state.validators.mitem(vidx).effective_balance = new_effective_balance -# https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.5/specs/phase0/beacon-chain.md#slashings-balances-updates +# https://github.com/ethereum/consensus-specs/blob/v1.3.0/specs/phase0/beacon-chain.md#slashings-balances-updates func process_slashings_reset*(state: var ForkyBeaconState) = let next_epoch = get_current_epoch(state) + 1 # Reset slashings state.slashings[int(next_epoch mod EPOCHS_PER_SLASHINGS_VECTOR)] = 0.Gwei -# https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.5/specs/phase0/beacon-chain.md#randao-mixes-updates +# https://github.com/ethereum/consensus-specs/blob/v1.3.0/specs/phase0/beacon-chain.md#randao-mixes-updates func process_randao_mixes_reset*(state: var ForkyBeaconState) = let current_epoch = get_current_epoch(state) @@ -973,12 +973,12 @@ func process_randao_mixes_reset*(state: var ForkyBeaconState) = func compute_historical_root*(state: var ForkyBeaconState): Eth2Digest = # Equivalent to hash_tree_root(foo: HistoricalBatch), but without using # significant additional stack or heap. - # https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.5/specs/phase0/beacon-chain.md#historicalbatch + # https://github.com/ethereum/consensus-specs/blob/v1.3.0/specs/phase0/beacon-chain.md#historicalbatch # In response to https://github.com/status-im/nimbus-eth2/issues/921 hash_tree_root([ hash_tree_root(state.block_roots), hash_tree_root(state.state_roots)]) -# https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.5/specs/phase0/beacon-chain.md#historical-roots-updates +# https://github.com/ethereum/consensus-specs/blob/v1.3.0/specs/phase0/beacon-chain.md#historical-roots-updates func process_historical_roots_update*(state: var ForkyBeaconState) = ## Set historical root accumulator let next_epoch = get_current_epoch(state) + 1 @@ -986,12 +986,12 @@ func process_historical_roots_update*(state: var ForkyBeaconState) = if next_epoch mod (SLOTS_PER_HISTORICAL_ROOT div SLOTS_PER_EPOCH) == 0: # Equivalent to hash_tree_root(foo: HistoricalBatch), but without using # significant additional stack or heap. - # https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.5/specs/phase0/beacon-chain.md#historicalbatch + # https://github.com/ethereum/consensus-specs/blob/v1.3.0/specs/phase0/beacon-chain.md#historicalbatch # In response to https://github.com/status-im/nimbus-eth2/issues/921 if not state.historical_roots.add state.compute_historical_root(): raiseAssert "no more room for historical roots, so long and thanks for the fish!" -# https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.5/specs/phase0/beacon-chain.md#participation-records-rotation +# https://github.com/ethereum/consensus-specs/blob/v1.3.0/specs/phase0/beacon-chain.md#participation-records-rotation func process_participation_record_updates*(state: var phase0.BeaconState) = # Rotate current/previous epoch attestations - using swap avoids copying all # elements using a slow genericSeqAssign @@ -1074,13 +1074,12 @@ func process_historical_summaries_update*( ok() -# https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.3/specs/phase0/beacon-chain.md#epoch-processing +# https://github.com/ethereum/consensus-specs/blob/v1.3.0/specs/phase0/beacon-chain.md#epoch-processing proc process_epoch*( cfg: RuntimeConfig, state: var phase0.BeaconState, flags: UpdateFlags, cache: var StateCache, info: var phase0.EpochInfo): Result[void, cstring] = - let currentEpoch = get_current_epoch(state) - trace "process_epoch", - current_epoch = currentEpoch + let epoch = get_current_epoch(state) + trace "process_epoch", epoch info.init(state) info.process_attestations(state, cache) @@ -1088,14 +1087,14 @@ proc process_epoch*( process_justification_and_finalization(state, info.balances, flags) # state.slot hasn't been incremented yet. - if strictVerification in flags and currentEpoch >= 2: - doAssert state.current_justified_checkpoint.epoch + 2 >= currentEpoch + if strictVerification in flags and epoch >= 2: + doAssert state.current_justified_checkpoint.epoch + 2 >= epoch - if strictVerification in flags and currentEpoch >= 3: + if strictVerification in flags and epoch >= 3: # Rule 2/3/4 finalization results in the most pessimal case. The other # three finalization rules finalize more quickly as long as the any of # the finalization rules triggered. - doAssert state.finalized_checkpoint.epoch + 3 >= currentEpoch + doAssert state.finalized_checkpoint.epoch + 3 >= epoch process_rewards_and_penalties(state, info) ? process_registry_updates(cfg, state, cache) @@ -1139,59 +1138,58 @@ proc process_epoch*( state: var (altair.BeaconState | bellatrix.BeaconState), flags: UpdateFlags, cache: var StateCache, info: var altair.EpochInfo): Result[void, cstring] = - let currentEpoch = get_current_epoch(state) - trace "process_epoch", - current_epoch = currentEpoch + let epoch = get_current_epoch(state) + trace "process_epoch", epoch info.init(state) - # https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.3/specs/phase0/beacon-chain.md#justification-and-finalization + # https://github.com/ethereum/consensus-specs/blob/v1.3.0/specs/altair/beacon-chain.md#justification-and-finalization + # [Modified in Altair] process_justification_and_finalization(state, info.balances, flags) # state.slot hasn't been incremented yet. - if strictVerification in flags and currentEpoch >= 2: - doAssert state.current_justified_checkpoint.epoch + 2 >= currentEpoch + if strictVerification in flags and epoch >= 2: + doAssert state.current_justified_checkpoint.epoch + 2 >= epoch - if strictVerification in flags and currentEpoch >= 3: + if strictVerification in flags and epoch >= 3: # Rule 2/3/4 finalization results in the most pessimal case. The other # three finalization rules finalize more quickly as long as the any of # the finalization rules triggered. - doAssert state.finalized_checkpoint.epoch + 3 >= currentEpoch + doAssert state.finalized_checkpoint.epoch + 3 >= epoch - process_inactivity_updates(cfg, state, info) + process_inactivity_updates(cfg, state, info) # [New in Altair] - # https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.3/specs/phase0/beacon-chain.md#process_rewards_and_penalties - process_rewards_and_penalties(cfg, state, info) + # https://github.com/ethereum/consensus-specs/blob/v1.3.0/specs/altair/beacon-chain.md#rewards-and-penalties + process_rewards_and_penalties(cfg, state, info) # [Modified in Altair] - # https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.3/specs/phase0/beacon-chain.md#registry-updates + # https://github.com/ethereum/consensus-specs/blob/v1.3.0/specs/phase0/beacon-chain.md#registry-updates ? process_registry_updates(cfg, state, cache) - # https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.3/specs/phase0/beacon-chain.md#slashings - process_slashings(state, info.balances.current_epoch) + # https://github.com/ethereum/consensus-specs/blob/v1.3.0/specs/altair/beacon-chain.md#slashings + process_slashings(state, info.balances.current_epoch) # [Modified in Altair] process_eth1_data_reset(state) process_effective_balance_updates(state) process_slashings_reset(state) process_randao_mixes_reset(state) process_historical_roots_update(state) - process_participation_flag_updates(state) - process_sync_committee_updates(state) + process_participation_flag_updates(state) # [New in Altair] + process_sync_committee_updates(state) # [New in Altair] ok() -# https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.2/specs/capella/beacon-chain.md#epoch-processing +# https://github.com/ethereum/consensus-specs/blob/v1.3.0/specs/capella/beacon-chain.md#epoch-processing proc process_epoch*( cfg: RuntimeConfig, state: var (capella.BeaconState | deneb.BeaconState), flags: UpdateFlags, cache: var StateCache, info: var altair.EpochInfo): Result[void, cstring] = - let currentEpoch = get_current_epoch(state) - trace "process_epoch", - current_epoch = currentEpoch + let epoch = get_current_epoch(state) + trace "process_epoch", epoch info.init(state) - # https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.5/specs/phase0/beacon-chain.md#justification-and-finalization + # https://github.com/ethereum/consensus-specs/blob/v1.3.0/specs/altair/beacon-chain.md#justification-and-finalization process_justification_and_finalization(state, info.balances, flags) # state.slot hasn't been incremented yet. @@ -1199,28 +1197,28 @@ proc process_epoch*( # Rule 2/3/4 finalization results in the most pessimal case. The other # three finalization rules finalize more quickly as long as the any of # the finalization rules triggered. - if (currentEpoch >= 2 and state.current_justified_checkpoint.epoch + 2 < currentEpoch) or - (currentEpoch >= 3 and state.finalized_checkpoint.epoch + 3 < currentEpoch): + if (epoch >= 2 and state.current_justified_checkpoint.epoch + 2 < epoch) or + (epoch >= 3 and state.finalized_checkpoint.epoch + 3 < epoch): fatal "The network did not finalize", - currentEpoch, finalizedEpoch = state.finalized_checkpoint.epoch + epoch, finalizedEpoch = state.finalized_checkpoint.epoch quit 1 process_inactivity_updates(cfg, state, info) - # https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.5/specs/phase0/beacon-chain.md#process_rewards_and_penalties + # https://github.com/ethereum/consensus-specs/blob/v1.3.0/specs/altair/beacon-chain.md#rewards-and-penalties process_rewards_and_penalties(cfg, state, info) - # https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.5/specs/phase0/beacon-chain.md#registry-updates + # https://github.com/ethereum/consensus-specs/blob/v1.3.0/specs/phase0/beacon-chain.md#registry-updates ? process_registry_updates(cfg, state, cache) - # https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.5/specs/phase0/beacon-chain.md#slashings + # https://github.com/ethereum/consensus-specs/blob/v1.3.0/specs/altair/beacon-chain.md#slashings process_slashings(state, info.balances.current_epoch) process_eth1_data_reset(state) process_effective_balance_updates(state) process_slashings_reset(state) process_randao_mixes_reset(state) - ? process_historical_summaries_update(state) + ? process_historical_summaries_update(state) # [Modified in Capella] process_participation_flag_updates(state) process_sync_committee_updates(state)