Skip to content

Commit e73b5d8

Browse files
committed
EIP-XXXX Stabilize next epoch proposer lookahead
1 parent ff99bc0 commit e73b5d8

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed

specs/electra/beacon-chain.md

+61
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@
5050
- [New `has_execution_withdrawal_credential`](#new-has_execution_withdrawal_credential)
5151
- [Modified `is_fully_withdrawable_validator`](#modified-is_fully_withdrawable_validator)
5252
- [Modified `is_partially_withdrawable_validator`](#modified-is_partially_withdrawable_validator)
53+
- [Modified `get_beacon_proposer_index`](#modified-get_beacon_proposer_index)
54+
- [New `compute_proposer_indices`](#new-compute_proposer_indices)
55+
- [New `compute_proposer_lookahead`](#new-compute_proposer_lookahead)
5356
- [Misc](#misc-1)
5457
- [New `get_committee_indices`](#new-get_committee_indices)
5558
- [New `get_max_effective_balance`](#new-get_max_effective_balance)
@@ -76,6 +79,7 @@
7679
- [New `process_pending_deposits`](#new-process_pending_deposits)
7780
- [New `process_pending_consolidations`](#new-process_pending_consolidations)
7881
- [Modified `process_effective_balance_updates`](#modified-process_effective_balance_updates)
82+
- [New `process_proposer_lookahead`](#new-process_proposer_lookahead)
7983
- [Execution engine](#execution-engine)
8084
- [Request data](#request-data)
8185
- [Modified `NewPayloadRequest`](#modified-newpayloadrequest)
@@ -420,6 +424,7 @@ class BeaconState(Container):
420424
# [New in Electra:EIP7251]
421425
pending_partial_withdrawals: List[PendingPartialWithdrawal, PENDING_PARTIAL_WITHDRAWALS_LIMIT]
422426
pending_consolidations: List[PendingConsolidation, PENDING_CONSOLIDATIONS_LIMIT] # [New in Electra:EIP7251]
427+
proposer_lookahead: List[ValidatorIndex, (MIN_SEED_LOOKAHEAD + 1) * SLOTS_PER_EPOCH] # [New in Electra:EIPXXXX]
423428
```
424429

425430
## Helper functions
@@ -529,6 +534,49 @@ def is_partially_withdrawable_validator(validator: Validator, balance: Gwei) ->
529534
)
530535
```
531536

537+
#### Modified `get_beacon_proposer_index`
538+
539+
*Note*: The function `get_beacon_proposer_index` is modified to use the pre-calculated `current_proposer_lookahead` instead of calculating it on-demand.
540+
541+
```python
542+
def get_beacon_proposer_index(state: BeaconState) -> ValidatorIndex:
543+
"""
544+
Return the beacon proposer index at the current slot.
545+
"""
546+
slot_offset = state.slot - compute_start_slot_at_epoch(get_current_epoch(state))
547+
return state.proposer_lookahead[slot_offset]
548+
```
549+
#### New `compute_proposer_indices`
550+
551+
```python
552+
def compute_proposer_indices(state: BeaconState, epoch: Epoch) -> List[ValidatorIndex, SLOTS_PER_EPOCH]:
553+
"""
554+
Return the proposer indices for the given ``epoch``.
555+
"""
556+
proposer_indices = []
557+
indices = get_active_validator_indices(state, epoch)
558+
start_slot = compute_start_slot_at_epoch(epoch)
559+
for slot in range(start_slot, start_slot + SLOTS_PER_EPOCH):
560+
seed = hash(get_seed(state, epoch, DOMAIN_BEACON_PROPOSER) + uint_to_bytes(Slot(slot)))
561+
proposer_indices.append(compute_proposer_index(state, indices, seed))
562+
return proposer_indices
563+
```
564+
565+
#### New `compute_proposer_lookahead`
566+
567+
```python
568+
def compute_proposer_lookahead(state: BeaconState) -> List[ValidatorIndex, (MIN_SEED_LOOKAHEAD + 1) * SLOTS_PER_EPOCH]:
569+
"""
570+
Return the proposer indices for the full available lookahead starting from current epoch.
571+
"""
572+
current_epoch = get_current_epoch(state)
573+
lookahead = []
574+
for i in range(MIN_SEED_LOOKAHEAD + 1):
575+
proposer_indices = compute_proposer_indices(state, Epoch(current_epoch + i))
576+
lookahead.extend(proposer_indices)
577+
return lookahead
578+
```
579+
532580
### Misc
533581

534582
#### New `get_committee_indices`
@@ -813,6 +861,7 @@ def process_epoch(state: BeaconState) -> None:
813861
process_historical_summaries_update(state)
814862
process_participation_flag_updates(state)
815863
process_sync_committee_updates(state)
864+
process_proposer_lookahead(state) # [New in Electra:EIPXXXX]
816865
```
817866

818867
#### Modified `process_registry_updates`
@@ -1002,6 +1051,18 @@ def process_effective_balance_updates(state: BeaconState) -> None:
10021051
validator.effective_balance = min(balance - balance % EFFECTIVE_BALANCE_INCREMENT, max_effective_balance)
10031052
```
10041053

1054+
#### New `process_proposer_lookahead`
1055+
1056+
```python
1057+
def process_proposer_lookahead(state: BeaconState) -> None:
1058+
last_epoch_start = len(state.proposer_lookahead) - SLOTS_PER_EPOCH
1059+
# Shift out proposers in the first epoch.
1060+
state.proposer_lookahead[0:last_epoch_start] = state.proposer_lookahead[SLOTS_PER_EPOCH:]
1061+
# Fill in the last epoch with new proposer indices.
1062+
last_epoch_proposers = compute_proposer_indices(state, Epoch(get_current_epoch(state) + MIN_SEED_LOOKAHEAD))
1063+
state.proposer_lookahead[last_epoch_start:] = last_epoch_proposers
1064+
```
1065+
10051066
### Execution engine
10061067

10071068
#### Request data

specs/electra/fork.md

+2
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ def upgrade_to_electra(pre: deneb.BeaconState) -> BeaconState:
139139
pending_deposits=[],
140140
pending_partial_withdrawals=[],
141141
pending_consolidations=[],
142+
# [New in Electra:EIPXXXX]
143+
proposer_lookahead=compute_proposer_lookahead(pre)
142144
)
143145

144146
post.exit_balance_to_consume = get_activation_exit_churn_limit(post)

tests/core/pyspec/eth2spec/test/helpers/genesis.py

+2
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ def create_genesis_state(spec, validator_balances, activation_threshold):
176176

177177
if is_post_electra(spec):
178178
state.deposit_requests_start_index = spec.UNSET_DEPOSIT_REQUESTS_START_INDEX
179+
# Initialize proposer lookahead list
180+
state.proposer_lookahead = spec.compute_proposer_lookahead(state)
179181

180182
if is_post_eip7441(spec):
181183
vc = len(state.validators)

0 commit comments

Comments
 (0)