Merge branch 'master' into JustinDrake-patch-3

This commit is contained in:
Danny Ryan 2018-11-04 23:22:11 +01:00
commit 41105c28d0
No known key found for this signature in database
GPG Key ID: 2765A792E42CE07A
2 changed files with 23 additions and 7 deletions

View File

@ -147,7 +147,7 @@ An `AttestationSignedData` has the following fields:
'slot': 'uint64', 'slot': 'uint64',
# Shard number # Shard number
'shard': 'uint16', 'shard': 'uint16',
# 31 parent hashes # CYCLE_LENGTH parent hashes
'parent_hashes': ['hash32'], 'parent_hashes': ['hash32'],
# Shard block hash # Shard block hash
'shard_block_hash': 'hash32', 'shard_block_hash': 'hash32',
@ -498,7 +498,8 @@ def on_startup(initial_validator_entries: List[Any]) -> Tuple[CrystallizedState,
withdrawal_shard=withdrawal_shard, withdrawal_shard=withdrawal_shard,
withdrawal_address=withdrawal_address, withdrawal_address=withdrawal_address,
randao_commitment=randao_commitment, randao_commitment=randao_commitment,
current_slot=0 current_slot=0,
status=ACTIVE,
) )
# Setup crystallized state # Setup crystallized state
x = get_new_shuffling(bytes([0] * 32), validators, 0) x = get_new_shuffling(bytes([0] * 32), validators, 0)
@ -545,7 +546,19 @@ The `CrystallizedState()` and `ActiveState()` constructors should initialize all
### Routine for adding a validator ### Routine for adding a validator
This routine should be run for every validator that is inducted as part of a log created on the PoW chain [TODO: explain where to check for these logs]. These logs should be processed in the order in which they are emitted by the PoW chain. Define `min_empty_validator(validators)` as a function that returns the lowest validator index `i` such that `validators[i].status == WITHDRAWN`, otherwise `None`. This routine should be run for every validator that is inducted as part of a log created on the PoW chain [TODO: explain where to check for these logs]. The status of the validators added after genesis is `PENDING_ACTIVATION`. These logs should be processed in the order in which they are emitted by the PoW chain.
First, a helper function:
```python
def min_empty_validator(validators: List[ValidatorRecord]):
for i, v in enumerate(validators):
if v.status == WITHDRAWN:
return i
return None
```
Now, to add a validator:
```python ```python
def add_validator(validators: List[ValidatorRecord], def add_validator(validators: List[ValidatorRecord],
@ -554,6 +567,7 @@ def add_validator(validators: List[ValidatorRecord],
withdrawal_shard: int, withdrawal_shard: int,
withdrawal_address: Address, withdrawal_address: Address,
randao_commitment: Hash32, randao_commitment: Hash32,
status: int,
current_slot: int) -> int: current_slot: int) -> int:
# if following assert fails, validator induction failed # if following assert fails, validator induction failed
# move on to next validator registration log # move on to next validator registration log
@ -566,8 +580,8 @@ def add_validator(validators: List[ValidatorRecord],
withdrawal_address=withdrawal_address, withdrawal_address=withdrawal_address,
randao_commitment=randao_commitment, randao_commitment=randao_commitment,
randao_last_change=current_slot, randao_last_change=current_slot,
balance=DEPOSIT_SIZE * GWEI_PER_ETH, balance=DEPOSIT_SIZE * GWEI_PER_ETH, # in Gwei
status=PENDING_ACTIVATION, status=status,
exit_slot=0 exit_slot=0
) )
index = min_empty_validator(validators) index = min_empty_validator(validators)
@ -665,7 +679,7 @@ For every `(shard, shard_block_hash)` tuple:
* Let `total_balance_attesting_to_h` be the total balance of validators that attested to the shard block with hash `shard_block_hash`. * Let `total_balance_attesting_to_h` be the total balance of validators that attested to the shard block with hash `shard_block_hash`.
* Let `total_committee_balance` be the total balance in the committee of validators that could have attested to the shard block with hash `shard_block_hash`. * Let `total_committee_balance` be the total balance in the committee of validators that could have attested to the shard block with hash `shard_block_hash`.
* If `3 * total_balance_attesting_to_h >= 2 * total_committee_balance` and `recently_changed is False`, set `crosslinks[shard] = CrosslinkRecord(recently_changed=True, slot=block.last_state_recalculation_slot + CYCLE_LENGTH, hash=shard_block_hash)`. * If `3 * total_balance_attesting_to_h >= 2 * total_committee_balance` and `recently_changed is False`, set `crosslinks[shard] = CrosslinkRecord(recently_changed=True, slot=last_state_recalculation_slot + CYCLE_LENGTH, hash=shard_block_hash)`.
#### Balance recalculations related to FFG rewards #### Balance recalculations related to FFG rewards

View File

@ -186,6 +186,8 @@ return byte_length + value
#### List/Vectors #### List/Vectors
Lists are a collection of elements of the same homogeneous type.
| Check to perform | Code | | Check to perform | Code |
|:--------------------------------------------|:----------------------------| |:--------------------------------------------|:----------------------------|
| Length of serialized list fits into 4 bytes | ``len(serialized) < 2**32`` | | Length of serialized list fits into 4 bytes | ``len(serialized) < 2**32`` |
@ -327,7 +329,7 @@ return rawbytes[bytes_start:bytes_end], new_index
#### List/Vectors #### List/Vectors
Deserialize each object in the list. Deserialize each element in the list.
1. Get the length of the serialized list. 1. Get the length of the serialized list.
2. Loop through deserializing each item in the list until you reach the 2. Loop through deserializing each item in the list until you reach the
entire length of the list. entire length of the list.