Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EIP-7251: Flatten get_active_balance #3949

Merged
merged 1 commit into from
Sep 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
source_effective_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, source_effective_balance)
increase_balance(state, pending_consolidation.target_index, source_effective_balance)
next_pending_consolidation += 1

state.pending_consolidations = state.pending_consolidations[next_pending_consolidation:]
Expand Down