mirror of
https://github.com/status-im/eth2.0-specs.git
synced 2025-01-12 19:54:34 +00:00
Merge pull request #44 from ethereum/fix-recent_block_hashes
Fix `recent_block_hashes`
This commit is contained in:
commit
f3ea9bf43c
@ -177,7 +177,7 @@ The `ActiveState` has the following fields:
|
||||
'pending_attestations': [AttestationRecord],
|
||||
# Specials not yet been processed
|
||||
'pending_specials': [SpecialRecord]
|
||||
# Most recent 2 * CYCLE_LENGTH block hashes, older to newer
|
||||
# recent block hashes needed to process attestations, older to newer
|
||||
'recent_block_hashes': ['hash32'],
|
||||
# RANDAO state
|
||||
'randao_mix': 'hash32'
|
||||
@ -454,8 +454,8 @@ def get_shards_and_committees_for_slot(crystallized_state: CrystallizedState,
|
||||
def get_block_hash(active_state: ActiveState,
|
||||
current_block: BeaconBlock,
|
||||
slot: int) -> Hash32:
|
||||
earliest_slot_in_array = current_block.slot - CYCLE_LENGTH * 2
|
||||
assert earliest_slot_in_array <= slot < earliest_slot_in_array + CYCLE_LENGTH * 2
|
||||
earliest_slot_in_array = current_block.slot - len(active_state.recent_block_hashes)
|
||||
assert earliest_slot_in_array <= slot < current_block.slot
|
||||
return active_state.recent_block_hashes[slot - earliest_slot_in_array]
|
||||
```
|
||||
|
||||
@ -605,15 +605,15 @@ This procedure should be carried out every block.
|
||||
First, set `recent_block_hashes` to the output of the following, where `parent_hash` is the hash of the immediate previous block (ie. must be equal to `ancestor_hashes[0]`):
|
||||
|
||||
```python
|
||||
def get_new_recent_block_hashes(old_block_hashes: List[Hash32],
|
||||
parent_slot: int,
|
||||
current_slot: int,
|
||||
parent_hash: Hash32) -> List[Hash32]:
|
||||
def append_to_recent_block_hashes(old_block_hashes: List[Hash32],
|
||||
parent_slot: int,
|
||||
current_slot: int,
|
||||
parent_hash: Hash32) -> List[Hash32]:
|
||||
d = current_slot - parent_slot
|
||||
return old_block_hashes[d:] + [parent_hash] * min(d, len(old_block_hashes))
|
||||
return old_block_hashes + [parent_hash] * d
|
||||
```
|
||||
|
||||
The output of `get_block_hash` should not change, except that it will no longer throw for `current_slot - 1`, and will now throw for `current_slot - CYCLE_LENGTH * 2 - 1`. Also, check that the block's `ancestor_hashes` array was correctly updated, using the following algorithm:
|
||||
The output of `get_block_hash` should not change, except that it will no longer throw for `current_slot - 1`. Also, check that the block's `ancestor_hashes` array was correctly updated, using the following algorithm:
|
||||
|
||||
```python
|
||||
def update_ancestor_hashes(parent_ancestor_hashes: List[Hash32],
|
||||
@ -716,6 +716,7 @@ For each `SpecialRecord` `obj` in `active_state.pending_specials`:
|
||||
* Set `crystallized_state.last_state_recalculation_slot += CYCLE_LENGTH`
|
||||
* Remove all attestation records older than slot `crystallized_state.last_state_recalculation_slot`
|
||||
* Empty the `active_state.pending_specials` list
|
||||
* Set `active_state.recent_block_hashes = active_state.recent_block_hashes[CYCLE_LENGTH:]`
|
||||
* Set `shard_and_committee_for_slots[:CYCLE_LENGTH] = shard_and_committee_for_slots[CYCLE_LENGTH:]`
|
||||
|
||||
### Validator set change
|
||||
|
Loading…
x
Reference in New Issue
Block a user