Merge pull request #838 from ethereum/JustinDrake-patch-11

Generalise `slash_validator` for phase 1
This commit is contained in:
Danny Ryan 2019-03-28 12:41:50 -06:00 committed by GitHub
commit 76e053f176
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 18 additions and 14 deletions

View File

@ -253,8 +253,8 @@ Code snippets appearing in `this style` are to be interpreted as Python code.
| Name | Value | | Name | Value |
| - | - | | - | - |
| `BASE_REWARD_QUOTIENT` | `2**5` (= 32) | | `BASE_REWARD_QUOTIENT` | `2**5` (= 32) |
| `WHISTLEBLOWER_REWARD_QUOTIENT` | `2**9` (= 512) | | `WHISTLEBLOWING_REWARD_QUOTIENT` | `2**9` (= 512) |
| `ATTESTATION_INCLUSION_REWARD_QUOTIENT` | `2**3` (= 8) | | `PROPOSER_REWARD_QUOTIENT` | `2**3` (= 8) |
| `INACTIVITY_PENALTY_QUOTIENT` | `2**24` (= 16,777,216) | | `INACTIVITY_PENALTY_QUOTIENT` | `2**24` (= 16,777,216) |
| `MIN_PENALTY_QUOTIENT` | `2**5` (= 32) | | `MIN_PENALTY_QUOTIENT` | `2**5` (= 32) |
@ -1398,21 +1398,25 @@ def exit_validator(state: BeaconState, index: ValidatorIndex) -> None:
#### `slash_validator` #### `slash_validator`
```python ```python
def slash_validator(state: BeaconState, index: ValidatorIndex) -> None: def slash_validator(state: BeaconState, slashed_index: ValidatorIndex, whistleblower_index: ValidatorIndex=None) -> None:
""" """
Slash the validator with index ``index``. Slash the validator with index ``slashed_index``.
Note that this function mutates ``state``. Note that this function mutates ``state``.
""" """
validator = state.validator_registry[index] exit_validator(state, slashed_index)
exit_validator(state, index) state.validator_registry[slashed_index].slashed = True
state.latest_slashed_balances[get_current_epoch(state) % LATEST_SLASHED_EXIT_LENGTH] += get_effective_balance(state, index) state.validator_registry[slashed_index].withdrawable_epoch = get_current_epoch(state) + LATEST_SLASHED_EXIT_LENGTH
slashed_balance = get_effective_balance(state, slashed_index)
state.latest_slashed_balances[get_current_epoch(state) % LATEST_SLASHED_EXIT_LENGTH] += slashed_balance
whistleblower_index = get_beacon_proposer_index(state, state.slot) proposer_index = get_beacon_proposer_index(state, state.slot)
whistleblower_reward = get_effective_balance(state, index) // WHISTLEBLOWER_REWARD_QUOTIENT if whistleblower_index is None:
increase_balance(state, whistleblower_index, whistleblower_reward) whistleblower_index = proposer_index
decrease_balance(state, index, whistleblower_reward) whistleblowing_reward = slashed_balance // WHISTLEBLOWING_REWARD_QUOTIENT
validator.slashed = True proposer_reward = whistleblowing_reward // PROPOSER_REWARD_QUOTIENT
validator.withdrawable_epoch = get_current_epoch(state) + LATEST_SLASHED_EXIT_LENGTH increase_balance(state, proposer_index, proposer_reward)
increase_balance(state, whistleblower_index, whistleblowing_reward - proposer_reward)
decrease_balance(state, slashed_index, whistleblowing_reward)
``` ```
#### `prepare_validator_for_withdrawal` #### `prepare_validator_for_withdrawal`
@ -1951,7 +1955,7 @@ def get_justification_and_finalization_deltas(state: BeaconState) -> Tuple[List[
# Proposer bonus # Proposer bonus
if index in get_attesting_indices(state, state.previous_epoch_attestations): if index in get_attesting_indices(state, state.previous_epoch_attestations):
proposer_index = get_beacon_proposer_index(state, inclusion_slot(state, index)) proposer_index = get_beacon_proposer_index(state, inclusion_slot(state, index))
rewards[proposer_index] += base_reward // ATTESTATION_INCLUSION_REWARD_QUOTIENT rewards[proposer_index] += base_reward // PROPOSER_REWARD_QUOTIENT
# Take away max rewards if we're not finalizing # Take away max rewards if we're not finalizing
if epochs_since_finality > 4: if epochs_since_finality > 4:
penalties[index] += base_reward * 4 penalties[index] += base_reward * 4