Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix off-by-one in process_pending_consolidations #3868

Merged
merged 4 commits into from
Aug 8, 2024

Conversation

mkalinin
Copy link
Collaborator

@mkalinin mkalinin commented Aug 6, 2024

Fixes an off-by-one in process_pending_consolidations, due to this bug a consolidation processing was delayed by an epoch which compounded with withdrawal sweep resulted in withdrawing the balance to EL instead of consolidating it to the target.

The fix

The expected logic of pending consolidation and deposit processing is as the following:

  • Let the next_epoch be the epoch the state is being transitioned to
  • Process pending consolidation if source.withdrawable_epoch == next_epoch to prevent consolidating balance from being withdrawn
  • Process pending deposit if source.withdrawable_epoch == next_epoch + 1 to prevent the balance to be accrued to the consolidating validator (as consolidations are processed after deposits in the epoch processing)

The actual logic uses current_epoch instead of the next_epoch. Note that with process_pending_balance_deposits case this would result in just delaying the processing by an epoch, while with consolidations it would lead to much worse outcome. The corresponding spec tests are added to cover both scenarios.

Huge gratitude to @parithosh and entire devops team for finding this bug on devnet-2. Fantastic catch!! 🙌

@hwwhww hwwhww added the Electra label Aug 6, 2024
@hwwhww hwwhww mentioned this pull request Aug 6, 2024
4 tasks
Copy link
Contributor

@fradamt fradamt left a comment

Choose a reason for hiding this comment

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

Lgtm! Your explanation perfectly matches the intended behavior, as far as I can tell from what I have previously noted in the wip annotated spec.

Nice catch 🐼s :)

Copy link
Contributor

@hwwhww hwwhww left a comment

Choose a reason for hiding this comment

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

LGTM! Thank you @mkalinin!

Some lines in tests seem a bit repeated, but I also didn't find a way to refactor the fragmented assertions better. 😭

Left a minor suggestion. I can refactor it tomorrow if you think it makes sense too.

Comment on lines +221 to +224
# Obtain state before the call to process_pending_consolidations
state_before_consolidation = compute_state_by_epoch_processing_to(spec, state, "process_pending_consolidations")

yield from run_epoch_processing_with(spec, state, "process_pending_consolidations")
Copy link
Contributor

@hwwhww hwwhww Aug 7, 2024

Choose a reason for hiding this comment

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

edited: run_epoch_processing_with compute_state_by_epoch_processing_to

Another solution is to make run_epoch_processing_to return values:

def run_epoch_processing_to(spec, state, process_name: str):
    ...
    pre = state.copy()
    ...
    return pre, state

and call it with return values in tests:

    pre, post = yield from compute_state_by_epoch_processing_to(spec, state, "process_pending_consolidations")

@hwwhww hwwhww merged commit f4e3908 into ethereum:dev Aug 8, 2024
26 checks passed
@hwwhww hwwhww added the general:bug Something isn't working label Aug 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Electra general:bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants