-
Notifications
You must be signed in to change notification settings - Fork 982
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
Changes from 2 commits
0eda70c
747a5a7
1bf8ca5
b29a1d3
d71d9dd
23699f5
2bc2604
a7b0d6f
11cfd96
2dd9e82
66f5c37
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,7 +61,6 @@ | |
- [Modified `get_next_sync_committee_indices`](#modified-get_next_sync_committee_indices) | ||
- [Beacon state mutators](#beacon-state-mutators) | ||
- [Modified `initiate_validator_exit`](#modified-initiate_validator_exit) | ||
- [New `switch_to_compounding_validator`](#new-switch_to_compounding_validator) | ||
- [New `queue_excess_active_balance`](#new-queue_excess_active_balance) | ||
- [New `queue_entire_balance_and_reset_validator`](#new-queue_entire_balance_and_reset_validator) | ||
- [New `compute_exit_epoch_and_update_churn`](#new-compute_exit_epoch_and_update_churn) | ||
|
@@ -678,16 +677,6 @@ def initiate_validator_exit(state: BeaconState, index: ValidatorIndex) -> None: | |
validator.withdrawable_epoch = Epoch(validator.exit_epoch + MIN_VALIDATOR_WITHDRAWABILITY_DELAY) | ||
``` | ||
|
||
#### New `switch_to_compounding_validator` | ||
|
||
```python | ||
def switch_to_compounding_validator(state: BeaconState, index: ValidatorIndex) -> None: | ||
validator = state.validators[index] | ||
if has_eth1_withdrawal_credential(validator): | ||
validator.withdrawal_credentials = COMPOUNDING_WITHDRAWAL_PREFIX + validator.withdrawal_credentials[1:] | ||
queue_excess_active_balance(state, index) | ||
``` | ||
|
||
#### New `queue_excess_active_balance` | ||
|
||
```python | ||
|
@@ -928,8 +917,6 @@ def process_pending_consolidations(state: BeaconState) -> None: | |
if source_validator.withdrawable_epoch > next_epoch: | ||
break | ||
|
||
# Churn any target excess active balance of target and raise its max | ||
switch_to_compounding_validator(state, pending_consolidation.target_index) | ||
# Move active balance to target. Excess balance is withdrawable. | ||
active_balance = get_active_balance(state, pending_consolidation.source_index) | ||
decrease_balance(state, pending_consolidation.source_index, active_balance) | ||
|
@@ -1225,14 +1212,6 @@ def apply_deposit(state: BeaconState, | |
state.pending_balance_deposits.append( | ||
PendingBalanceDeposit(index=index, amount=amount) | ||
) # [Modified in Electra:EIP7251] | ||
# Check if valid deposit switch to compounding credentials | ||
if ( | ||
is_compounding_withdrawal_credential(withdrawal_credentials) | ||
and has_eth1_withdrawal_credential(state.validators[index]) | ||
and is_valid_deposit_signature(pubkey, withdrawal_credentials, amount, signature) | ||
): | ||
switch_to_compounding_validator(state, index) | ||
|
||
``` | ||
|
||
###### New `is_valid_deposit_signature` | ||
|
@@ -1431,10 +1410,6 @@ def process_consolidation_request( | |
source_validator = state.validators[source_index] | ||
target_validator = state.validators[target_index] | ||
|
||
# Verify that source != target, so a consolidation cannot be used as an exit. | ||
if source_index == target_index: | ||
return | ||
|
||
# Verify source withdrawal credentials | ||
has_correct_credential = has_execution_withdrawal_credential(source_validator) | ||
is_correct_source_address = ( | ||
|
@@ -1459,12 +1434,23 @@ def process_consolidation_request( | |
if target_validator.exit_epoch != FAR_FUTURE_EPOCH: | ||
return | ||
|
||
# Churn any target excess active balance of target and raise its max | ||
if has_eth1_withdrawal_credential(target_validator): | ||
state.validators[target_index].withdrawal_credentials = ( | ||
COMPOUNDING_WITHDRAWAL_PREFIX + target_validator.withdrawal_credentials[1:] | ||
) | ||
queue_excess_active_balance(state, target_index) | ||
|
||
# Verify that source != target, so a consolidation cannot be used as an exit. | ||
if source_index == target_index: | ||
return | ||
|
||
# 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 commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
state, source_validator.effective_balance | ||
) | ||
source_validator.withdrawable_epoch = Epoch( | ||
source_validator.exit_epoch + MIN_VALIDATOR_WITHDRAWABILITY_DELAY | ||
state.validators[source_index].withdrawable_epoch = Epoch( | ||
state.validators[source_index].exit_epoch + MIN_VALIDATOR_WITHDRAWABILITY_DELAY | ||
) | ||
state.pending_consolidations.append(PendingConsolidation( | ||
source_index=source_index, | ||
|
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.
lets do this later but I think we can also factor out a helper like
is_valid_consolidation_request