pr feedback

This commit is contained in:
Danny Ryan 2018-12-11 09:49:50 -06:00
parent ae33eec081
commit 1e3f518f02
No known key found for this signature in database
GPG Key ID: 2765A792E42CE07A

View File

@ -1096,7 +1096,7 @@ def on_startup(initial_validator_entries: List[Any],
randao_commitment=randao_commitment randao_commitment=randao_commitment
) )
if state.validator_registry[index].balance >= MAX_DEPOSIT: if state.validator_registry[index].balance >= MAX_DEPOSIT:
update_validator_status(index, state, ACTIVE) update_validator_status(state, index, ACTIVE)
# set initial committee shuffling # set initial committee shuffling
initial_shuffling = get_new_shuffling(ZERO_HASH, initial_validator_registry, 0) initial_shuffling = get_new_shuffling(ZERO_HASH, initial_validator_registry, 0)
@ -1180,26 +1180,27 @@ def process_deposit(state: BeaconState,
### Routine for updating validator status ### Routine for updating validator status
```python ```python
def update_validator_status(index: int, def update_validator_status(state: BeaconState,
state: BeaconState, index: int,
new_status: int) -> None: new_status: int) -> None:
""" """
Update the validator status with the given ``index`` to ``new_status``. Update the validator status with the given ``index`` to ``new_status``.
Handle other general accounting related to this status update.
Note that this function mutates ``state``. Note that this function mutates ``state``.
""" """
if new_status == ACTIVE: if new_status == ACTIVE:
activate_validator(index, state) activate_validator(state, index)
if new_status == ACTIVE_PENDING_EXIT: if new_status == ACTIVE_PENDING_EXIT:
initiate_validator_exit(index, state) initiate_validator_exit(state, index)
if new_status in [EXITED_WITH_PENALTY, EXITED_WITHOUT_PENALTY]: if new_status in [EXITED_WITH_PENALTY, EXITED_WITHOUT_PENALTY]:
exit_validator(index, state, new_status) exit_validator(state, index, new_status)
``` ```
The following are helpers and should only be called via `update_validator_status`: The following are helpers and should only be called via `update_validator_status`:
```python ```python
def activate_validator(index: int, def activate_validator(state: BeaconState,
state: BeaconState) -> None: index: int) -> None:
""" """
Activate the validator with the given ``index``. Activate the validator with the given ``index``.
Note that this function mutates ``state``. Note that this function mutates ``state``.
@ -1219,16 +1220,23 @@ def activate_validator(index: int,
``` ```
```python ```python
def initiate_validator_exit(index: int, def initiate_validator_exit(state: BeaconState,
state: BeaconState) -> None: index: int) -> None:
"""
Initiate exit for the validator with the given ``index``.
Note that this function mutates ``state``.
"""
if validator.status != ACTIVE:
return
validator = state.validator_registry[index] validator = state.validator_registry[index]
validator.status = ACTIVE_PENDING_EXIT validator.status = ACTIVE_PENDING_EXIT
validator.latest_status_change_slot = state.slot validator.latest_status_change_slot = state.slot
``` ```
```python ```python
def exit_validator(index: int, def exit_validator(state: BeaconState,
state: BeaconState, index: int,
new_status: int) -> None: new_status: int) -> None:
""" """
Exit the validator with the given ``index``. Exit the validator with the given ``index``.
@ -1236,6 +1244,10 @@ def exit_validator(index: int,
""" """
validator = state.validator_registry[index] validator = state.validator_registry[index]
prev_status = validator.status prev_status = validator.status
if prev_status == EXITED_WITH_PENALTY:
return
validator.status = new_status validator.status = new_status
validator.latest_status_change_slot = state.slot validator.latest_status_change_slot = state.slot
@ -1247,7 +1259,7 @@ def exit_validator(index: int,
whistleblower.balance += whistleblower_reward whistleblower.balance += whistleblower_reward
validator.balance -= whistleblower_reward validator.balance -= whistleblower_reward
if prev_status in [EXITED_WITH_PENALTY, EXITED_WITHOUT_PENALTY] if prev_status == EXITED_WITHOUT_PENALTY
return return
# The following updates only occur if not previous exited # The following updates only occur if not previous exited
@ -1323,7 +1335,7 @@ For each `proposer_slashing` in `block.body.proposer_slashings`:
* Verify that `proposer_slashing.proposal_data_1.shard == proposer_slashing.proposal_data_2.shard`. * Verify that `proposer_slashing.proposal_data_1.shard == proposer_slashing.proposal_data_2.shard`.
* Verify that `proposer_slashing.proposal_data_1.block_hash != proposer_slashing.proposal_data_2.block_hash`. * Verify that `proposer_slashing.proposal_data_1.block_hash != proposer_slashing.proposal_data_2.block_hash`.
* Verify that `proposer.status != EXITED_WITH_PENALTY`. * Verify that `proposer.status != EXITED_WITH_PENALTY`.
* Run `update_validator_status(proposer_slashing.proposer_index, state, new_status=EXITED_WITH_PENALTY)`. * Run `update_validator_status(state, proposer_slashing.proposer_index, new_status=EXITED_WITH_PENALTY)`.
#### Casper slashings #### Casper slashings
@ -1338,7 +1350,7 @@ For each `casper_slashing` in `block.body.casper_slashings`:
* Let `intersection = [x for x in indices(casper_slashing.votes_1) if x in indices(casper_slashing.votes_2)]`. * Let `intersection = [x for x in indices(casper_slashing.votes_1) if x in indices(casper_slashing.votes_2)]`.
* Verify that `len(intersection) >= 1`. * Verify that `len(intersection) >= 1`.
* Verify that `casper_slashing.votes_1.data.justified_slot + 1 < casper_slashing.votes_2.data.justified_slot + 1 == casper_slashing.votes_2.data.slot < casper_slashing.votes_1.data.slot` or `casper_slashing.votes_1.data.slot == casper_slashing.votes_2.data.slot`. * Verify that `casper_slashing.votes_1.data.justified_slot + 1 < casper_slashing.votes_2.data.justified_slot + 1 == casper_slashing.votes_2.data.slot < casper_slashing.votes_1.data.slot` or `casper_slashing.votes_1.data.slot == casper_slashing.votes_2.data.slot`.
* For each [validator](#dfn-validator) index `i` in `intersection`, if `state.validator_registry[i].status` does not equal `EXITED_WITH_PENALTY`, then run `update_validator_status(i, state, new_status=EXITED_WITH_PENALTY)` * For each [validator](#dfn-validator) index `i` in `intersection`, if `state.validator_registry[i].status` does not equal `EXITED_WITH_PENALTY`, then run `update_validator_status(state, i, new_status=EXITED_WITH_PENALTY)`
#### Attestations #### Attestations
@ -1405,7 +1417,7 @@ For each `exit` in `block.body.exits`:
* Verify that `validator.status == ACTIVE`. * Verify that `validator.status == ACTIVE`.
* Verify that `state.slot >= exit.slot`. * Verify that `state.slot >= exit.slot`.
* Verify that `state.slot >= validator.latest_status_change_slot + SHARD_PERSISTENT_COMMITTEE_CHANGE_PERIOD`. * Verify that `state.slot >= validator.latest_status_change_slot + SHARD_PERSISTENT_COMMITTEE_CHANGE_PERIOD`.
* Run `update_validator_status(validator_index, state, new_status=ACTIVE_PENDING_EXIT)`. * Run `update_validator_status(state, validator_index, new_status=ACTIVE_PENDING_EXIT)`.
### Ejections ### Ejections
@ -1419,7 +1431,7 @@ def process_ejections(state: BeaconState) -> None:
""" """
for index, validator in enumerate(state.validator_registry): for index, validator in enumerate(state.validator_registry):
if is_active_validator(validor) and validator.balance < EJECTION_BALANCE: if is_active_validator(validor) and validator.balance < EJECTION_BALANCE:
update_validator_status(index, state, new_status=EXITED_WITHOUT_PENALTY) update_validator_status(state, index, new_status=EXITED_WITHOUT_PENALTY)
``` ```
## Per-epoch processing ## Per-epoch processing
@ -1560,7 +1572,7 @@ def update_validator_registry(state: BeaconState) -> None:
break break
# Activate validator # Activate validator
update_validator_status(index, state, new_status=ACTIVE) update_validator_status(state, index, new_status=ACTIVE)
# Exit validators within the allowable balance churn # Exit validators within the allowable balance churn
balance_churn = 0 balance_churn = 0
@ -1572,7 +1584,7 @@ def update_validator_registry(state: BeaconState) -> None:
break break
# Exit validator # Exit validator
update_validator_status(index, state, new_status=EXITED_WITHOUT_PENALTY) update_validator_status(state, index, new_status=EXITED_WITHOUT_PENALTY)
# Calculate the total ETH that has been penalized in the last ~2-3 withdrawal periods # Calculate the total ETH that has been penalized in the last ~2-3 withdrawal periods