Skip to content

Commit 4f3e932

Browse files
committed
Implement "Bugfix and more withdrawal tests"
1 parent b576003 commit 4f3e932

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

consensus/state_processing/src/per_block_processing.rs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::consensus_context::ConsensusContext;
22
use errors::{BlockOperationError, BlockProcessingError, HeaderInvalid};
33
use rayon::prelude::*;
4-
use safe_arith::{ArithError, SafeArith};
4+
use safe_arith::{ArithError, SafeArith, SafeArithIter};
55
use signature_sets::{block_proposal_signature_set, get_pubkey_from_state, randao_signature_set};
66
use std::borrow::Cow;
77
use tree_hash::TreeHash;
@@ -512,9 +512,9 @@ pub fn get_expected_withdrawals<E: EthSpec>(
512512

513513
// [New in Electra:EIP7251]
514514
// Consume pending partial withdrawals
515-
let partial_withdrawals_count =
515+
let processed_partial_withdrawals_count =
516516
if let Ok(partial_withdrawals) = state.pending_partial_withdrawals() {
517-
let mut partial_withdrawals_count = 0;
517+
let mut processed_partial_withdrawals_count = 0;
518518
for withdrawal in partial_withdrawals {
519519
if withdrawal.withdrawable_epoch > epoch
520520
|| withdrawals.len() == spec.max_pending_partials_per_withdrawals_sweep as usize
@@ -547,9 +547,9 @@ pub fn get_expected_withdrawals<E: EthSpec>(
547547
});
548548
withdrawal_index.safe_add_assign(1)?;
549549
}
550-
partial_withdrawals_count.safe_add_assign(1)?;
550+
processed_partial_withdrawals_count.safe_add_assign(1)?;
551551
}
552-
Some(partial_withdrawals_count)
552+
Some(processed_partial_withdrawals_count)
553553
} else {
554554
None
555555
};
@@ -560,9 +560,19 @@ pub fn get_expected_withdrawals<E: EthSpec>(
560560
);
561561
for _ in 0..bound {
562562
let validator = state.get_validator(validator_index as usize)?;
563-
let balance = *state.balances().get(validator_index as usize).ok_or(
564-
BeaconStateError::BalancesOutOfBounds(validator_index as usize),
565-
)?;
563+
let partially_withdrawn_balance = withdrawals
564+
.iter()
565+
.filter_map(|withdrawal| {
566+
(withdrawal.validator_index == validator_index).then_some(withdrawal.amount)
567+
})
568+
.safe_sum()?;
569+
let balance = state
570+
.balances()
571+
.get(validator_index as usize)
572+
.ok_or(BeaconStateError::BalancesOutOfBounds(
573+
validator_index as usize,
574+
))?
575+
.safe_sub(partially_withdrawn_balance)?;
566576
if validator.is_fully_withdrawable_at(balance, epoch, spec, fork_name) {
567577
withdrawals.push(Withdrawal {
568578
index: withdrawal_index,
@@ -594,7 +604,7 @@ pub fn get_expected_withdrawals<E: EthSpec>(
594604
.safe_rem(state.validators().len() as u64)?;
595605
}
596606

597-
Ok((withdrawals.into(), partial_withdrawals_count))
607+
Ok((withdrawals.into(), processed_partial_withdrawals_count))
598608
}
599609

600610
/// Apply withdrawals to the state.

testing/ef_tests/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
TESTS_TAG := v1.5.0-alpha.8
1+
TESTS_TAG := v1.5.0-alpha.10
22
TESTS = general minimal mainnet
33
TARBALLS = $(patsubst %,%-$(TESTS_TAG).tar.gz,$(TESTS))
44

0 commit comments

Comments
 (0)