Merge pull request #1013 from terencechain/patch-69
Generate seed once for get_beacon_proposer_index
This commit is contained in:
commit
a25103cefd
|
@ -928,10 +928,11 @@ def get_beacon_proposer_index(state: BeaconState) -> ValidatorIndex:
|
||||||
current_epoch = get_current_epoch(state)
|
current_epoch = get_current_epoch(state)
|
||||||
first_committee, _ = get_crosslink_committees_at_slot(state, state.slot)[0]
|
first_committee, _ = get_crosslink_committees_at_slot(state, state.slot)[0]
|
||||||
MAX_RANDOM_BYTE = 2**8 - 1
|
MAX_RANDOM_BYTE = 2**8 - 1
|
||||||
|
seed = generate_seed(state, current_epoch)
|
||||||
i = 0
|
i = 0
|
||||||
while True:
|
while True:
|
||||||
candidate_index = first_committee[(current_epoch + i) % len(first_committee)]
|
candidate_index = first_committee[(current_epoch + i) % len(first_committee)]
|
||||||
random_byte = hash(generate_seed(state, current_epoch) + int_to_bytes8(i // 32))[i % 32]
|
random_byte = hash(seed + int_to_bytes8(i // 32))[i % 32]
|
||||||
effective_balance = state.validator_registry[candidate_index].effective_balance
|
effective_balance = state.validator_registry[candidate_index].effective_balance
|
||||||
if effective_balance * MAX_RANDOM_BYTE >= MAX_EFFECTIVE_BALANCE * random_byte:
|
if effective_balance * MAX_RANDOM_BYTE >= MAX_EFFECTIVE_BALANCE * random_byte:
|
||||||
return candidate_index
|
return candidate_index
|
||||||
|
|
Loading…
Reference in New Issue