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

@@ -135,7 +135,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
state
.get_validator(proposer_slashing.proposer_index() as usize)?
.effective_balance
.safe_div(self.spec.whistleblower_reward_quotient_for_state(state))?,
.safe_div(state.get_whistleblower_reward_quotient(&self.spec))?,
)?;
}
@@ -157,7 +157,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
state
.get_validator(attester_index as usize)?
.effective_balance
.safe_div(self.spec.whistleblower_reward_quotient_for_state(state))?,
.safe_div(state.get_whistleblower_reward_quotient(&self.spec))?,
)?;
}
}

View File

@@ -269,16 +269,16 @@ async fn test_rewards_electra_slashings() {
harness.add_attester_slashing(vec![0]).unwrap();
let slashed_balance_1 = initial_balances.get_mut(0).unwrap();
let validator_1_effective_balance = state.get_effective_balance(0).unwrap();
let delta_1 = validator_1_effective_balance
/ harness.spec.min_slashing_penalty_quotient_for_state(&state);
let delta_1 =
validator_1_effective_balance / state.get_min_slashing_penalty_quotient(&harness.spec);
*slashed_balance_1 -= delta_1;
// add a proposer slashing and calculating slashing penalties
harness.add_proposer_slashing(1).unwrap();
let slashed_balance_2 = initial_balances.get_mut(1).unwrap();
let validator_2_effective_balance = state.get_effective_balance(1).unwrap();
let delta_2 = validator_2_effective_balance
/ harness.spec.min_slashing_penalty_quotient_for_state(&state);
let delta_2 =
validator_2_effective_balance / state.get_min_slashing_penalty_quotient(&harness.spec);
*slashed_balance_2 -= delta_2;
check_all_electra_rewards(&harness, initial_balances).await;