From 5c3a51ae794f1d61c9dbc5f9e64c790ea5b077ba Mon Sep 17 00:00:00 2001 From: Mikhail Kalinin Date: Tue, 25 Jun 2024 17:26:17 +0600 Subject: [PATCH] Process deposit requests after Eth1 bridge deposits are applied --- specs/electra/beacon-chain.md | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/specs/electra/beacon-chain.md b/specs/electra/beacon-chain.md index e87ca5003..e096eaf30 100644 --- a/specs/electra/beacon-chain.md +++ b/specs/electra/beacon-chain.md @@ -635,7 +635,7 @@ def get_activation_churn_consumption(state: BeaconState, pending_deposit: Pendin if pending_deposit.pubkey not in validator_pubkeys: return pending_deposit.amount else: - validator_index = ValidatorIndex(validator_pubkeys.index(deposit.pubkey)) + validator_index = ValidatorIndex(validator_pubkeys.index(pending_deposit.pubkey)) validator = state.validators[validator_index] # Validator is exiting, do not consume the churn if validator.exit_epoch < FAR_FUTURE_EPOCH: @@ -850,8 +850,15 @@ def process_pending_deposits(state: BeaconState) -> None: processed_amount = 0 next_deposit_index = 0 deposits_to_postpone = [] + is_churn_limit_reached = False for deposit in state.pending_deposits: + # Do not process any deposit requests if Eth1 bridge deposits are not yet applied + if (state.deposit_requests_start_index != UNSET_DEPOSIT_REQUESTS_START_INDEX + and state.eth1_deposit_index < state.deposit_requests_start_index + and deposit.slot > GENESIS_SLOT): + break + # Check if number of processed deposits fits in the limit if next_deposit_index > MAX_PENDING_DEPOSITS_PER_EPOCH_PROCESSING: break @@ -859,6 +866,7 @@ def process_pending_deposits(state: BeaconState) -> None: # Check if deposit fits in the churn, otherwise, do no more deposit processing in this epoch. churn_consumption = get_activation_churn_consumption(state, deposit) if processed_amount + churn_consumption > available_for_processing: + is_churn_limit_reached = True break # Consume churn and process deposit @@ -907,10 +915,10 @@ def process_pending_deposits(state: BeaconState) -> None: state.pending_deposits = state.pending_deposits[next_deposit_index:] - if len(state.pending_deposits) == 0: - state.deposit_balance_to_consume = Gwei(0) - else: + if is_churn_limit_reached: state.deposit_balance_to_consume = available_for_processing - processed_amount + else: + state.deposit_balance_to_consume = Gwei(0) state.pending_deposits += deposits_to_postpone ```