Merge pull request #3769 from ethDreamer/fix_compute_proposer_index
Electra: Properly Calculate Proposer Probabilities
This commit is contained in:
commit
071f0a3097
|
@ -42,6 +42,7 @@
|
||||||
- [`BeaconState`](#beaconstate)
|
- [`BeaconState`](#beaconstate)
|
||||||
- [Helper functions](#helper-functions)
|
- [Helper functions](#helper-functions)
|
||||||
- [Predicates](#predicates)
|
- [Predicates](#predicates)
|
||||||
|
- [Updated `compute_proposer_index`](#updated-compute_proposer_index)
|
||||||
- [Updated `is_eligible_for_activation_queue`](#updated-is_eligible_for_activation_queue)
|
- [Updated `is_eligible_for_activation_queue`](#updated-is_eligible_for_activation_queue)
|
||||||
- [New `is_compounding_withdrawal_credential`](#new-is_compounding_withdrawal_credential)
|
- [New `is_compounding_withdrawal_credential`](#new-is_compounding_withdrawal_credential)
|
||||||
- [New `has_compounding_withdrawal_credential`](#new-has_compounding_withdrawal_credential)
|
- [New `has_compounding_withdrawal_credential`](#new-has_compounding_withdrawal_credential)
|
||||||
|
@ -438,6 +439,27 @@ class BeaconState(Container):
|
||||||
|
|
||||||
### Predicates
|
### Predicates
|
||||||
|
|
||||||
|
#### Updated `compute_proposer_index`
|
||||||
|
|
||||||
|
```python
|
||||||
|
def compute_proposer_index(state: BeaconState, indices: Sequence[ValidatorIndex], seed: Bytes32) -> ValidatorIndex:
|
||||||
|
"""
|
||||||
|
Return from ``indices`` a random index sampled by effective balance.
|
||||||
|
"""
|
||||||
|
assert len(indices) > 0
|
||||||
|
MAX_RANDOM_BYTE = 2**8 - 1
|
||||||
|
i = uint64(0)
|
||||||
|
total = uint64(len(indices))
|
||||||
|
while True:
|
||||||
|
candidate_index = indices[compute_shuffled_index(i % total, total, seed)]
|
||||||
|
random_byte = hash(seed + uint_to_bytes(uint64(i // 32)))[i % 32]
|
||||||
|
effective_balance = state.validators[candidate_index].effective_balance
|
||||||
|
# [Modified in Electra:EIP7251]
|
||||||
|
if effective_balance * MAX_RANDOM_BYTE >= MAX_EFFECTIVE_BALANCE_ELECTRA * random_byte:
|
||||||
|
return candidate_index
|
||||||
|
i += 1
|
||||||
|
```
|
||||||
|
|
||||||
#### Updated `is_eligible_for_activation_queue`
|
#### Updated `is_eligible_for_activation_queue`
|
||||||
|
|
||||||
```python
|
```python
|
||||||
|
|
Loading…
Reference in New Issue