From cda10d059b61bc610493509803120e92c1bdf85b Mon Sep 17 00:00:00 2001 From: Mikhail Kalinin Date: Wed, 27 Mar 2024 16:49:12 +0600 Subject: [PATCH] Refactor EL withdraw request processing --- specs/_features/eip7251/beacon-chain.md | 29 +++++++++++++++++-------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/specs/_features/eip7251/beacon-chain.md b/specs/_features/eip7251/beacon-chain.md index c4aad0a6f..19fb7a91d 100644 --- a/specs/_features/eip7251/beacon-chain.md +++ b/specs/_features/eip7251/beacon-chain.md @@ -8,6 +8,7 @@ - [Introduction](#introduction) - [Constants](#constants) + - [Misc](#misc) - [Withdrawal prefixes](#withdrawal-prefixes) - [Domains](#domains) - [Presets](#presets) @@ -87,6 +88,12 @@ See [a modest proposal](https://notes.ethereum.org/@mikeneuder/increase-maxeb), The following values are (non-configurable) constants used throughout the specification. +### Misc + +| Name | Value | +| - | - | +| `FULL_EXIT_REQUEST_AMOUNT` | `uint64(2**64 - 1)` | + ### Withdrawal prefixes | Name | Value | @@ -866,7 +873,8 @@ def process_execution_layer_withdraw_request( execution_layer_withdraw_request: ExecutionLayerWithdrawRequest ) -> None: amount = execution_layer_withdraw_request.amount - is_full_exit_request = amount == 0 + is_full_exit_request = amount == FULL_EXIT_REQUEST_AMOUNT + # If partial withdrawal queue is full, only full exits are processed if len(state.pending_partial_withdrawals) >= PENDING_PARTIAL_WITHDRAWALS_LIMIT and not is_full_exit_request: return @@ -888,20 +896,23 @@ def process_execution_layer_withdraw_request( and get_current_epoch(state) >= validator.activation_epoch + SHARD_COMMITTEE_PERIOD ): return - # New condition: only allow partial withdrawals with compounding withdrawal credentials - if not (is_full_exit_request or has_compounding_withdrawal_credential(validator)): - return pending_balance_to_withdraw = sum( item.amount for item in state.pending_partial_withdrawals if item.index == index ) - # only exit validator if it has no pending withdrawals in the queue - if is_full_exit_request and pending_balance_to_withdraw > 0: - return if is_full_exit_request: - initiate_validator_exit(state, index) - elif state.balances[index] > MIN_ACTIVATION_BALANCE + pending_balance_to_withdraw: + # Only exit validator if it has no pending withdrawals in the queue + if pending_balance_to_withdraw == 0: + initiate_validator_exit(state, index) + + return + + + has_excess_balance = state.balances[index] > MIN_ACTIVATION_BALANCE + pending_balance_to_withdraw + + # Only allow partial withdrawals with compounding withdrawal credentials + if has_compounding_withdrawal_credential(validator) and has_excess_balance: to_withdraw = min( state.balances[index] - MIN_ACTIVATION_BALANCE - pending_balance_to_withdraw, amount