Skip to content

Commit

Permalink
Fix partal withdrawal code
Browse files Browse the repository at this point in the history
  • Loading branch information
lucassaldanha committed Dec 5, 2024
1 parent f2c21f3 commit 410b739
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ allprojects {
}

def nightly = System.getenv("NIGHTLY") != null
def refTestVersion = nightly ? "nightly" : "v1.5.0-alpha.8"
def refTestVersion = nightly ? "nightly" : "v1.5.0-alpha.9"
def blsRefTestVersion = 'v0.1.2'
def slashingProtectionInterchangeRefTestVersion = 'v5.3.0'
def refTestBaseUrl = 'https://github.com/ethereum/consensus-spec-tests/releases/download'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ private static WithdrawalSummary getPendingPartialWithdrawals(
final List<Withdrawal> partialWithdrawals = new ArrayList<>();
final SszList<PendingPartialWithdrawal> pendingPartialWithdrawals =
preState.getPendingPartialWithdrawals();
int partialWithdrawalsCount = 0;
int processedPartialWithdrawalsCount = 0;
UInt64 withdrawalIndex = preState.getNextWithdrawalIndex();

for (int i = 0; i < pendingPartialWithdrawals.size() && i < maxPendingPartialWithdrawals; i++) {
Expand Down Expand Up @@ -198,9 +198,9 @@ private static WithdrawalSummary getPendingPartialWithdrawals(
withdrawableBalance));
withdrawalIndex = withdrawalIndex.increment();
}
partialWithdrawalsCount++;
processedPartialWithdrawalsCount++;
}
return new WithdrawalSummary(partialWithdrawals, partialWithdrawalsCount);
return new WithdrawalSummary(partialWithdrawals, processedPartialWithdrawalsCount);
}

// get_expected_withdrawals
Expand Down Expand Up @@ -231,7 +231,16 @@ private static List<Withdrawal> getExpectedWithdrawals(
for (int i = 0; i < bound; i++) {
final Validator validator = validators.get(validatorIndex);
if (predicates.hasExecutionWithdrawalCredential(validator)) {
final UInt64 balance = balances.get(validatorIndex).get();
final UInt64 finalValidatorIndex = UInt64.valueOf(validatorIndex);
final UInt64 partiallyWithdrawalBalance =
partialWithdrawals.stream()
.filter(
partialWithdrawal ->
partialWithdrawal.getValidatorIndex().equals(finalValidatorIndex))
.map(Withdrawal::getAmount)
.reduce(UInt64.ZERO, UInt64::plus);
final UInt64 balance =
balances.get(validatorIndex).get().minusMinZero(partiallyWithdrawalBalance);

if (predicates.isFullyWithdrawableValidatorCredentialsChecked(validator, balance, epoch)) {
expectedWithdrawals.add(
Expand Down

0 comments on commit 410b739

Please sign in to comment.