# `partial_withdrawals_count` should account for skipped `pending_partial_withdrawals` *Based on consensus spec commit: `666b63ac38f9239eade9ed45e47ef0c1fa6501e9`* --- In Electra, to process withdrawals, we first call `get_expected_withdrawals`, which returns `expected_withdrawals` and `partial_withdrawals_count`. To consume a pending partial withdrawal, the validator must have sufficient effective balance and excess balance, otherwise the validator is skipped. `partial_withdrawals_count` **represents the number of valid partial withdrawals that can be processed**. Finally, in `process_withdrawal`, we prune the state's `pending_partial_withdrawals` using `partial_withdrawals_count`. ```python def process_withdrawals(state: BeaconState, payload: ExecutionPayload) -> None: expected_withdrawals, partial_withdrawals_count = get_expected_withdrawals(state) # [Modified in Electra:EIP7251] for withdrawal in expected_withdrawals: decrease_balance(state, withdrawal.validator_index, withdrawal.amount) state.pending_partial_withdrawals = state.pending_partial_withdrawals[partial_withdrawals_count:] ``` The issue with this is that when a `pending_partial_withdrawal` is skipped, it creates an offset when we prune the `pending_partial_withdrawals` using `partial_withdrawals_count`. For example: - The pending withdrawals in state is `[{validator_index: 0, amount: 1eth}, {validator_index: 1, amount: 1eth}, {validator_index: 2, amount: 1eth}]` - The validator balances at the time of processing are: `[31eth, 34eth, 34eth]` - After processing withdrawals, the pending withdrawal request becomes: `[{validator_index: 2, amount: 1eth}]` - The validator balances are now: `[31eth, 33eth, 33eth]` - One epoch later, `[{validator_index: 2, amount: 1eth}]` is processed and validator balances are now `[31eth, 33eth, 32eth]` This means `validator_index` 2 will get processed for 1eth twice even though it only sent one withdrawal request for 1eth. One way to solve this is to simply count `partial_withdrawals_count` in the loop `for withdrawal in state.pending_partial_withdrawals:` such that a skipped `withdrawal` also increments the count. This ensures that the pruning process remains accurate and accounts for all pending withdrawals, including those that are skipped.