Skip to content

eip7251: Bugfix and more withdrawal tests#3979

Merged
jtraglia merged 2 commits intoethereum:devfrom
mkalinin:more-withdrawal-tests
Oct 30, 2024
Merged

eip7251: Bugfix and more withdrawal tests#3979
jtraglia merged 2 commits intoethereum:devfrom
mkalinin:more-withdrawal-tests

Conversation

@mkalinin
Copy link
Copy Markdown
Contributor

Follow up to #3943 with more withdrawal tests and yet another bugfix.
The PR does also proposes to rename partial_withdrawals_count to processed_partial_withdrawals_count and withdrawals test helper refactor.

The fix

The balance withdrawn upon request, i.e. by processing a pending partial withdrawal, wasn’t taken into account for the sweep. Potential outcome is a validator being considered partially withdrawable while it has no excess balance and effectively is not partially withdrawable.

The proposed fix is simply to check if validator index is already presented in the withdrawals and deduct the already withdrawn balance from the balance considered by the sweep.

Copy link
Copy Markdown
Member

@jtraglia jtraglia left a comment

Choose a reason for hiding this comment

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

Thanks for this! It looks really good.

  • The name processed_partial_withdrawals_count makes sense 👍
  • Good catch on the bug, the fix looks correct to me.
  • The new tests are nice. I see no issues here, just a few questions.

Copy link
Copy Markdown
Member

@haxxpop haxxpop left a comment

Choose a reason for hiding this comment

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

The idea looks good to me

balance = state.balances[validator_index]
# [Modified in Electra:EIP7251]
partially_withdrawn_balance = sum(
withdrawal.amount for withdrawal in withdrawals if withdrawal.validator_index == validator_index)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Alternatively, it could iterate over withdrawals[:effective_partial_withdrawals_count] which contains partial withdrawals included during the current run. In cases when there are no withdrawal requests eligible for processing this computation will be a noop. But we can also leave the existing computation in the spec for simplicity and defer possible optimisation to the implementations

Copy link
Copy Markdown
Member

@haxxpop haxxpop Oct 18, 2024

Choose a reason for hiding this comment

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

What is effective_partial_withdrawals_count? I cannot find its definition.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@ppopth I think he meant processed_partial_withdrawals_count, the newly renamed variable.

Copy link
Copy Markdown
Contributor Author

@mkalinin mkalinin Oct 19, 2024

Choose a reason for hiding this comment

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

effective_partial_withdrawals_count = len(withdrawals) computed before the sweep. processed_partial_withdrawals_count may be greater than that number due to skipped partial withdrawals

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

That makes sense then.

Co-authored-by: Justin Traglia <95511699+jtraglia@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants