Fix off-by-one in process_pending_consolidations#3868
Merged
hwwhww merged 4 commits intoethereum:devfrom Aug 8, 2024
Merged
Conversation
g11tech
approved these changes
Aug 6, 2024
fradamt
approved these changes
Aug 7, 2024
Contributor
fradamt
left a comment
There was a problem hiding this comment.
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>
hwwhww
approved these changes
Aug 7, 2024
Contributor
There was a problem hiding this comment.
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") |
Contributor
There was a problem hiding this comment.
edited: run_epoch_processing_withcompute_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, stateand call it with return values in tests:
pre, post = yield from compute_state_by_epoch_processing_to(spec, state, "process_pending_consolidations")
1 task
This was referenced Aug 22, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_epochbe the epoch the state is being transitioned tosource.withdrawable_epoch == next_epochto prevent consolidating balance from being withdrawnsource.withdrawable_epoch == next_epoch + 1to 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_epochinstead of thenext_epoch. Note that withprocess_pending_balance_depositscase 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!! 🙌