mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-09 19:51:47 +00:00
Remove state dependency from core module in consensus/types (#8653)
#8652 - This removes instances of `BeaconStateError` from `eth_spec.rs`, and replaces them directly with `ArithError` which can be trivially converted back to `BeaconStateError` at the call site. - Also moves the state related methods on `ChainSpec` to be methods on `BeaconState` instead. I think this might be a more natural place for them to exist anyway. Co-Authored-By: Mac L <mjladson@pm.me>
This commit is contained in:
@@ -42,8 +42,7 @@ pub fn slash_validator<E: EthSpec>(
|
||||
decrease_balance(
|
||||
state,
|
||||
slashed_index,
|
||||
validator_effective_balance
|
||||
.safe_div(spec.min_slashing_penalty_quotient_for_state(state))?,
|
||||
validator_effective_balance.safe_div(state.get_min_slashing_penalty_quotient(spec))?,
|
||||
)?;
|
||||
|
||||
update_progressive_balances_on_slashing(state, slashed_index, validator_effective_balance)?;
|
||||
@@ -54,8 +53,8 @@ pub fn slash_validator<E: EthSpec>(
|
||||
// Apply proposer and whistleblower rewards
|
||||
let proposer_index = ctxt.get_proposer_index(state, spec)? as usize;
|
||||
let whistleblower_index = opt_whistleblower_index.unwrap_or(proposer_index);
|
||||
let whistleblower_reward = validator_effective_balance
|
||||
.safe_div(spec.whistleblower_reward_quotient_for_state(state))?;
|
||||
let whistleblower_reward =
|
||||
validator_effective_balance.safe_div(state.get_whistleblower_reward_quotient(spec))?;
|
||||
let proposer_reward = if state.fork_name_unchecked().altair_enabled() {
|
||||
whistleblower_reward
|
||||
.safe_mul(PROPOSER_WEIGHT)?
|
||||
|
||||
@@ -886,7 +886,7 @@ impl SlashingsContext {
|
||||
) -> Result<Self, Error> {
|
||||
let sum_slashings = state.get_all_slashings().iter().copied().safe_sum()?;
|
||||
let adjusted_total_slashing_balance = min(
|
||||
sum_slashings.safe_mul(spec.proportional_slashing_multiplier_for_state(state))?,
|
||||
sum_slashings.safe_mul(state.get_proportional_slashing_multiplier(spec))?,
|
||||
state_ctxt.total_active_balance,
|
||||
);
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ pub fn process_slashings<E: EthSpec>(
|
||||
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_for_state(state))?,
|
||||
sum_slashings.safe_mul(state.get_proportional_slashing_multiplier(spec))?,
|
||||
total_balance,
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user