Skip to content

Commit 85adbfb

Browse files
committed
Switch spec to MAX_EFFECTIVE_BALANCE_ELECTRA
1 parent 50972f9 commit 85adbfb

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

specs/electra/beacon-chain.md

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
- [New `get_active_balance`](#new-get_active_balance)
6060
- [New `get_pending_balance_to_withdraw`](#new-get_pending_balance_to_withdraw)
6161
- [Modified `get_attesting_indices`](#modified-get_attesting_indices)
62+
- [Modified `get_next_sync_committee_indices`](#modified-get_next_sync_committee_indices)
6263
- [Beacon state mutators](#beacon-state-mutators)
6364
- [Updated `initiate_validator_exit`](#updated--initiate_validator_exit)
6465
- [New `switch_to_compounding_validator`](#new-switch_to_compounding_validator)
@@ -441,6 +442,8 @@ class BeaconState(Container):
441442

442443
#### Updated `compute_proposer_index`
443444

445+
*Note*: The function is modified to use `MAX_EFFECTIVE_BALANCE_ELECTRA` preset.
446+
444447
```python
445448
def compute_proposer_index(state: BeaconState, indices: Sequence[ValidatorIndex], seed: Bytes32) -> ValidatorIndex:
446449
"""
@@ -624,6 +627,36 @@ def get_attesting_indices(state: BeaconState, attestation: Attestation) -> Set[V
624627
return output
625628
```
626629

630+
#### Modified `get_next_sync_committee_indices`
631+
632+
*Note*: The function is modified to use `MAX_EFFECTIVE_BALANCE_ELECTRA` preset.
633+
634+
```python
635+
def get_next_sync_committee_indices(state: BeaconState) -> Sequence[ValidatorIndex]:
636+
"""
637+
Return the sync committee indices, with possible duplicates, for the next sync committee.
638+
"""
639+
epoch = Epoch(get_current_epoch(state) + 1)
640+
641+
MAX_RANDOM_BYTE = 2**8 - 1
642+
active_validator_indices = get_active_validator_indices(state, epoch)
643+
active_validator_count = uint64(len(active_validator_indices))
644+
seed = get_seed(state, epoch, DOMAIN_SYNC_COMMITTEE)
645+
i = 0
646+
sync_committee_indices: List[ValidatorIndex] = []
647+
while len(sync_committee_indices) < SYNC_COMMITTEE_SIZE:
648+
shuffled_index = compute_shuffled_index(uint64(i % active_validator_count), active_validator_count, seed)
649+
candidate_index = active_validator_indices[shuffled_index]
650+
random_byte = hash(seed + uint_to_bytes(uint64(i // 32)))[i % 32]
651+
effective_balance = state.validators[candidate_index].effective_balance
652+
# [Modified in Electra:EIP7251]
653+
if effective_balance * MAX_RANDOM_BYTE >= MAX_EFFECTIVE_BALANCE_ELECTRA * random_byte:
654+
sync_committee_indices.append(candidate_index)
655+
i += 1
656+
return sync_committee_indices
657+
```
658+
659+
627660
### Beacon state mutators
628661

629662
#### Updated `initiate_validator_exit`
@@ -1409,8 +1442,8 @@ def initialize_beacon_state_from_eth1(eth1_block_hash: Hash32,
14091442
# Process activations
14101443
for index, validator in enumerate(state.validators):
14111444
balance = state.balances[index]
1412-
validator.effective_balance = min(balance - balance % EFFECTIVE_BALANCE_INCREMENT, MAX_EFFECTIVE_BALANCE)
1413-
if validator.effective_balance == MAX_EFFECTIVE_BALANCE:
1445+
validator.effective_balance = min(balance - balance % EFFECTIVE_BALANCE_INCREMENT, MAX_EFFECTIVE_BALANCE_ELECTRA)
1446+
if validator.effective_balance >= MIN_ACTIVATION_BALANCE:
14141447
validator.activation_eligibility_epoch = GENESIS_EPOCH
14151448
validator.activation_epoch = GENESIS_EPOCH
14161449

0 commit comments

Comments
 (0)