Adds review suggestions I missed

This commit is contained in:
Carl Beekhuizen 2019-06-06 11:39:22 +02:00
parent 4c1b9ef6d6
commit 35c03c5f3e
No known key found for this signature in database
GPG Key ID: D05CA176D0020646
4 changed files with 19 additions and 21 deletions

View File

@ -7,6 +7,6 @@ phase0: 67108864
# phase0_funny_fork_name: 67116000
# Example 2:
# Should be equal to PHASE_1_GENESIS_EPOCH
# Should be equal to PHASE_1_FORK_EPOCH
# (placeholder in example value here)
# phase1: 67163000

View File

@ -372,7 +372,7 @@ def process_custody_key_reveal(state: BeaconState,
# Reward Block Preposer
proposer_index = get_beacon_proposer_index(state)
increase_balance(state, proposer_index, get_base_reward(state, proposer_index) // MINOR_REWARD_QUOTIENT)
increase_balance(state, proposer_index, get_base_reward(state, reveal.revealer_index) // MINOR_REWARD_QUOTIENT)
```
#### Early derived secret reveals
@ -462,7 +462,7 @@ For each `challenge` in `block.body.custody_chunk_challenges`, run the following
def process_chunk_challenge(state: BeaconState,
challenge: CustodyChunkChallenge) -> None:
# Verify the attestation
assert validate_indexed_attestation(state, convert_to_indexed(state, challenge.attestation))
validate_indexed_attestation(state, convert_to_indexed(state, challenge.attestation))
# Verify it is not too late to challenge
assert slot_to_epoch(challenge.attestation.data.slot) >= get_current_epoch(state) - MAX_CHUNK_CHALLENGE_DELAY
responder = state.validator_registry[challenge.responder_index]
@ -517,14 +517,15 @@ def process_bit_challenge(state: BeaconState,
assert is_slashable_validator(challenger, get_current_epoch(state))
# Verify the attestation
assert validate_indexed_attestation(state, convert_to_indexed(state, challenge.attestation))
attestation = challenge.attestation
validate_indexed_attestation(state, convert_to_indexed(state, attestation))
# Verify the attestation is eligible for challenging
responder = state.validator_registry[challenge.responder_index]
assert (slot_to_epoch(challenge.attestation.data.slot) + responder.max_reveal_lateness <=
assert (slot_to_epoch(attestation.data.slot) + responder.max_reveal_lateness <=
get_validators_custody_reveal_period(state, challenge.responder_index))
# Verify the responder participated in the attestation
attesters = get_attesting_indices(state, challenge.attestation.data, challenge.attestation.aggregation_bitfield)
attesters = get_attesting_indices(state, attestation.data, attestation.aggregation_bitfield)
assert challenge.responder_index in attesters
# A validator can be the challenger for at most one challenge at a time
@ -536,7 +537,7 @@ def process_bit_challenge(state: BeaconState,
get_validators_custody_reveal_period(
state=state,
index=challenge.responder_index,
epoch=slot_to_epoch(challenge.attestation.data.slot)),
epoch=slot_to_epoch(attestation.data.slot)),
challenge.responder_index
)
assert bls_verify(
@ -551,10 +552,10 @@ def process_bit_challenge(state: BeaconState,
)
# Verify the chunk count
chunk_count = get_custody_chunk_count(challenge.attestation.data.crosslink)
chunk_count = get_custody_chunk_count(attestation.data.crosslink)
assert verify_bitfield(challenge.chunk_bits, chunk_count)
# Verify the first bit of the hash of the chunk bits does not equal the custody bit
custody_bit = get_bitfield_bit(challenge.attestation.custody_bitfield, attesters.index(challenge.responder_index))
custody_bit = get_bitfield_bit(attestation.custody_bitfield, attesters.index(challenge.responder_index))
assert custody_bit != get_bitfield_bit(get_chunk_bits_root(challenge.chunk_bits), 0)
# Add new bit challenge record
new_record = CustodyBitChallengeRecord(
@ -562,7 +563,7 @@ def process_bit_challenge(state: BeaconState,
challenger_index=challenge.challenger_index,
responder_index=challenge.responder_index,
inclusion_epoch=get_current_epoch(state),
data_root=challenge.attestation.data.crosslink.data_root,
data_root=attestation.data.crosslink.data_root,
chunk_count=chunk_count,
chunk_bits_merkle_root=hash_tree_root(challenge.chunk_bits),
responder_key=challenge.responder_key,
@ -669,8 +670,8 @@ Run `process_reveal_deadlines(state)` immediately after `process_registry_update
# end insert @process_reveal_deadlines
def process_reveal_deadlines(state: BeaconState) -> None:
for index, validator in enumerate(state.validator_registry):
if (validator.next_custody_reveal_period + (CUSTODY_RESPONSE_DEADLINE // EPOCHS_PER_CUSTODY_PERIOD)
< get_validators_custody_reveal_period(state, index)):
deadline = validator.next_custody_reveal_period + (CUSTODY_RESPONSE_DEADLINE // EPOCHS_PER_CUSTODY_PERIOD)
if get_validators_custody_reveal_period(state, index) > deadline:
slash_validator(state, index)
```

View File

@ -46,8 +46,8 @@ This document describes the shard data layer and the shard fork choice rule in P
| - | - |
| `BYTES_PER_SHARD_BLOCK_BODY` | `2**14` (= 16,384) |
| `MAX_SHARD_ATTESTIONS` | `2**4` (= 16) |
| `PHASE_1_GENESIS_EPOCH` | **TBD** |
| `PHASE_1_GENESIS_SLOT` | **TBD** |
| `PHASE_1_FORK_EPOCH` | **TBD** |
| `PHASE_1_FORK_SLOT` | **TBD** |
| `GENESIS_SHARD_SLOT` | 0 |
### Time parameters
@ -274,14 +274,12 @@ Let:
* `beacon_blocks` be the `BeaconBlock` list such that `beacon_blocks[slot]` is the canonical `BeaconBlock` at slot `slot`
* `beacon_state` be the canonical `BeaconState` after processing `beacon_blocks[-1]`
* `valid_shard_blocks` be the list of valid `ShardBlock`, recursively defined
* `unix_time` be the current unix time
* `candidate` be a candidate `ShardBlock` for which validity is to be determined by running `is_valid_shard_block`
```python
def is_valid_shard_block(beacon_blocks: List[BeaconBlock],
beacon_state: BeaconState,
valid_shard_blocks: List[ShardBlock],
unix_time: int,
candidate: ShardBlock) -> bool:
# Check if block is already determined valid
for _, block in enumerate(valid_shard_blocks):
@ -289,8 +287,7 @@ def is_valid_shard_block(beacon_blocks: List[BeaconBlock],
return True
# Check slot number
assert candidate.slot >= PHASE_1_GENESIS_SLOT
assert unix_time >= beacon_state.genesis_time + (block.slot - GENESIS_SLOT) * SECONDS_PER_SLOT
assert candidate.slot >= PHASE_1_FORK_SLOT
# Check shard number
assert candidate.shard <= SHARD_COUNT
@ -304,7 +301,7 @@ def is_valid_shard_block(beacon_blocks: List[BeaconBlock],
assert candidate.state_root == ZERO_HASH # [to be removed in phase 2]
# Check parent block
if candidate.slot == PHASE_1_GENESIS_SLOT:
if candidate.slot == PHASE_1_FORK_SLOT:
assert candidate.parent_root == ZERO_HASH
else:
parent_block = next(
@ -386,7 +383,7 @@ def is_valid_beacon_attestation(shard: Shard,
return True
# Check previous attestation
if candidate.data.previous_crosslink.epoch <= PHASE_1_GENESIS_EPOCH:
if candidate.data.previous_crosslink.epoch <= PHASE_1_FORK_EPOCH:
assert candidate.data.previous_crosslink.data_root == ZERO_HASH
else:
previous_attestation = next(