diff --git a/consensus/types/src/beacon_state.rs b/consensus/types/src/beacon_state.rs index 085b2fb9886..4db17aea5c4 100644 --- a/consensus/types/src/beacon_state.rs +++ b/consensus/types/src/beacon_state.rs @@ -2456,8 +2456,13 @@ impl BeaconState { .map_err(Into::into) } + // TODO(EIP-7732): The consensus spec PR for this change mentions that some EF tests will be needed but haven't been created yet. + // We should integrate them once they are available. + // https://github.com/ethereum/consensus-specs/pull/4513 pub fn get_pending_balance_to_withdraw(&self, validator_index: usize) -> Result { let mut pending_balance = 0; + + // Sum pending partial withdrawals for withdrawal in self .pending_partial_withdrawals()? .iter() @@ -2465,6 +2470,27 @@ impl BeaconState { { pending_balance.safe_add_assign(withdrawal.amount)?; } + + // Sum builder pending withdrawals + if let Ok(builder_pending_withdrawals) = self.builder_pending_withdrawals() { + for withdrawal in builder_pending_withdrawals + .iter() + .filter(|withdrawal| withdrawal.builder_index as usize == validator_index) + { + pending_balance.safe_add_assign(withdrawal.amount)?; + } + } + + // Sum builder pending payments + if let Ok(builder_pending_payments) = self.builder_pending_payments() { + for payment in builder_pending_payments + .iter() + .filter(|payment| payment.withdrawal.builder_index as usize == validator_index) + { + pending_balance.safe_add_assign(payment.withdrawal.amount)?; + } + } + Ok(pending_balance) }