|
50 | 50 | - [New `has_execution_withdrawal_credential`](#new-has_execution_withdrawal_credential)
|
51 | 51 | - [Modified `is_fully_withdrawable_validator`](#modified-is_fully_withdrawable_validator)
|
52 | 52 | - [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) |
53 | 56 | - [Misc](#misc-1)
|
54 | 57 | - [New `get_committee_indices`](#new-get_committee_indices)
|
55 | 58 | - [New `get_max_effective_balance`](#new-get_max_effective_balance)
|
|
76 | 79 | - [New `process_pending_deposits`](#new-process_pending_deposits)
|
77 | 80 | - [New `process_pending_consolidations`](#new-process_pending_consolidations)
|
78 | 81 | - [Modified `process_effective_balance_updates`](#modified-process_effective_balance_updates)
|
| 82 | + - [New `process_proposer_lookahead`](#new-process_proposer_lookahead) |
79 | 83 | - [Execution engine](#execution-engine)
|
80 | 84 | - [Request data](#request-data)
|
81 | 85 | - [Modified `NewPayloadRequest`](#modified-newpayloadrequest)
|
@@ -420,6 +424,7 @@ class BeaconState(Container):
|
420 | 424 | # [New in Electra:EIP7251]
|
421 | 425 | pending_partial_withdrawals: List[PendingPartialWithdrawal, PENDING_PARTIAL_WITHDRAWALS_LIMIT]
|
422 | 426 | 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] |
423 | 428 | ```
|
424 | 429 |
|
425 | 430 | ## Helper functions
|
@@ -529,6 +534,49 @@ def is_partially_withdrawable_validator(validator: Validator, balance: Gwei) ->
|
529 | 534 | )
|
530 | 535 | ```
|
531 | 536 |
|
| 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 | + |
532 | 580 | ### Misc
|
533 | 581 |
|
534 | 582 | #### New `get_committee_indices`
|
@@ -813,6 +861,7 @@ def process_epoch(state: BeaconState) -> None:
|
813 | 861 | process_historical_summaries_update(state)
|
814 | 862 | process_participation_flag_updates(state)
|
815 | 863 | process_sync_committee_updates(state)
|
| 864 | + process_proposer_lookahead(state) # [New in Electra:EIPXXXX] |
816 | 865 | ```
|
817 | 866 |
|
818 | 867 | #### Modified `process_registry_updates`
|
@@ -1002,6 +1051,18 @@ def process_effective_balance_updates(state: BeaconState) -> None:
|
1002 | 1051 | validator.effective_balance = min(balance - balance % EFFECTIVE_BALANCE_INCREMENT, max_effective_balance)
|
1003 | 1052 | ```
|
1004 | 1053 |
|
| 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 | + |
1005 | 1066 | ### Execution engine
|
1006 | 1067 |
|
1007 | 1068 | #### Request data
|
|
0 commit comments