Adds review suggestions I missed
This commit is contained in:
parent
4c1b9ef6d6
commit
35c03c5f3e
|
@ -7,6 +7,6 @@ phase0: 67108864
|
||||||
# phase0_funny_fork_name: 67116000
|
# phase0_funny_fork_name: 67116000
|
||||||
|
|
||||||
# Example 2:
|
# Example 2:
|
||||||
# Should be equal to PHASE_1_GENESIS_EPOCH
|
# Should be equal to PHASE_1_FORK_EPOCH
|
||||||
# (placeholder in example value here)
|
# (placeholder in example value here)
|
||||||
# phase1: 67163000
|
# phase1: 67163000
|
||||||
|
|
|
@ -372,7 +372,7 @@ def process_custody_key_reveal(state: BeaconState,
|
||||||
|
|
||||||
# Reward Block Preposer
|
# Reward Block Preposer
|
||||||
proposer_index = get_beacon_proposer_index(state)
|
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
|
#### 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,
|
def process_chunk_challenge(state: BeaconState,
|
||||||
challenge: CustodyChunkChallenge) -> None:
|
challenge: CustodyChunkChallenge) -> None:
|
||||||
# Verify the attestation
|
# 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
|
# Verify it is not too late to challenge
|
||||||
assert slot_to_epoch(challenge.attestation.data.slot) >= get_current_epoch(state) - MAX_CHUNK_CHALLENGE_DELAY
|
assert slot_to_epoch(challenge.attestation.data.slot) >= get_current_epoch(state) - MAX_CHUNK_CHALLENGE_DELAY
|
||||||
responder = state.validator_registry[challenge.responder_index]
|
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))
|
assert is_slashable_validator(challenger, get_current_epoch(state))
|
||||||
|
|
||||||
# Verify the attestation
|
# 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
|
# Verify the attestation is eligible for challenging
|
||||||
responder = state.validator_registry[challenge.responder_index]
|
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))
|
get_validators_custody_reveal_period(state, challenge.responder_index))
|
||||||
|
|
||||||
# Verify the responder participated in the attestation
|
# 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
|
assert challenge.responder_index in attesters
|
||||||
|
|
||||||
# A validator can be the challenger for at most one challenge at a time
|
# 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(
|
get_validators_custody_reveal_period(
|
||||||
state=state,
|
state=state,
|
||||||
index=challenge.responder_index,
|
index=challenge.responder_index,
|
||||||
epoch=slot_to_epoch(challenge.attestation.data.slot)),
|
epoch=slot_to_epoch(attestation.data.slot)),
|
||||||
challenge.responder_index
|
challenge.responder_index
|
||||||
)
|
)
|
||||||
assert bls_verify(
|
assert bls_verify(
|
||||||
|
@ -551,10 +552,10 @@ def process_bit_challenge(state: BeaconState,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Verify the chunk count
|
# 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)
|
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
|
# 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)
|
assert custody_bit != get_bitfield_bit(get_chunk_bits_root(challenge.chunk_bits), 0)
|
||||||
# Add new bit challenge record
|
# Add new bit challenge record
|
||||||
new_record = CustodyBitChallengeRecord(
|
new_record = CustodyBitChallengeRecord(
|
||||||
|
@ -562,7 +563,7 @@ def process_bit_challenge(state: BeaconState,
|
||||||
challenger_index=challenge.challenger_index,
|
challenger_index=challenge.challenger_index,
|
||||||
responder_index=challenge.responder_index,
|
responder_index=challenge.responder_index,
|
||||||
inclusion_epoch=get_current_epoch(state),
|
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_count=chunk_count,
|
||||||
chunk_bits_merkle_root=hash_tree_root(challenge.chunk_bits),
|
chunk_bits_merkle_root=hash_tree_root(challenge.chunk_bits),
|
||||||
responder_key=challenge.responder_key,
|
responder_key=challenge.responder_key,
|
||||||
|
@ -669,8 +670,8 @@ Run `process_reveal_deadlines(state)` immediately after `process_registry_update
|
||||||
# end insert @process_reveal_deadlines
|
# end insert @process_reveal_deadlines
|
||||||
def process_reveal_deadlines(state: BeaconState) -> None:
|
def process_reveal_deadlines(state: BeaconState) -> None:
|
||||||
for index, validator in enumerate(state.validator_registry):
|
for index, validator in enumerate(state.validator_registry):
|
||||||
if (validator.next_custody_reveal_period + (CUSTODY_RESPONSE_DEADLINE // EPOCHS_PER_CUSTODY_PERIOD)
|
deadline = validator.next_custody_reveal_period + (CUSTODY_RESPONSE_DEADLINE // EPOCHS_PER_CUSTODY_PERIOD)
|
||||||
< get_validators_custody_reveal_period(state, index)):
|
if get_validators_custody_reveal_period(state, index) > deadline:
|
||||||
slash_validator(state, index)
|
slash_validator(state, index)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -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) |
|
| `BYTES_PER_SHARD_BLOCK_BODY` | `2**14` (= 16,384) |
|
||||||
| `MAX_SHARD_ATTESTIONS` | `2**4` (= 16) |
|
| `MAX_SHARD_ATTESTIONS` | `2**4` (= 16) |
|
||||||
| `PHASE_1_GENESIS_EPOCH` | **TBD** |
|
| `PHASE_1_FORK_EPOCH` | **TBD** |
|
||||||
| `PHASE_1_GENESIS_SLOT` | **TBD** |
|
| `PHASE_1_FORK_SLOT` | **TBD** |
|
||||||
| `GENESIS_SHARD_SLOT` | 0 |
|
| `GENESIS_SHARD_SLOT` | 0 |
|
||||||
|
|
||||||
### Time parameters
|
### 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_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]`
|
* `beacon_state` be the canonical `BeaconState` after processing `beacon_blocks[-1]`
|
||||||
* `valid_shard_blocks` be the list of valid `ShardBlock`, recursively defined
|
* `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`
|
* `candidate` be a candidate `ShardBlock` for which validity is to be determined by running `is_valid_shard_block`
|
||||||
|
|
||||||
```python
|
```python
|
||||||
def is_valid_shard_block(beacon_blocks: List[BeaconBlock],
|
def is_valid_shard_block(beacon_blocks: List[BeaconBlock],
|
||||||
beacon_state: BeaconState,
|
beacon_state: BeaconState,
|
||||||
valid_shard_blocks: List[ShardBlock],
|
valid_shard_blocks: List[ShardBlock],
|
||||||
unix_time: int,
|
|
||||||
candidate: ShardBlock) -> bool:
|
candidate: ShardBlock) -> bool:
|
||||||
# Check if block is already determined valid
|
# Check if block is already determined valid
|
||||||
for _, block in enumerate(valid_shard_blocks):
|
for _, block in enumerate(valid_shard_blocks):
|
||||||
|
@ -289,8 +287,7 @@ def is_valid_shard_block(beacon_blocks: List[BeaconBlock],
|
||||||
return True
|
return True
|
||||||
|
|
||||||
# Check slot number
|
# Check slot number
|
||||||
assert candidate.slot >= PHASE_1_GENESIS_SLOT
|
assert candidate.slot >= PHASE_1_FORK_SLOT
|
||||||
assert unix_time >= beacon_state.genesis_time + (block.slot - GENESIS_SLOT) * SECONDS_PER_SLOT
|
|
||||||
|
|
||||||
# Check shard number
|
# Check shard number
|
||||||
assert candidate.shard <= SHARD_COUNT
|
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]
|
assert candidate.state_root == ZERO_HASH # [to be removed in phase 2]
|
||||||
|
|
||||||
# Check parent block
|
# Check parent block
|
||||||
if candidate.slot == PHASE_1_GENESIS_SLOT:
|
if candidate.slot == PHASE_1_FORK_SLOT:
|
||||||
assert candidate.parent_root == ZERO_HASH
|
assert candidate.parent_root == ZERO_HASH
|
||||||
else:
|
else:
|
||||||
parent_block = next(
|
parent_block = next(
|
||||||
|
@ -386,7 +383,7 @@ def is_valid_beacon_attestation(shard: Shard,
|
||||||
return True
|
return True
|
||||||
|
|
||||||
# Check previous attestation
|
# 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
|
assert candidate.data.previous_crosslink.data_root == ZERO_HASH
|
||||||
else:
|
else:
|
||||||
previous_attestation = next(
|
previous_attestation = next(
|
||||||
|
|
|
@ -19,7 +19,7 @@ def run_early_derived_secret_reveal_processing(spec, state, randao_key_reveal, v
|
||||||
expect_assertion_error(lambda: spec.process_early_derived_secret_reveal(state, randao_key_reveal))
|
expect_assertion_error(lambda: spec.process_early_derived_secret_reveal(state, randao_key_reveal))
|
||||||
yield 'post', None
|
yield 'post', None
|
||||||
return
|
return
|
||||||
|
|
||||||
pre_slashed_balance = get_balance(state, randao_key_reveal.revealed_index)
|
pre_slashed_balance = get_balance(state, randao_key_reveal.revealed_index)
|
||||||
|
|
||||||
spec.process_early_derived_secret_reveal(state, randao_key_reveal)
|
spec.process_early_derived_secret_reveal(state, randao_key_reveal)
|
||||||
|
|
Loading…
Reference in New Issue