diff --git a/electra-gap.md b/electra-gap.md index 3dacfcf6b..739f7ed8b 100644 --- a/electra-gap.md +++ b/electra-gap.md @@ -36,7 +36,7 @@ Here we will detail the current implementation gaps with the specs and the way t ### Phase 1: Beacon Chain Implementation -We are at `49/57` (86%) of the [beacon chain changes](docs/specs/electra/beacon-chain.md), and most of the remaining functions are already in progress. We have still `108/11370` spec test failures, but we are working on them. The skipped tests were there previous to the electra upgrade, so we will work on them if needed after we finish the first phase. Our aim as mentioned before is to reach `0` failures before going to the next phase. +We are at `52/57` (91%) of the [beacon chain changes](docs/specs/electra/beacon-chain.md), and most of the remaining functions are already in progress. We have still `73/11370` spec test failures, but we are working on them. The skipped tests were there previous to the electra upgrade, so we will work on them if needed after we finish the first phase. Our aim as mentioned before is to reach `0` failures before going to the next phase. The current status of the implementation in the [electra-support](https://github.com/lambdaclass/lambda_ethereum_consensus/tree/electra-support) branch is as follows: @@ -91,15 +91,15 @@ The current status of the implementation in the [electra-support](https://github - [x] Modified `compute_proposer_index` ([Spec](docs/specs/electra/beacon-chain.md#modified-compute_proposer_index), [PR](https://github.com/lambdaclass/lambda_ethereum_consensus/pull/1417)) - [x] New `get_max_effective_balance` ([Spec](docs/specs/electra/beacon-chain.md#new-get_max_effective_balance), [PR](https://github.com/lambdaclass/lambda_ethereum_consensus/pull/1419)) -#### Epoch Processing (5/8 - 63%) +#### Epoch Processing (8/8 - 100%) -- [ ] Modified `process_epoch` ([Spec](docs/specs/electra/beacon-chain.md#modified-process_epoch)) +- [x] Modified `process_epoch` ([Spec](docs/specs/electra/beacon-chain.md#modified-process_epoch), [PR](https://github.com/lambdaclass/lambda_ethereum_consensus/pull/1428)) - [x] Modified `process_registry_updates` ([Spec](docs/specs/electra/beacon-chain.md#modified-process_registry_updates), [PR](https://github.com/lambdaclass/lambda_ethereum_consensus/pull/1420)) - [x] Modified `process_slashings` ([Spec](docs/specs/electra/beacon-chain.md#modified-process_slashings), [PR](https://github.com/lambdaclass/lambda_ethereum_consensus/pull/1417)) - [x] New `apply_pending_deposit` ([Spec](docs/specs/electra/beacon-chain.md#new-apply_pending_deposit), [PR](https://github.com/lambdaclass/lambda_ethereum_consensus/pull/1424)) - [x] New `process_pending_deposits` ([Spec](docs/specs/electra/beacon-chain.md#new-process_pending_deposits), [PR](https://github.com/lambdaclass/lambda_ethereum_consensus/pull/1424)) -- [ ] New `process_pending_consolidations` ([Spec](docs/specs/electra/beacon-chain.md#new-process_pending_consolidations)) -- [ ] Modified `process_effective_balance_updates` ([Spec](docs/specs/electra/beacon-chain.md#modified-process_effective_balance_updates)) +- [x] New `process_pending_consolidations` ([Spec](docs/specs/electra/beacon-chain.md#new-process_pending_consolidations), [PR](https://github.com/lambdaclass/lambda_ethereum_consensus/pull/1428)) +- [x] Modified `process_effective_balance_updates` ([Spec](docs/specs/electra/beacon-chain.md#modified-process_effective_balance_updates), [PR](https://github.com/lambdaclass/lambda_ethereum_consensus/pull/1428)) - [x] Modified `get_validator_from_deposit` ([Spec](docs/specs/electra/beacon-chains.md#modified-get_validator_from_deposit), [PR](https://github.com/lambdaclass/lambda_ethereum_consensus/pull/1424)) #### Block Processing (10/12 - 83%) diff --git a/lib/lambda_ethereum_consensus/state_transition/epoch_processing.ex b/lib/lambda_ethereum_consensus/state_transition/epoch_processing.ex index a3024c8a3..1139e254f 100644 --- a/lib/lambda_ethereum_consensus/state_transition/epoch_processing.ex +++ b/lib/lambda_ethereum_consensus/state_transition/epoch_processing.ex @@ -44,7 +44,6 @@ defmodule LambdaEthereumConsensus.StateTransition.EpochProcessing do hysteresis_quotient = ChainSpec.get("HYSTERESIS_QUOTIENT") hysteresis_downward_multiplier = ChainSpec.get("HYSTERESIS_DOWNWARD_MULTIPLIER") hysteresis_upward_multiplier = ChainSpec.get("HYSTERESIS_UPWARD_MULTIPLIER") - max_effective_balance = ChainSpec.get("MAX_EFFECTIVE_BALANCE") hysteresis_increment = div(effective_balance_increment, hysteresis_quotient) downward_threshold = hysteresis_increment * hysteresis_downward_multiplier @@ -55,7 +54,10 @@ defmodule LambdaEthereumConsensus.StateTransition.EpochProcessing do |> Aja.Vector.zip_with(balances, fn %Validator{} = validator, balance -> if balance + downward_threshold < validator.effective_balance or validator.effective_balance + upward_threshold < balance do - min(balance - rem(balance, effective_balance_increment), max_effective_balance) + min( + balance - rem(balance, effective_balance_increment), + Validator.get_max_effective_balance(validator) + ) |> then(&%{validator | effective_balance: &1}) else validator @@ -569,8 +571,45 @@ defmodule LambdaEthereumConsensus.StateTransition.EpochProcessing do @spec process_pending_consolidations(BeaconState.t()) :: {:ok, BeaconState.t()} def process_pending_consolidations(%BeaconState{} = state) do - # TODO: Not implemented yet - {:ok, state} + next_epoch = Accessors.get_current_epoch(state) + 1 + + {next_pending_consolidation, state} = + state.pending_consolidations + |> Enum.reduce_while({0, state}, fn pending_consolidation, + {next_pending_consolidation, state} -> + source_index = pending_consolidation.source_index + target_index = pending_consolidation.target_index + source_validator = state.validators |> Aja.Vector.at(source_index) + + cond do + source_validator.slashed -> + {:cont, {next_pending_consolidation + 1, state}} + + source_validator.withdrawable_epoch > next_epoch -> + {:halt, {next_pending_consolidation, state}} + + true -> + source_effective_balance = + min( + Aja.Vector.at(state.balances, source_index), + source_validator.effective_balance + ) + + updated_state = + state + |> BeaconState.decrease_balance(source_index, source_effective_balance) + |> BeaconState.increase_balance(target_index, source_effective_balance) + + {:cont, {next_pending_consolidation + 1, updated_state}} + end + end) + + {:ok, + %BeaconState{ + state + | pending_consolidations: + Enum.drop(state.pending_consolidations, next_pending_consolidation) + }} end defp apply_pending_deposit(state, deposit) do