Replace MIN_ACTIVATION_BALANCE with MAX_EFFECTIVE_BALANCE
This commit is contained in:
parent
cda10d059b
commit
6f5cc4baf5
|
@ -373,7 +373,7 @@ def get_validator_max_effective_balance(validator: Validator) -> Gwei:
|
||||||
if has_compounding_withdrawal_credential(validator):
|
if has_compounding_withdrawal_credential(validator):
|
||||||
return MAX_EFFECTIVE_BALANCE_EIP7251
|
return MAX_EFFECTIVE_BALANCE_EIP7251
|
||||||
else:
|
else:
|
||||||
return MIN_ACTIVATION_BALANCE
|
return MAX_EFFECTIVE_BALANCE
|
||||||
```
|
```
|
||||||
|
|
||||||
#### New `get_churn_limit`
|
#### New `get_churn_limit`
|
||||||
|
@ -411,12 +411,8 @@ def get_consolidation_churn_limit(state: BeaconState) -> Gwei:
|
||||||
|
|
||||||
```python
|
```python
|
||||||
def get_active_balance(state: BeaconState, validator_index: ValidatorIndex) -> Gwei:
|
def get_active_balance(state: BeaconState, validator_index: ValidatorIndex) -> Gwei:
|
||||||
active_balance_ceil = (
|
max_effective_balance = get_validator_max_effective_balance(state.validators[validator_index])
|
||||||
MIN_ACTIVATION_BALANCE
|
return min(state.balances[validator_index], max_effective_balance)
|
||||||
if has_eth1_withdrawal_credential(state.validators[validator_index])
|
|
||||||
else MAX_EFFECTIVE_BALANCE_EIP7251
|
|
||||||
)
|
|
||||||
return min(state.balances[validator_index], active_balance_ceil)
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### Beacon state mutators
|
### Beacon state mutators
|
||||||
|
@ -649,16 +645,12 @@ def process_effective_balance_updates(state: BeaconState) -> None:
|
||||||
HYSTERESIS_INCREMENT = uint64(EFFECTIVE_BALANCE_INCREMENT // HYSTERESIS_QUOTIENT)
|
HYSTERESIS_INCREMENT = uint64(EFFECTIVE_BALANCE_INCREMENT // HYSTERESIS_QUOTIENT)
|
||||||
DOWNWARD_THRESHOLD = HYSTERESIS_INCREMENT * HYSTERESIS_DOWNWARD_MULTIPLIER
|
DOWNWARD_THRESHOLD = HYSTERESIS_INCREMENT * HYSTERESIS_DOWNWARD_MULTIPLIER
|
||||||
UPWARD_THRESHOLD = HYSTERESIS_INCREMENT * HYSTERESIS_UPWARD_MULTIPLIER
|
UPWARD_THRESHOLD = HYSTERESIS_INCREMENT * HYSTERESIS_UPWARD_MULTIPLIER
|
||||||
EFFECTIVE_BALANCE_LIMIT = (
|
max_effective_balance = get_validator_max_effective_balance(validator)
|
||||||
MAX_EFFECTIVE_BALANCE_EIP7251 if has_compounding_withdrawal_credential(validator)
|
|
||||||
else MIN_ACTIVATION_BALANCE
|
|
||||||
)
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
balance + DOWNWARD_THRESHOLD < validator.effective_balance
|
balance + DOWNWARD_THRESHOLD < validator.effective_balance
|
||||||
or validator.effective_balance + UPWARD_THRESHOLD < balance
|
or validator.effective_balance + UPWARD_THRESHOLD < balance
|
||||||
):
|
):
|
||||||
validator.effective_balance = min(balance - balance % EFFECTIVE_BALANCE_INCREMENT, EFFECTIVE_BALANCE_LIMIT)
|
validator.effective_balance = min(balance - balance % EFFECTIVE_BALANCE_INCREMENT, max_effective_balance) # [Modified in EIP7251]
|
||||||
```
|
```
|
||||||
|
|
||||||
### Block processing
|
### Block processing
|
||||||
|
@ -689,8 +681,8 @@ def get_expected_withdrawals(state: BeaconState) -> Tuple[Sequence[Withdrawal],
|
||||||
break
|
break
|
||||||
|
|
||||||
validator = state.validators[withdrawal.index]
|
validator = state.validators[withdrawal.index]
|
||||||
if validator.exit_epoch == FAR_FUTURE_EPOCH and state.balances[withdrawal.index] > MIN_ACTIVATION_BALANCE:
|
if validator.exit_epoch == FAR_FUTURE_EPOCH and state.balances[withdrawal.index] > MAX_EFFECTIVE_BALANCE:
|
||||||
withdrawable_balance = min(state.balances[withdrawal.index] - MIN_ACTIVATION_BALANCE, withdrawal.amount)
|
withdrawable_balance = min(state.balances[withdrawal.index] - MAX_EFFECTIVE_BALANCE, withdrawal.amount)
|
||||||
withdrawals.append(Withdrawal(
|
withdrawals.append(Withdrawal(
|
||||||
index=withdrawal_index,
|
index=withdrawal_index,
|
||||||
validator_index=withdrawal.index,
|
validator_index=withdrawal.index,
|
||||||
|
@ -909,12 +901,12 @@ def process_execution_layer_withdraw_request(
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
has_excess_balance = state.balances[index] > MIN_ACTIVATION_BALANCE + pending_balance_to_withdraw
|
has_excess_balance = state.balances[index] > MAX_EFFECTIVE_BALANCE + pending_balance_to_withdraw
|
||||||
|
|
||||||
# Only allow partial withdrawals with compounding withdrawal credentials
|
# Only allow partial withdrawals with compounding withdrawal credentials
|
||||||
if has_compounding_withdrawal_credential(validator) and has_excess_balance:
|
if has_compounding_withdrawal_credential(validator) and has_excess_balance:
|
||||||
to_withdraw = min(
|
to_withdraw = min(
|
||||||
state.balances[index] - MIN_ACTIVATION_BALANCE - pending_balance_to_withdraw,
|
state.balances[index] - MAX_EFFECTIVE_BALANCE - pending_balance_to_withdraw,
|
||||||
amount
|
amount
|
||||||
)
|
)
|
||||||
exit_queue_epoch = compute_exit_epoch_and_update_churn(state, to_withdraw)
|
exit_queue_epoch = compute_exit_epoch_and_update_churn(state, to_withdraw)
|
||||||
|
@ -935,7 +927,7 @@ def process_consolidation(state: BeaconState, signed_consolidation: SignedConsol
|
||||||
# If the pending consolidations queue is full, no consolidations are allowed in the block
|
# If the pending consolidations queue is full, no consolidations are allowed in the block
|
||||||
assert len(state.pending_consolidations) < PENDING_CONSOLIDATIONS_LIMIT
|
assert len(state.pending_consolidations) < PENDING_CONSOLIDATIONS_LIMIT
|
||||||
# If there is too little available consolidation churn limit, no consolidations are allowed in the block
|
# If there is too little available consolidation churn limit, no consolidations are allowed in the block
|
||||||
assert get_consolidation_churn_limit(state) > MIN_ACTIVATION_BALANCE
|
assert get_consolidation_churn_limit(state) > MAX_EFFECTIVE_BALANCE
|
||||||
consolidation = signed_consolidation.message
|
consolidation = signed_consolidation.message
|
||||||
# Verify that source != target, so a consolidation cannot be used as an exit.
|
# Verify that source != target, so a consolidation cannot be used as an exit.
|
||||||
assert consolidation.source_index != consolidation.target_index
|
assert consolidation.source_index != consolidation.target_index
|
||||||
|
|
Loading…
Reference in New Issue