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

eip7251: Switch to compounding when consolidating with source==target #3918

Open
wants to merge 7 commits into
base: dev
Choose a base branch
from

Conversation

mkalinin
Copy link
Collaborator

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:

  • The switching logic is encapsulated into consolidation flow simplifying the Electra deposit flow
  • There is no need to deposit 1 ETH (minimal deposit amount) to switch to compounding credentials (consolidation request fee should be significantly lower than that)
  • The switch is authorized by the withdrawal credentials rather than validator’s pubkey which looks more secure

Additionally, this PR moves switching to compounding from process_pending_consolidations to process_consolidation_request which is cleaner and simpler to reason about as process_pending_consolidations doesn’t append to pending_deposit_balances queue anymore. Also the switch happens instantly instead of waiting for consolidation queue to be processed.

Copy link
Collaborator

@dapplion dapplion left a 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.

specs/electra/beacon-chain.md Outdated Show resolved Hide resolved
Co-authored-by: Lion - dapplion <35266934+dapplion@users.noreply.github.com>
# 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(
Copy link
Contributor

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.

Copy link
Collaborator Author

@mkalinin mkalinin Sep 17, 2024

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

Co-authored-by: Alex Stokes <r.alex.stokes@gmail.com>
@mkalinin
Copy link
Collaborator Author

mkalinin commented Sep 18, 2024

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.

@hwwhww hwwhww added the Electra label Sep 18, 2024
Comment on lines 35 to 36
else:
balance = spec.MAX_EFFECTIVE_BALANCE
Copy link
Member

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

Copy link
Collaborator Author

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.

Copy link
Member

@ralexstokes ralexstokes left a 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

@ethDreamer
Copy link
Contributor

love it!

Copy link
Contributor

@rolfyone rolfyone left a comment

Choose a reason for hiding this comment

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

LGTM

Comment on lines +1420 to +1422
# Verify source withdrawal credentials
if not has_eth1_withdrawal_credential(source_validator):
return False
Copy link
Member

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.

Copy link
Member

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.

Copy link
Collaborator Author

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

specs/electra/beacon-chain.md Outdated Show resolved Hide resolved
target_pubkey=state.validators[source_index].pubkey,
)

# exit source
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
# exit source
# Initiate exit for source

target_pubkey=state.validators[source_index].pubkey,
)

# set source validator as not yet activated
Copy link
Member

@jtraglia jtraglia Sep 26, 2024

Choose a reason for hiding this comment

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

Suggested change
# 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
Copy link
Member

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.

Suggested change
# Check the the return condition
# Check the return condition

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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants