Added RANDAO support (without multi-skip mechanism)

This commit is contained in:
Vitalik Buterin 2018-10-03 10:29:00 -04:00
parent ef5d54cda0
commit e7ff5ad5e7
No known key found for this signature in database
GPG Key ID: A99D082A6179F987
1 changed files with 8 additions and 4 deletions

View File

@ -90,7 +90,7 @@ fields = {
# Hash of the crystallized state # Hash of the crystallized state
'crystallized_state_root': 'hash32', 'crystallized_state_root': 'hash32',
# Logouts, penalties, etc etc # Logouts, penalties, etc etc
'specials': [SpecialObject] 'specials': [SpecialObject],
} }
``` ```
@ -139,7 +139,9 @@ fields = {
# Special objects that have not yet been processed # Special objects that have not yet been processed
'pending_specials': [SpecialObject], 'pending_specials': [SpecialObject],
# Most recent 2 * CYCLE_LENGTH block hashes, older to newer # Most recent 2 * CYCLE_LENGTH block hashes, older to newer
'recent_block_hashes': ['hash32'] 'recent_block_hashes': ['hash32'],
# RANDAO state
'randao_mix': 'hash32'
} }
``` ```
@ -459,7 +461,9 @@ For each one of these attestations:
Extend the list of `AttestationRecord` objects in the `active_state` with those included in the block, ordering the new additions in the same order as they came in the block. Similarly extend the list of `SpecialObject` objects in the `active_state` with those included in the block. Extend the list of `AttestationRecord` objects in the `active_state` with those included in the block, ordering the new additions in the same order as they came in the block. Similarly extend the list of `SpecialObject` objects in the `active_state` with those included in the block.
Verify that the `parent.slot % len(get_shards_and_committees_for_slot(crystallized_state, parent.slot)[0].committee)`'th attester in `get_shards_and_committees_for_slot(crystallized_state, parent.slot)[0]` is part of the first (ie. item 0 in the array) `AttestationRecord` object; this attester can be considered to be the proposer of the parent block. In general, when a block is produced, it is broadcasted at the network layer along with the attestation from its proposer. Let `proposer_index` be the validator index of the `parent.slot % len(get_shards_and_committees_for_slot(crystallized_state, parent.slot)[0].committee)`'th attester in `get_shards_and_committees_for_slot(crystallized_state, parent.slot)[0]`. Verify that an attestation from this validator is part of the first (ie. item 0 in the array) `AttestationRecord` object; this attester can be considered to be the proposer of the parent block. In general, when a block is produced, it is broadcasted at the network layer along with the attestation from its proposer.
Additionally, verify that `hash(block.randao_reveal) == crystallized_state.validators[proposer_index].randao_commitment`, and set `active_state.randao_mix = xor(active_state.randao_mix, block.randao_reveal)` and `crystallized_state.validators[proposer_index].randao_commitment = block.randao_reveal`.
### State recalculations (every `CYCLE_LENGTH` slots) ### State recalculations (every `CYCLE_LENGTH` slots)
@ -579,7 +583,7 @@ Finally:
* Set `last_dynasty_start = crystallized_state.last_state_recalculation` * Set `last_dynasty_start = crystallized_state.last_state_recalculation`
* Set `crystallized_state.current_dynasty += 1` * Set `crystallized_state.current_dynasty += 1`
* Let `next_start_shard = (shard_and_committee_for_slots[-1][-1].shard_id + 1) % SHARD_COUNT` * Let `next_start_shard = (shard_and_committee_for_slots[-1][-1].shard_id + 1) % SHARD_COUNT`
* Set `shard_and_committee_for_slots[CYCLE_LENGTH:] = get_new_shuffling(block.ancestor_hashes[0], validators, next_start_shard)` * Set `shard_and_committee_for_slots[CYCLE_LENGTH:] = get_new_shuffling(active_state.randao_mix, validators, next_start_shard)`
------- -------