-
Notifications
You must be signed in to change notification settings - Fork 997
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
Conversation
There was a problem hiding this 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 :)
tests/core/pyspec/eth2spec/test/electra/epoch_processing/test_process_pending_consolidations.py
Outdated
Show resolved
Hide resolved
tests/core/pyspec/eth2spec/test/electra/epoch_processing/test_process_pending_consolidations.py
Show resolved
Hide resolved
tests/core/pyspec/eth2spec/test/electra/epoch_processing/test_process_pending_consolidations.py
Outdated
Show resolved
Hide resolved
tests/core/pyspec/eth2spec/test/electra/epoch_processing/test_process_pending_consolidations.py
Outdated
Show resolved
Hide resolved
Co-authored-by: fradamt <104826920+fradamt@users.noreply.github.com>
There was a problem hiding this 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.
# 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") |
There was a problem hiding this comment.
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")
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:
next_epoch
be the epoch the state is being transitioned tosource.withdrawable_epoch == next_epoch
to prevent consolidating balance from being withdrawnsource.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 thenext_epoch
. Note that withprocess_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!! 🙌