-
Notifications
You must be signed in to change notification settings - Fork 958
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
eip7251: Switch to compounding when consolidating with source==target #3918
base: dev
Are you sure you want to change the base?
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.
Clean simplification! Much better to signal the switch without requiring the 1 ETH deposit.
Co-authored-by: Lion - dapplion <35266934+dapplion@users.noreply.github.com>
specs/electra/beacon-chain.md
Outdated
# Initiate source validator exit and append pending consolidation | ||
source_validator.exit_epoch = compute_consolidation_epoch_and_update_churn( | ||
state.validators[source_index].exit_epoch = compute_consolidation_epoch_and_update_churn( |
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.
I think in Python variable is assigned to a reference. So if you modify a variable that is a reference to an element in an array, the array element will be updated as well.
I don't see why we would need to replace source_validator
with state.validators[source_index]
explicitly when updating. Unless I am missing something.
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.
Yes, you’re right, and the reason for doing so is the bug somewhere in one of the components that spec relies on, likely in remerklable. Consider the following test:
@with_electra_and_later
@spec_state_test
def test_state_changes_overwritten(spec, state):
validator_0 = state.validators[0]
validator_1 = state.validators[1]
validator_0.exit_epoch = spec.Epoch(0)
validator_1.exit_epoch = spec.Epoch(1)
assert state.validators[1].exit_epoch == spec.Epoch(1)
assert state.validators[0].exit_epoch == spec.Epoch(0)
The second assert fails while it must not. This problem requires a separate work, and I decided to use a workaround for this spec change. Filed an issue #3925
tests/core/pyspec/eth2spec/test/electra/block_processing/test_process_consolidation_request.py
Outdated
Show resolved
Hide resolved
Co-authored-by: Alex Stokes <r.alex.stokes@gmail.com>
I’ve attempted to isolate the switch to compounding flow from the main consolidation flow, the reason for that is slightly different checks considering that source equals target, especially the switch request should be valid even when there is not enough consolidation churn and pending consolidation queue is full. This entailed update to the spec tests as well but left the consolidation flow pretty much the same as it was before. IMHO, the spec became more readable and easier to reason about. Sorry for almost the last minute change to this request. |
else: | ||
balance = spec.MAX_EFFECTIVE_BALANCE |
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.
I'd have to check how this helper is used but I wonder if we should keep balance
at 32 ETH, regardless of the fork
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.
Let me just revert this change for now, I think proper changes should also include new tests for the cases when the withdrawal sweep is applied to compounding creds.
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.
generally looks good! I like uncoupling the "switch to compounding" flow from the deposit flow as much as we can
will also want to review in the context of the other refactors to the core pectra EIPs we are looking at
love it! |
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
# Verify source withdrawal credentials | ||
if not has_eth1_withdrawal_credential(source_validator): | ||
return False |
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.
Maybe worth mentioning that this is what prevents the switch from happening twice.
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.
Hmm actually, I'm not sure that would be very useful. I just had to double check it was the correct method, ie not has_execution_withdrawal_credential
which checks for compounding
and eth1
creds.
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.
Before the proposed change, the switch_to_compounding_validator
were doing this check. We can bring it back to this method but as for me switch_to_
is imperative and shouldn’t be conditional, so the outer check makes more sense to me
target_pubkey=state.validators[source_index].pubkey, | ||
) | ||
|
||
# exit source |
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.
# exit source | |
# Initiate exit for source |
target_pubkey=state.validators[source_index].pubkey, | ||
) | ||
|
||
# set source validator as not yet activated |
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.
# set source validator as not yet activated | |
# Set source validator as it's not yet activated |
# exit source | ||
spec.initiate_validator_exit(state, source_index) | ||
|
||
# Check the the return condition |
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.
This typo is present in all of the failing tests.
# Check the the return condition | |
# Check the return condition |
Co-authored-by: Justin Traglia <95511699+jtraglia@users.noreply.github.com>
This PR implements @ralexstokes’s idea of switching validator to compounding credentials via consolidation request rather than depositing with the updated withdrawal credentials. The pure switch happens when a consolidation request has
source_index == target_index
. Advantages of this approach:Additionally, this PR moves switching to compounding from
process_pending_consolidations
toprocess_consolidation_request
which is cleaner and simpler to reason about asprocess_pending_consolidations
doesn’t append topending_deposit_balances
queue anymore. Also the switch happens instantly instead of waiting for consolidation queue to be processed.