Update consensus code and tests to v0.12.3 (#1655)

## Proposed Changes

Update test vectors for v0.12.3, and introduced configurable `proportional_slashing_multiplier`.

Also makes `YamlConfig` a bit safer by making every field access in `apply_to_chain_spec` explicit, and removing the `#[serde(default)]` attribute, which would instantiate missing fields to type defaults! Risky!
This commit is contained in:
Michael Sproul
2020-09-26 01:58:29 +00:00
parent 3412a3ec54
commit 258b28469e
9 changed files with 264 additions and 100 deletions

View File

@@ -11,6 +11,10 @@ pub fn process_slashings<T: EthSpec>(
) -> Result<(), Error> {
let epoch = state.current_epoch();
let sum_slashings = state.get_all_slashings().iter().copied().safe_sum()?;
let adjusted_total_slashing_balance = std::cmp::min(
sum_slashings.safe_mul(spec.proportional_slashing_multiplier)?,
total_balance,
);
for (index, validator) in state.validators.iter().enumerate() {
if validator.slashed
@@ -21,7 +25,7 @@ pub fn process_slashings<T: EthSpec>(
let penalty_numerator = validator
.effective_balance
.safe_div(increment)?
.safe_mul(std::cmp::min(sum_slashings.safe_mul(3)?, total_balance))?;
.safe_mul(adjusted_total_slashing_balance)?;
let penalty = penalty_numerator
.safe_div(total_balance)?
.safe_mul(increment)?;