Skip to content

Commit

Permalink
EIP-7251: Flatten get_active_balance
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ppopth committed Sep 29, 2024
1 parent 0c5ad81 commit fb486c8
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions specs/electra/beacon-chain.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:]
Expand Down

0 comments on commit fb486c8

Please sign in to comment.