Keep randao mixes in the state
Response to #295 Also a simplification, as two special cases get replaced: `state.randao_mix` -> `state.latest_randao_mixes[-1]`, and `state.next_seed` -> `state.latest_randao_mixes[-CYCLE_LENGTH-1]`.
This commit is contained in:
parent
6c6fcef0c2
commit
425f7d51c9
|
@ -459,8 +459,7 @@ Unless otherwise indicated, code appearing in `this style` is to be interpreted
|
||||||
'validator_registry_delta_chain_tip': 'hash32', # For light clients to track deltas
|
'validator_registry_delta_chain_tip': 'hash32', # For light clients to track deltas
|
||||||
|
|
||||||
# Randomness and committees
|
# Randomness and committees
|
||||||
'randao_mix': 'hash32',
|
'latest_randao_mixes': ['hash32'],
|
||||||
'next_seed': 'hash32',
|
|
||||||
'shard_committees_at_slots': [[ShardCommittee]],
|
'shard_committees_at_slots': [[ShardCommittee]],
|
||||||
'persistent_committees': [['uint24']],
|
'persistent_committees': [['uint24']],
|
||||||
'persistent_committee_reassignments': [ShardReassignmentRecord],
|
'persistent_committee_reassignments': [ShardReassignmentRecord],
|
||||||
|
@ -1154,8 +1153,7 @@ def get_initial_beacon_state(initial_validator_deposits: List[Deposit],
|
||||||
validator_registry_delta_chain_tip=ZERO_HASH,
|
validator_registry_delta_chain_tip=ZERO_HASH,
|
||||||
|
|
||||||
# Randomness and committees
|
# Randomness and committees
|
||||||
randao_mix=ZERO_HASH,
|
latest_randao_mixes=[ZERO_HASH for _ in range(LATEST_BLOCK_ROOTS_LENGTH)],
|
||||||
next_seed=ZERO_HASH,
|
|
||||||
shard_committees_at_slots=[],
|
shard_committees_at_slots=[],
|
||||||
persistent_committees=[],
|
persistent_committees=[],
|
||||||
persistent_committee_reassignments=[],
|
persistent_committee_reassignments=[],
|
||||||
|
@ -1415,7 +1413,7 @@ Below are the processing steps that happen at every `block`.
|
||||||
* Let `repeat_hash(x, n) = x if n == 0 else repeat_hash(hash(x), n-1)`.
|
* Let `repeat_hash(x, n) = x if n == 0 else repeat_hash(hash(x), n-1)`.
|
||||||
* Let `proposer = state.validator_registry[get_beacon_proposer_index(state, state.slot)]`.
|
* Let `proposer = state.validator_registry[get_beacon_proposer_index(state, state.slot)]`.
|
||||||
* Verify that `repeat_hash(block.randao_reveal, proposer.randao_layers) == proposer.randao_commitment`.
|
* Verify that `repeat_hash(block.randao_reveal, proposer.randao_layers) == proposer.randao_commitment`.
|
||||||
* Set `state.randao_mix = xor(state.randao_mix, block.randao_reveal)`.
|
* Set `state.latest_randao_mixes = state.latest_randao_mixes[1:] + [xor(state.latest_randao_mixes[-1], block.randao_reveal)]
|
||||||
* Set `proposer.randao_commitment = block.randao_reveal`.
|
* Set `proposer.randao_commitment = block.randao_reveal`.
|
||||||
* Set `proposer.randao_layers = 0`.
|
* Set `proposer.randao_layers = 0`.
|
||||||
|
|
||||||
|
@ -1749,15 +1747,14 @@ Also perform the following updates:
|
||||||
|
|
||||||
* Set `state.validator_registry_latest_change_slot = state.slot`.
|
* Set `state.validator_registry_latest_change_slot = state.slot`.
|
||||||
* Set `state.shard_committees_at_slots[:EPOCH_LENGTH] = state.shard_committees_at_slots[EPOCH_LENGTH:]`.
|
* Set `state.shard_committees_at_slots[:EPOCH_LENGTH] = state.shard_committees_at_slots[EPOCH_LENGTH:]`.
|
||||||
* Set `state.shard_committees_at_slots[EPOCH_LENGTH:] = get_new_shuffling(state.next_seed, state.validator_registry, next_start_shard)` where `next_start_shard = (state.shard_committees_at_slots[-1][-1].shard + 1) % SHARD_COUNT`.
|
* Set `state.shard_committees_at_slots[EPOCH_LENGTH:] = get_new_shuffling(state.latest_randao_mixes[-CYCLE_LENGTH-1], state.validator_registry, next_start_shard)` where `next_start_shard = (state.shard_committees_at_slots[-1][-1].shard + 1) % SHARD_COUNT`.
|
||||||
* Set `state.next_seed = state.randao_mix`.
|
|
||||||
|
|
||||||
If a validator registry update does _not_ happen do the following:
|
If a validator registry update does _not_ happen do the following:
|
||||||
|
|
||||||
* Set `state.shard_committees_at_slots[:EPOCH_LENGTH] = state.shard_committees_at_slots[EPOCH_LENGTH:]`.
|
* Set `state.shard_committees_at_slots[:EPOCH_LENGTH] = state.shard_committees_at_slots[EPOCH_LENGTH:]`.
|
||||||
* Let `slots_since_finality = state.slot - state.validator_registry_latest_change_slot`.
|
* Let `slots_since_finality = state.slot - state.validator_registry_latest_change_slot`.
|
||||||
* Let `start_shard = state.shard_committees_at_slots[0][0].shard`.
|
* Let `start_shard = state.shard_committees_at_slots[0][0].shard`.
|
||||||
* If `slots_since_finality * EPOCH_LENGTH <= MIN_VALIDATOR_REGISTRY_CHANGE_INTERVAL` or `slots_since_finality` is an exact power of 2, set `state.shard_committees_at_slots[EPOCH_LENGTH:] = get_new_shuffling(state.next_seed, state.validator_registry, start_shard)` and set `state.next_seed = state.randao_mix`. Note that `start_shard` is not changed from the last epoch.
|
* If `slots_since_finality * EPOCH_LENGTH <= MIN_VALIDATOR_REGISTRY_CHANGE_INTERVAL` or `slots_since_finality` is an exact power of 2, set `state.shard_committees_at_slots[EPOCH_LENGTH:] = get_new_shuffling(state.latest_randao_mixes[-CYCLE_LENGTH-1], state.validator_registry, start_shard)`. Note that `start_shard` is not changed from the last epoch.
|
||||||
|
|
||||||
### Proposer reshuffling
|
### Proposer reshuffling
|
||||||
|
|
||||||
|
@ -1769,8 +1766,8 @@ num_validators_to_reshuffle = len(active_validator_indices) // SHARD_PERSISTENT_
|
||||||
for i in range(num_validators_to_reshuffle):
|
for i in range(num_validators_to_reshuffle):
|
||||||
# Multiplying i to 2 to ensure we have different input to all the required hashes in the shuffling
|
# Multiplying i to 2 to ensure we have different input to all the required hashes in the shuffling
|
||||||
# and none of the hashes used for entropy in this loop will be the same
|
# and none of the hashes used for entropy in this loop will be the same
|
||||||
validator_index = active_validator_indices[hash(state.randao_mix + bytes8(i * 2)) % len(active_validator_indices)]
|
validator_index = active_validator_indices[hash(state.latest_randao_mixes[-1] + bytes8(i * 2)) % len(active_validator_indices)]
|
||||||
new_shard = hash(state.randao_mix + bytes8(i * 2 + 1)) % SHARD_COUNT
|
new_shard = hash(state.latest_randao_mixes[-1] + bytes8(i * 2 + 1)) % SHARD_COUNT
|
||||||
shard_reassignment_record = ShardReassignmentRecord(
|
shard_reassignment_record = ShardReassignmentRecord(
|
||||||
validator_index=validator_index,
|
validator_index=validator_index,
|
||||||
shard=new_shard,
|
shard=new_shard,
|
||||||
|
|
Loading…
Reference in New Issue