Skip to content

Reserve space for one validator sweep withdrawal#4832

Merged
jtraglia merged 3 commits intoethereum:masterfrom
jtraglia:reserve-for-validator-sweep
Jan 14, 2026
Merged

Reserve space for one validator sweep withdrawal#4832
jtraglia merged 3 commits intoethereum:masterfrom
jtraglia:reserve-for-validator-sweep

Conversation

@jtraglia
Copy link
Copy Markdown
Member

In order for update_next_withdrawal_validator_index to function properly, the last withdrawal must be from the validator sweep (or empty).

def update_next_withdrawal_validator_index(
state: BeaconState, withdrawals: Sequence[Withdrawal]
) -> None:
# Update the next validator index to start the next withdrawal sweep
if len(withdrawals) == MAX_WITHDRAWALS_PER_PAYLOAD:
# Next sweep starts after the latest withdrawal's validator index
next_validator_index = ValidatorIndex(
(withdrawals[-1].validator_index + 1) % len(state.validators)
)
state.next_withdrawal_validator_index = next_validator_index
else:
# Advance sweep by the max length of the sweep if there was not a full set of withdrawals
next_index = state.next_withdrawal_validator_index + MAX_VALIDATORS_PER_WITHDRAWALS_SWEEP
next_validator_index = ValidatorIndex(next_index % len(state.validators))
state.next_withdrawal_validator_index = next_validator_index

@jihoonsong
Copy link
Copy Markdown
Member

jihoonsong commented Jan 13, 2026

While either adding the assertion or switching has_reached_limit from == to >= achieves the same goal, I'd prefer the prior as it makes it explicit what the precondition of each withdrawal function is. With those assertions, len(all_withdrawals) cannot be greater than withdrawals_limit, but I don't think it hurts to change to >=.

@jtraglia
Copy link
Copy Markdown
Member Author

While either adding the assertion or switching has_reached_limit from == to >= achieves the same goal, I'd prefer the prior as it makes it explicit what the precondition of each withdrawal function is. With those assertions, len(all_withdrawals) cannot be greater than withdrawals_limit, but I don't think it hurts to change to >=.

I agree with this & this is the reason why I did both (asserts & comp changes).

Copy link
Copy Markdown
Contributor

@potuz potuz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Copy Markdown
Member

@jihoonsong jihoonsong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that we have four withdrawal functions, passing max_withdrawals_limit or something similar would make these functions less stateful. Nonetheless, this PR achieves what it aims for.

@jtraglia jtraglia merged commit a5a56a9 into ethereum:master Jan 14, 2026
17 checks passed
@jtraglia jtraglia deleted the reserve-for-validator-sweep branch January 14, 2026 15:58
leolara added a commit to leolara/consensus-specs that referenced this pull request Jan 19, 2026
leolara added a commit to leolara/consensus-specs that referenced this pull request Jan 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants