|
59 | 59 | - [New `get_active_balance`](#new-get_active_balance) |
60 | 60 | - [New `get_pending_balance_to_withdraw`](#new-get_pending_balance_to_withdraw) |
61 | 61 | - [Modified `get_attesting_indices`](#modified-get_attesting_indices) |
| 62 | + - [Modified `get_next_sync_committee_indices`](#modified-get_next_sync_committee_indices) |
62 | 63 | - [Beacon state mutators](#beacon-state-mutators) |
63 | 64 | - [Updated `initiate_validator_exit`](#updated--initiate_validator_exit) |
64 | 65 | - [New `switch_to_compounding_validator`](#new-switch_to_compounding_validator) |
@@ -441,6 +442,8 @@ class BeaconState(Container): |
441 | 442 |
|
442 | 443 | #### Updated `compute_proposer_index` |
443 | 444 |
|
| 445 | +*Note*: The function is modified to use `MAX_EFFECTIVE_BALANCE_ELECTRA` preset. |
| 446 | + |
444 | 447 | ```python |
445 | 448 | def compute_proposer_index(state: BeaconState, indices: Sequence[ValidatorIndex], seed: Bytes32) -> ValidatorIndex: |
446 | 449 | """ |
@@ -624,6 +627,36 @@ def get_attesting_indices(state: BeaconState, attestation: Attestation) -> Set[V |
624 | 627 | return output |
625 | 628 | ``` |
626 | 629 |
|
| 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 | + |
627 | 660 | ### Beacon state mutators |
628 | 661 |
|
629 | 662 | #### Updated `initiate_validator_exit` |
@@ -1409,8 +1442,8 @@ def initialize_beacon_state_from_eth1(eth1_block_hash: Hash32, |
1409 | 1442 | # Process activations |
1410 | 1443 | for index, validator in enumerate(state.validators): |
1411 | 1444 | 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: |
1414 | 1447 | validator.activation_eligibility_epoch = GENESIS_EPOCH |
1415 | 1448 | validator.activation_epoch = GENESIS_EPOCH |
1416 | 1449 |
|
|
0 commit comments