Skip to content

feat: electra process_operations changes #1426

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 97 commits into from
Apr 24, 2025
Merged
Show file tree
Hide file tree
Changes from 85 commits
Commits
Show all changes
97 commits
Select commit Hold shift + click to select a range
ed74379
feat EpochProcessing.process_slashings electra changes
LeanSerra Apr 3, 2025
71b3674
feat compute_proposer_index changes
LeanSerra Apr 4, 2025
9aa4202
feat compute_sync_committees Electra changes
LeanSerra Apr 4, 2025
f09b71b
fix fork_choice.ex tests were flaky because env var cleanup was not done
LeanSerra Apr 4, 2025
df45ee4
feat eligible_for_activation_queue Electra changes
LeanSerra Apr 7, 2025
8fb4d63
feat new compounding_withdrawal_credential? Electra function
LeanSerra Apr 7, 2025
6e34108
feat new has_compounding_withdrawal_credential Electra function
LeanSerra Apr 7, 2025
620e700
feat new has_execution_withdrawal_credential Electra function
LeanSerra Apr 7, 2025
d904593
feat fully_withdrawable_validator? Electra changes
LeanSerra Apr 7, 2025
5445583
feat new get_max_effective_balance Electra function
LeanSerra Apr 7, 2025
5cbc5af
feat partially_withdrawable_validator? Electra changes
LeanSerra Apr 7, 2025
753badb
fix typo in struct field in has_compounding_withdrawal_credential
LeanSerra Apr 7, 2025
29bf08a
feat new get_committee_indices Electra function
LeanSerra Apr 7, 2025
17bf479
feat get_attesting_indices Electra changes
LeanSerra Apr 7, 2025
42b0bfb
lint remove unnecessary parentheses in if
LeanSerra Apr 7, 2025
6df1b36
feat slash_validator Electra changes
LeanSerra Apr 7, 2025
9e13ad5
feat new get_balance_churn_limit Electra function
LeanSerra Apr 7, 2025
abc2585
feat new get_activation_exit_churn_limit Electra function
LeanSerra Apr 7, 2025
5b7e5dc
feat compute_exit_epoch_and_churn Electra function
LeanSerra Apr 7, 2025
4eddb4b
feat initiate_validator_exit Electra changes
LeanSerra Apr 7, 2025
44a00ec
feat process_registry_updates Electra changes
LeanSerra Apr 8, 2025
9bc3a0b
refactor remove unused eject_validator(_,_,_, false) variant
LeanSerra Apr 8, 2025
ed8be8a
fix compute_exit_epoch_and_update_churn wrong exit_balance calculation
LeanSerra Apr 8, 2025
c084913
Merge branch 'electra-support' into electra_predicates
LeanSerra Apr 8, 2025
6ec0216
fix additional_epochs calculation in compute_exit_epoch_and_update_churn
LeanSerra Apr 8, 2025
7da3d5a
fix wrong values for constants in minimal config
LeanSerra Apr 8, 2025
70d40aa
Merge branch 'electra_predicates' into electra_validator_exit
LeanSerra Apr 8, 2025
e4e8607
feat process_epoch changes + deposits/consolidation scaffolding
LeanSerra Apr 8, 2025
0e53f57
feat new is_valid_deposit_signature Electra function
LeanSerra Apr 9, 2025
12ed2d3
feat get_validator_from_deposit Electra changes
LeanSerra Apr 9, 2025
a73c061
feat apply_deposit Electra changes
LeanSerra Apr 9, 2025
6ad6e4d
feat new apply_pending_deposit Electra function
LeanSerra Apr 9, 2025
3eef3e7
feat new process_pending_deposits Electra function
LeanSerra Apr 9, 2025
88c7308
refactor move registry_update for each validator to own function inli…
LeanSerra Apr 9, 2025
14a0539
Merge branch 'electra_validator_exit' into electra_deposits
LeanSerra Apr 9, 2025
ebc73e0
refactor avoid negation in if when calculating pending_deposits in ap…
LeanSerra Apr 9, 2025
f8c443a
Merge branch 'electra-support' into electra_validator_exit
LeanSerra Apr 10, 2025
8f72d6b
Merge branch 'electra_validator_exit' into electra_deposits
LeanSerra Apr 10, 2025
b4a9d15
Merge branch 'electra-support' into electra_validator_exit
LeanSerra Apr 10, 2025
280669a
Merge branch 'electra_validator_exit' into electra_deposits
LeanSerra Apr 10, 2025
c2db045
refactor move logic to handle an individual pending_deposit to its ow…
LeanSerra Apr 10, 2025
7bc38b9
feat process_operations Electra changes
LeanSerra Apr 10, 2025
6d74e53
feat new process_deposit_request Electra function
LeanSerra Apr 10, 2025
40b0a5c
fix conditional logic for verify_deposits was incorrect
LeanSerra Apr 10, 2025
82afc64
fix get_committee_indices calculation was incorrect
LeanSerra Apr 10, 2025
6521f68
feat process_attestation Electra changes
LeanSerra Apr 10, 2025
e437245
feat new get_pending_balance_to_withdraw Electra function
LeanSerra Apr 10, 2025
8417e96
feat process_voluntary_exit Electra changes
LeanSerra Apr 10, 2025
39dd889
feat new process_withdrawal_request Electra function
LeanSerra Apr 11, 2025
2db24de
feat add constant g2_point_at_infinity
LeanSerra Apr 11, 2025
1b8024e
feat new queue_excess_active_balance Electra function
LeanSerra Apr 11, 2025
253b824
feat new switch_to_compounding_validator Electra function
LeanSerra Apr 11, 2025
6ace4d9
feat new get_consolidation_churn_limit Electra function
LeanSerra Apr 11, 2025
2166fb4
refactor move logic to find a validator by pubkey to own function
LeanSerra Apr 11, 2025
2c1001f
refactor invalid_withdrawal_credentials parameter is now the address …
LeanSerra Apr 11, 2025
0f8b360
feat new process_consolidation_request Electra function
LeanSerra Apr 11, 2025
5b9721c
Merge branch 'electra-support' into electra_deposits
LeanSerra Apr 11, 2025
38c5a4e
docs update electra-gap.md with changes from #1424
LeanSerra Apr 11, 2025
a7997c5
Merge branch 'electra_deposits' into electra_process_operations
LeanSerra Apr 11, 2025
20515be
refactor process_consolidation_request split validations to different…
LeanSerra Apr 11, 2025
0726736
refactor process_withdrawal_request split validations to different fu…
LeanSerra Apr 14, 2025
65b1f57
feat new compute_consolidation_epoch_and_update_churn Electra function
LeanSerra Apr 14, 2025
9f720d5
fix do_process_conslidation_request was using compute_exit when it sh…
LeanSerra Apr 14, 2025
27ef594
fix typo in struct field in do_process_consolidation_request
LeanSerra Apr 14, 2025
4dcfb90
fix typo in struct field in do_process_consolidation_request
LeanSerra Apr 14, 2025
93c1002
docs update electra-gap.md with changes from #1426
LeanSerra Apr 14, 2025
ff7ab9f
Merge branch 'electra-support' into electra_deposits
LeanSerra Apr 15, 2025
7cab380
Merge branch 'electra_deposits' into electra_process_operations
LeanSerra Apr 15, 2025
ae7be10
fix full_exit valid_withdrawal was returning a nested tuple instead o…
LeanSerra Apr 15, 2025
b426cc7
fix do_process_consolidation_request was returnig {:process, BeaconSt…
LeanSerra Apr 16, 2025
7d711d5
fix full_exit handle_valid_withdrawal_request was not updating the ex…
LeanSerra Apr 16, 2025
c4008f2
fix apply_deposits, apply_initial_deposit amount should be 0, returne…
LeanSerra Apr 16, 2025
ffbd715
fix apply_deposits using Enum.member when it should be using Enum.any
LeanSerra Apr 16, 2025
a9a9d2f
fix process_deposit_request was overwritting the updated_state
LeanSerra Apr 16, 2025
3346f10
fix add new Containers to operations.ex runner
LeanSerra Apr 16, 2025
86d539f
fix invalid_consolidation_request_credentials? logic was inverted + s…
LeanSerra Apr 16, 2025
b85fcbd
Merge branch 'electra-support' into electra_deposits
LeanSerra Apr 16, 2025
5f2929f
Merge branch 'electra_deposits' into electra_process_operations
LeanSerra Apr 16, 2025
c049a33
Merge branch 'electra-support' into electra_deposits
LeanSerra Apr 16, 2025
2b6c4e1
Merge branch 'electra_deposits' into electra_process_operations
LeanSerra Apr 16, 2025
2eb2ce3
Merge branch 'electra-support' into electra_process_operations
LeanSerra Apr 21, 2025
5bdef50
fix added diff lines
LeanSerra Apr 21, 2025
e163179
fix added diff lines
LeanSerra Apr 21, 2025
75bf0b4
fix fast_process_attestation wrong attesting indices
LeanSerra Apr 21, 2025
dd42e10
fix BitList.set should be BitList.set?, fix incorrect pattern matchin…
LeanSerra Apr 16, 2025
95f69b1
refactor use pattern matching for Operations.check_data_index_zero
LeanSerra Apr 23, 2025
30952b6
refactor use cond clause for withdrawal_request_type in process_withd…
LeanSerra Apr 23, 2025
f41a70a
refactor check_committee_indices improve readability
LeanSerra Apr 23, 2025
35cc192
refactor process_withdrawal_request with clause
LeanSerra Apr 23, 2025
3a7afaf
refactor find_validator uses Aja functions and returns only nil when …
LeanSerra Apr 24, 2025
7c86102
refactor move get_committee_indices call to check_committee_indices
LeanSerra Apr 24, 2025
9b43f1a
refactor rename partial_exit_with_partial_withdrawal_queue_full? to p…
LeanSerra Apr 24, 2025
8ebb655
refactor avoid recalculating pending_balance_to_withdraw in handle_va…
LeanSerra Apr 24, 2025
e36cd51
refactor use Aja.Vector.at instead of Enum.at
LeanSerra Apr 24, 2025
8e3456e
refactor rename validate_validators & validate_consolidation_request
LeanSerra Apr 24, 2025
01c86b1
refactor verify_consolidation_validators does not need to return the …
LeanSerra Apr 24, 2025
ef1ad43
refactor check_committee_indices reduce function length
LeanSerra Apr 24, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions electra-gap.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,16 @@ This document outlines the gaps in the current implementation of the Electra. It
- [x] Modified `get_next_sync_committee_indices` ([Spec](docs/specs/electra/beacon-chain.md#modified-get_next_sync_committee_indices), [PR](https://github.com/lambdaclass/lambda_ethereum_consensus/pull/1417))
- [x] New `get_balance_churn_limit` ([Spec](docs/specs/electra/beacon-chain.md#new-get_balance_churn_limit), [PR](https://github.com/lambdaclass/lambda_ethereum_consensus/pull/1420))
- [x] New `get_activation_exit_churn_limit` ([Spec](docs/specs/electra/beacon-chain.md#new-get_activation_exit_churn_limit), [PR](https://github.com/lambdaclass/lambda_ethereum_consensus/pull/1420))
- [ ] New `get_consolidation_churn_limit` ([Spec](docs/specs/electra/beacon-chain.md#new-get_consolidation_churn_limit))
- [ ] New `get_pending_balance_to_withdraw` ([Spec](docs/specs/electra/beacon-chain.md#new-get_pending_balance_to_withdraw))
- [x] New `get_consolidation_churn_limit` ([Spec](docs/specs/electra/beacon-chain.md#new-get_consolidation_churn_limit), [PR](https://github.com/lambdaclass/lambda_ethereum_consensus/pull/1426))
- [x] New `get_pending_balance_to_withdraw` ([Spec](docs/specs/electra/beacon-chain.md#new-get_pending_balance_to_withdraw), [PR](https://github.com/lambdaclass/lambda_ethereum_consensus/pull/1426))

## Beacon State Mutators

- [x] Modified `initiate_validator_exit` ([Spec](docs/specs/electra/beacon-chain.md#modified-initiate_validator_exit), [PR](https://github.com/lambdaclass/lambda_ethereum_consensus/pull/1420))
- [ ] New `switch_to_compounding_validator` ([Spec](docs/specs/electra/beacon-chain.md#new-switch_to_compounding_validator))
- [ ] New `queue_excess_active_balance` ([Spec](docs/specs/electra/beacon-chain.md#new-queue_excess_active_balance))
- [x] New `switch_to_compounding_validator` ([Spec](docs/specs/electra/beacon-chain.md#new-switch_to_compounding_validator), [PR](https://github.com/lambdaclass/lambda_ethereum_consensus/pull/1426))
- [x] New `queue_excess_active_balance` ([Spec](docs/specs/electra/beacon-chain.md#new-queue_excess_active_balance), [PR](https://github.com/lambdaclass/lambda_ethereum_consensus/pull/1426))
- [x] New `compute_exit_epoch_and_update_churn` ([Spec](docs/specs/electra/beacon-chain.md#new-compute_exit_epoch_and_update_churn), [PR](https://github.com/lambdaclass/lambda_ethereum_consensus/pull/1420))
- [ ] New `compute_consolidation_epoch_and_update_churn` ([Spec](docs/specs/electra/beacon-chain.md#new-compute_consolidation_epoch_and_update_churn))
- [x] New `compute_consolidation_epoch_and_update_churn` ([Spec](docs/specs/electra/beacon-chain.md#new-compute_consolidation_epoch_and_update_churn), [PR](https://github.com/lambdaclass/lambda_ethereum_consensus/pull/1426))
- [x] Modified `slash_validator` ([Spec](docs/specs/electra/beacon-chain.md#modified-slash_validator), [PR](https://github.com/lambdaclass/lambda_ethereum_consensus/pull/1420))

## Miscellaneous
Expand All @@ -73,12 +73,12 @@ This document outlines the gaps in the current implementation of the Electra. It
- [ ] Modified `process_withdrawals` ([Spec](docs/specs/electra/beacon-chain.md#modified-process_withdrawals))
- [ ] Modified `process_execution_payload` ([Spec](docs/specs/electra/beacon-chain.md#modified-process_execution_payload))
- [x] Modified `process_operations` ([Spec](docs/specs/electra/beacon-chain.md#modified-process_operations), [PR](https://github.com/lambdaclass/lambda_ethereum_consensus/pull/1424))
- [ ] Modified `process_attestation` ([Spec](docs/specs/electra/beacon-chain.md#modified-process_attestation))
- [x] Modified `process_attestation` ([Spec](docs/specs/electra/beacon-chain.md#modified-process_attestation), [PR](https://github.com/lambdaclass/lambda_ethereum_consensus/pull/1426))
- [x] Modified `process_deposit` ([Spec](docs/specs/electra/beacon-chain.md#modified-process_deposit), [PR](https://github.com/lambdaclass/lambda_ethereum_consensus/pull/1424))
- [ ] Modified `process_voluntary_exit` ([Spec](docs/specs/electra/beacon-chain.md#modified-process_voluntary_exit))
- [ ] New `process_withdrawal_request` ([Spec](docs/specs/electra/beacon-chain.md#new-process_withdrawal_request))
- [x] Modified `process_voluntary_exit` ([Spec](docs/specs/electra/beacon-chain.md#modified-process_voluntary_exit), [PR](https://github.com/lambdaclass/lambda_ethereum_consensus/pull/1426))
- [x] New `process_withdrawal_request` ([Spec](docs/specs/electra/beacon-chain.md#new-process_withdrawal_request), [PR](https://github.com/lambdaclass/lambda_ethereum_consensus/pull/1426))
- [x] New `process_deposit_request` ([Spec](docs/specs/electra/beacon-chain.md#new-process_deposit_request), [PR](https://github.com/lambdaclass/lambda_ethereum_consensus/pull/1424))
- [ ] New `process_consolidation_request` ([Spec](docs/specs/electra/beacon-chain.md#new-process_consolidation_request))
- [x] New `process_consolidation_request` ([Spec](docs/specs/electra/beacon-chain.md#new-process_consolidation_request), [PR](https://github.com/lambdaclass/lambda_ethereum_consensus/pull/1426))
- [x] New `is_valid_deposit_signature` ([Spec](docs/specs/electra/beacon-chain.md#new-is_valid_deposit_signature), [PR](https://github.com/lambdaclass/lambda_ethereum_consensus/pull/1424))
- [x] Modified `add_validator_to_registry` ([Spec](docs/specs/electra/beacon-chain.md#modified-add_validator_to_registry), [PR](https://github.com/lambdaclass/lambda_ethereum_consensus/pull/1424))
- [x] Modified `apply_deposit` ([Spec](docs/specs/electra/beacon-chain.md#modified-apply_deposit), [PR](https://github.com/lambdaclass/lambda_ethereum_consensus/pull/1424))
Expand Down
3 changes: 3 additions & 0 deletions lib/constants.ex
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,7 @@ defmodule Constants do

@spec consolidation_request_type() :: Types.bytes1()
def consolidation_request_type(), do: <<2>>

@spec g2_point_at_infinity() :: Types.bls_signature()
def g2_point_at_infinity(), do: <<0xC0, 0::8*95>>
end
21 changes: 20 additions & 1 deletion lib/lambda_ethereum_consensus/state_transition/accessors.ex
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,11 @@ defmodule LambdaEthereumConsensus.StateTransition.Accessors do

@spec get_committee_indices(Types.bitvector()) :: Enumerable.t(Types.commitee_index())
def get_committee_indices(committee_bits) do
bitlist = committee_bits |> :binary.bin_to_list() |> Enum.reverse()
bitlist =
for <<bit::1 <- committee_bits>> do
bit
end
|> Enum.reverse()

for {bit, index} <- Enum.with_index(bitlist), bit == 1, do: index
end
Expand Down Expand Up @@ -682,4 +686,19 @@ defmodule LambdaEthereumConsensus.StateTransition.Accessors do
get_balance_churn_limit(state)
)
end

@spec get_pending_balance_to_withdraw(BeaconState.t(), Types.validator_index()) :: Types.gwei()
def get_pending_balance_to_withdraw(state, validator_index) do
for(
withdrawal <- state.pending_partial_withdrawals,
withdrawal.validator_index == validator_index,
do: withdrawal.amount
)
|> Enum.sum()
end

@spec get_consolidation_churn_limit(BeaconState.t()) :: Types.gwei()
def get_consolidation_churn_limit(state) do
get_balance_churn_limit(state) - get_activation_exit_churn_limit(state)
end
end
91 changes: 91 additions & 0 deletions lib/lambda_ethereum_consensus/state_transition/mutators.ex
Original file line number Diff line number Diff line change
Expand Up @@ -218,4 +218,95 @@ defmodule LambdaEthereumConsensus.StateTransition.Mutators do
earliest_exit_epoch: earliest_exit_epoch
}
end

@spec compute_consolidation_epoch_and_update_churn(Types.BeaconState.t(), Types.gwei()) ::
Types.BeaconState.t()
def compute_consolidation_epoch_and_update_churn(state, consolidation_balance) do
current_epoch = Accessors.get_current_epoch(state)

earliest_consolidation_epoch =
max(state.earliest_consolidation_epoch, Misc.compute_activation_exit_epoch(current_epoch))

per_epoch_consolidation_churn = Accessors.get_consolidation_churn_limit(state)

consolidation_balance_to_consume =
if state.earliest_consolidation_epoch < earliest_consolidation_epoch do
per_epoch_consolidation_churn
else
state.consolidation_balance_to_consume
end

{earliest_consolidation_epoch, consolidation_balance_to_consume} =
if consolidation_balance > consolidation_balance_to_consume do
balance_to_process = consolidation_balance - consolidation_balance_to_consume
additional_epochs = div(balance_to_process - 1, per_epoch_consolidation_churn) + 1

{
earliest_consolidation_epoch + additional_epochs,
consolidation_balance_to_consume + additional_epochs * per_epoch_consolidation_churn
}
else
{earliest_consolidation_epoch, consolidation_balance_to_consume}
end

%BeaconState{
state
| consolidation_balance_to_consume:
consolidation_balance_to_consume - consolidation_balance,
earliest_consolidation_epoch: earliest_consolidation_epoch
}
end

@spec switch_to_compounding_validator(BeaconState.t(), Types.validator_index()) ::
BeaconState.t()
def switch_to_compounding_validator(state, index) do
validator = Aja.Enum.at(state.validators, index)
<<_first_byte::binary-size(1), rest::binary>> = validator.withdrawal_credentials

withdrawal_credentials =
Constants.compounding_withdrawal_prefix() <> rest

updated_validator = %Validator{
validator
| withdrawal_credentials: withdrawal_credentials
}

state = %BeaconState{
state
| validators: Aja.Vector.replace_at(state.validators, index, updated_validator)
}

queue_excess_active_balance(state, index)
end

@spec queue_excess_active_balance(BeaconState.t(), Types.validator_index()) ::
BeaconState.t()
def queue_excess_active_balance(state, index) do
min_activation_balance = ChainSpec.get("MIN_ACTIVATION_BALANCE")
balance = Aja.Vector.at(state.balances, index)

if balance > min_activation_balance do
excess_balance = balance - min_activation_balance
validator = Aja.Vector.at(state.validators, index)

updated_balances = Aja.Vector.replace_at(state.balances, index, min_activation_balance)
# Use bls.G2_POINT_AT_INFINITY as a signature field placeholder
# and GENESIS_SLOT to distinguish from a pending deposit request
pending_deposit = %PendingDeposit{
pubkey: validator.pubkey,
withdrawal_credentials: validator.withdrawal_credentials,
amount: excess_balance,
signature: Constants.g2_point_at_infinity(),
slot: Constants.genesis_slot()
}

%BeaconState{
state
| balances: updated_balances,
pending_deposits: state.pending_deposits ++ [pending_deposit]
}
else
state
end
end
end
Loading
Loading