From fb486c86b9a9921ca93f88d8dfce5eea182d76d1 Mon Sep 17 00:00:00 2001 From: Suphanat Chunhapanya Date: Sun, 29 Sep 2024 11:39:29 +0700 Subject: [PATCH] EIP-7251: Flatten get_active_balance We have both get_active_balance and get_total_active_balance which have totally different meanings, since get_active_balance uses the balance field while get_total_active_balance uses the effective_balance field. The names suggest that get_total_active_balance is the total of get_active_balance which is not true. The name of get_active_balance doesn't quite make sense and it's used only in one place, so this commit flattens the logic of get_active_balance to the place where it's used. --- specs/electra/beacon-chain.md | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/specs/electra/beacon-chain.md b/specs/electra/beacon-chain.md index dbf84d8de8..a40d532c49 100644 --- a/specs/electra/beacon-chain.md +++ b/specs/electra/beacon-chain.md @@ -53,7 +53,6 @@ - [New `get_balance_churn_limit`](#new-get_balance_churn_limit) - [New `get_activation_exit_churn_limit`](#new-get_activation_exit_churn_limit) - [New `get_consolidation_churn_limit`](#new-get_consolidation_churn_limit) - - [New `get_active_balance`](#new-get_active_balance) - [New `get_pending_balance_to_withdraw`](#new-get_pending_balance_to_withdraw) - [Modified `get_attesting_indices`](#modified-get_attesting_indices) - [Modified `get_next_sync_committee_indices`](#modified-get_next_sync_committee_indices) @@ -539,14 +538,6 @@ def get_consolidation_churn_limit(state: BeaconState) -> Gwei: return get_balance_churn_limit(state) - get_activation_exit_churn_limit(state) ``` -#### New `get_active_balance` - -```python -def get_active_balance(state: BeaconState, validator_index: ValidatorIndex) -> Gwei: - max_effective_balance = get_max_effective_balance(state.validators[validator_index]) - return min(state.balances[validator_index], max_effective_balance) -``` - #### New `get_pending_balance_to_withdraw` ```python @@ -884,10 +875,14 @@ def process_pending_consolidations(state: BeaconState) -> None: # Churn any target excess active balance of target and raise its max switch_to_compounding_validator(state, pending_consolidation.target_index) + + # Calculate the consolidated balance + max_effective_balance = get_max_effective_balance(source_validator) + consolidated_balance = min(state.balances[pending_consolidation.source_index], max_effective_balance) + # 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) - increase_balance(state, pending_consolidation.target_index, active_balance) + decrease_balance(state, pending_consolidation.source_index, consolidated_balance) + increase_balance(state, pending_consolidation.target_index, consolidated_balance) next_pending_consolidation += 1 state.pending_consolidations = state.pending_consolidations[next_pending_consolidation:]