Enforce Activation Rate Limit at Fork Transition

This commit is contained in:
Mark Mackey 2024-04-08 15:58:36 -06:00
parent dd2721f3c6
commit 397c2beeb8
2 changed files with 31 additions and 0 deletions

View File

@ -51,6 +51,7 @@
- [Updated `initiate_validator_exit`](#updated--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)
- [New `compute_consolidation_epoch_and_update_churn`](#new-compute_consolidation_epoch_and_update_churn)
- [Updated `slash_validator`](#updated-slash_validator)
@ -526,6 +527,19 @@ def queue_excess_active_balance(state: BeaconState, index: ValidatorIndex) -> No
)
```
#### New `queue_entire_balance_and_reset_validator`
```python
def queue_entire_balance_and_reset_validator(state: BeaconState, index: ValidatorIndex) -> None:
balance = state.balances[index]
state.balances[index] = 0
validator = state.validators[index]
validator.effective_balance = 0
validator.activation_eligibility_epoch = FAR_FUTURE_EPOCH
state.pending_balance_deposits.append(
PendingBalanceDeposit(index=index, amount=balance)
)
```
#### New `compute_exit_epoch_and_update_churn`
```python

View File

@ -128,6 +128,23 @@ def upgrade_to_eip7251(pre: deneb.BeaconState) -> BeaconState:
pending_consolidations=[],
)
activation_queue = []
pre_activation_queue = []
below_minimum = []
for index, validator in enumerate(post.validators):
if validator.activation_epoch == FAR_FUTURE_EPOCH:
if validator.activation_eligibility_epoch != FAR_FUTURE_EPOCH:
activation_queue.append(index)
else:
if validator.effective_balance >= MIN_ACTIVATION_BALANCE:
pre_activation_queue.append(index)
else:
below_minimum.append(index)
activation_queue.sort(key=lambda index: (post.validators[index].activation_eligibility_epoch, index))
for index in activation_queue + pre_activation_queue + below_minimum:
queue_entire_balance_and_reset_validator(post, ValidatorIndex(index))
# Ensure early adopters of compounding credentials go through the activation churn
for index, validator in enumerate(post.validators):
if has_compounding_withdrawal_credential(validator):