Skip to content

Commit 0c8645e

Browse files
authored
EIP-7251: Flatten get_active_balance (#3949)
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.
1 parent bda8957 commit 0c8645e

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

specs/electra/beacon-chain.md

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
- [New `get_balance_churn_limit`](#new-get_balance_churn_limit)
5454
- [New `get_activation_exit_churn_limit`](#new-get_activation_exit_churn_limit)
5555
- [New `get_consolidation_churn_limit`](#new-get_consolidation_churn_limit)
56-
- [New `get_active_balance`](#new-get_active_balance)
5756
- [New `get_pending_balance_to_withdraw`](#new-get_pending_balance_to_withdraw)
5857
- [Modified `get_attesting_indices`](#modified-get_attesting_indices)
5958
- [Modified `get_next_sync_committee_indices`](#modified-get_next_sync_committee_indices)
@@ -539,14 +538,6 @@ def get_consolidation_churn_limit(state: BeaconState) -> Gwei:
539538
return get_balance_churn_limit(state) - get_activation_exit_churn_limit(state)
540539
```
541540

542-
#### New `get_active_balance`
543-
544-
```python
545-
def get_active_balance(state: BeaconState, validator_index: ValidatorIndex) -> Gwei:
546-
max_effective_balance = get_max_effective_balance(state.validators[validator_index])
547-
return min(state.balances[validator_index], max_effective_balance)
548-
```
549-
550541
#### New `get_pending_balance_to_withdraw`
551542

552543
```python
@@ -884,10 +875,14 @@ def process_pending_consolidations(state: BeaconState) -> None:
884875

885876
# Churn any target excess active balance of target and raise its max
886877
switch_to_compounding_validator(state, pending_consolidation.target_index)
878+
879+
# Calculate the consolidated balance
880+
max_effective_balance = get_max_effective_balance(source_validator)
881+
source_effective_balance = min(state.balances[pending_consolidation.source_index], max_effective_balance)
882+
887883
# Move active balance to target. Excess balance is withdrawable.
888-
active_balance = get_active_balance(state, pending_consolidation.source_index)
889-
decrease_balance(state, pending_consolidation.source_index, active_balance)
890-
increase_balance(state, pending_consolidation.target_index, active_balance)
884+
decrease_balance(state, pending_consolidation.source_index, source_effective_balance)
885+
increase_balance(state, pending_consolidation.target_index, source_effective_balance)
891886
next_pending_consolidation += 1
892887

893888
state.pending_consolidations = state.pending_consolidations[next_pending_consolidation:]

0 commit comments

Comments
 (0)