Improve beacon proposer selection logic
This commit is contained in:
parent
c6d206e581
commit
df6e531d74
|
@ -934,15 +934,12 @@ def get_beacon_proposer_index(state: BeaconState) -> ValidatorIndex:
|
|||
Return the beacon proposer index at the current slot.
|
||||
"""
|
||||
epoch = get_current_epoch(state)
|
||||
committees_per_slot = get_committee_count(state, epoch) // SLOTS_PER_EPOCH
|
||||
offset = committees_per_slot * (state.slot % SLOTS_PER_EPOCH)
|
||||
shard = Shard((get_start_shard(state, epoch) + offset) % SHARD_COUNT)
|
||||
first_committee = get_crosslink_committee(state, epoch, shard)
|
||||
indices = get_active_validator_indices(state, epoch)
|
||||
seed = hash(get_seed(state, epoch) + int_to_bytes(state.slot, length=8))
|
||||
MAX_RANDOM_BYTE = 2**8 - 1
|
||||
seed = get_seed(state, epoch)
|
||||
i = 0
|
||||
while True:
|
||||
candidate_index = first_committee[(epoch + i) % len(first_committee)]
|
||||
candidate_index = indices[compute_shuffled_index(ValidatorIndex(i % len(indices)), len(indices), seed)]
|
||||
random_byte = hash(seed + int_to_bytes(i // 32, length=8))[i % 32]
|
||||
effective_balance = state.validators[candidate_index].effective_balance
|
||||
if effective_balance * MAX_RANDOM_BYTE >= MAX_EFFECTIVE_BALANCE * random_byte:
|
||||
|
@ -1608,9 +1605,8 @@ def process_operations(state: BeaconState, body: BeaconBlockBody) -> None:
|
|||
```python
|
||||
def process_proposer_slashing(state: BeaconState, proposer_slashing: ProposerSlashing) -> None:
|
||||
proposer = state.validators[proposer_slashing.proposer_index]
|
||||
# Verify that the epoch is the same
|
||||
assert (compute_epoch_of_slot(proposer_slashing.header_1.slot)
|
||||
== compute_epoch_of_slot(proposer_slashing.header_2.slot))
|
||||
# Verify slots match
|
||||
assert proposer_slashing.header_1.slot == proposer_slashing.header_2.slot
|
||||
# But the headers are different
|
||||
assert proposer_slashing.header_1 != proposer_slashing.header_2
|
||||
# Check proposer is slashable
|
||||
|
|
|
@ -18,7 +18,6 @@ def get_valid_proposer_slashing(spec, state, signed_1=False, signed_2=False):
|
|||
)
|
||||
header_2 = deepcopy(header_1)
|
||||
header_2.parent_root = b'\x99' * 32
|
||||
header_2.slot = slot + 1
|
||||
|
||||
if signed_1:
|
||||
sign_block_header(spec, state, header_1, privkey)
|
||||
|
|
Loading…
Reference in New Issue