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:
Mac L
2026-01-15 06:16:40 +04:00
committed by GitHub
parent f584521e85
commit 605ef8e8e6
9 changed files with 53 additions and 66 deletions

View File

@@ -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)?