@@ -171,8 +171,7 @@ public void processWithdrawals(
171171 expectedWithdrawals .withdrawals (),
172172 expectedWithdrawals .processedBuilderWithdrawalsCount (),
173173 expectedWithdrawals .processedPartialWithdrawalsCount (),
174- expectedWithdrawals .processedBuildersSweepCount (),
175- expectedWithdrawals .processedValidatorsSweepCount ());
174+ expectedWithdrawals .processedBuildersSweepCount ());
176175 }
177176
178177 private void assertWithdrawalsInExecutionPayloadMatchExpected (
@@ -208,17 +207,15 @@ public void processWithdrawals(final MutableBeaconState state) {
208207 expectedWithdrawals .withdrawals (),
209208 expectedWithdrawals .processedBuilderWithdrawalsCount (),
210209 expectedWithdrawals .processedPartialWithdrawalsCount (),
211- expectedWithdrawals .processedBuildersSweepCount (),
212- expectedWithdrawals .processedValidatorsSweepCount ());
210+ expectedWithdrawals .processedBuildersSweepCount ());
213211 }
214212
215213 private void processWithdrawalsUnchecked (
216214 final MutableBeaconState state ,
217215 final List <Withdrawal > withdrawals ,
218216 final int processedBuilderWithdrawalsCount ,
219217 final int processedPartialWithdrawalsCount ,
220- final int processedBuildersSweepCount ,
221- final int processedValidatorsSweepCount ) {
218+ final int processedBuildersSweepCount ) {
222219
223220 applyWithdrawals (state , withdrawals );
224221
@@ -236,7 +233,7 @@ private void processWithdrawalsUnchecked(
236233
237234 updateNextWithdrawalBuilderIndex (state , processedBuildersSweepCount );
238235
239- updateNextWithdrawalValidatorIndex (state , processedValidatorsSweepCount );
236+ updateNextWithdrawalValidatorIndex (state , withdrawals );
240237 }
241238
242239 protected void applyWithdrawals (
@@ -274,12 +271,22 @@ protected void updateNextWithdrawalBuilderIndex(
274271 final MutableBeaconState state , final int processedBuildersSweepCount ) {}
275272
276273 protected void updateNextWithdrawalValidatorIndex (
277- final MutableBeaconState state , final int processedValidatorsSweepCount ) {
274+ final MutableBeaconState state , final List < Withdrawal > withdrawals ) {
278275 final MutableBeaconStateCapella stateCapella = MutableBeaconStateCapella .required (state );
279- // Update the next validator index to start the next withdrawal sweep
280- final UInt64 nextIndex =
281- stateCapella .getNextWithdrawalValidatorIndex ().plus (processedValidatorsSweepCount );
282- final UInt64 nextValidatorIndex = nextIndex .mod (state .getValidators ().size ());
283- stateCapella .setNextWithdrawalValidatorIndex (nextValidatorIndex );
276+
277+ if (withdrawals .size () == specConfig .getMaxWithdrawalsPerPayload ()) {
278+ // Next sweep starts after the latest withdrawal's validator index
279+ final UInt64 nextValidatorIndex =
280+ withdrawals .getLast ().getValidatorIndex ().plus (1 ).mod (state .getValidators ().size ());
281+ stateCapella .setNextWithdrawalValidatorIndex (nextValidatorIndex );
282+ } else {
283+ // Advance sweep by the max length of the sweep if there was not a full set of withdrawals
284+ final UInt64 nextIndex =
285+ stateCapella
286+ .getNextWithdrawalValidatorIndex ()
287+ .plus (specConfig .getMaxValidatorsPerWithdrawalSweep ());
288+ final UInt64 nextValidatorIndex = nextIndex .mod (state .getValidators ().size ());
289+ stateCapella .setNextWithdrawalValidatorIndex (nextValidatorIndex );
290+ }
284291 }
285292}
0 commit comments