Minor refactorings

This commit is contained in:
Pawan Dhananjay
2025-01-22 12:13:02 -08:00
parent 67dd619383
commit ea38409b2c
2 changed files with 10 additions and 32 deletions

View File

@@ -600,9 +600,7 @@ pub fn get_expected_withdrawals<E: EthSpec>(
address: validator
.get_execution_withdrawal_address(spec)
.ok_or(BlockProcessingError::WithdrawalCredentialsInvalid)?,
amount: balance.safe_sub(
validator.get_max_effective_balance(spec, state.fork_name_unchecked()),
)?,
amount: balance.safe_sub(validator.get_max_effective_balance(spec, fork_name))?,
});
withdrawal_index.safe_add_assign(1)?;
}

View File

@@ -2329,21 +2329,12 @@ impl<E: EthSpec> BeaconState<E> {
| BeaconState::Bellatrix(_)
| BeaconState::Capella(_)
| BeaconState::Deneb(_) => Err(Error::IncorrectStateVariant),
BeaconState::Electra(_) => {
let state = self.as_electra_mut()?;
BeaconState::Electra(_) | BeaconState::Fulu(_) => {
// Consume the balance and update state variables
state.exit_balance_to_consume = exit_balance_to_consume.safe_sub(exit_balance)?;
state.earliest_exit_epoch = earliest_exit_epoch;
Ok(state.earliest_exit_epoch)
}
BeaconState::Fulu(_) => {
let state = self.as_fulu_mut()?;
// Consume the balance and update state variables
state.exit_balance_to_consume = exit_balance_to_consume.safe_sub(exit_balance)?;
state.earliest_exit_epoch = earliest_exit_epoch;
Ok(state.earliest_exit_epoch)
*self.exit_balance_to_consume_mut()? =
exit_balance_to_consume.safe_sub(exit_balance)?;
*self.earliest_exit_epoch_mut()? = earliest_exit_epoch;
self.earliest_exit_epoch()
}
}
}
@@ -2385,23 +2376,12 @@ impl<E: EthSpec> BeaconState<E> {
| BeaconState::Bellatrix(_)
| BeaconState::Capella(_)
| BeaconState::Deneb(_) => Err(Error::IncorrectStateVariant),
BeaconState::Electra(_) => {
let state = self.as_electra_mut()?;
BeaconState::Electra(_) | BeaconState::Fulu(_) => {
// Consume the balance and update state variables.
state.consolidation_balance_to_consume =
*self.consolidation_balance_to_consume_mut()? =
consolidation_balance_to_consume.safe_sub(consolidation_balance)?;
state.earliest_consolidation_epoch = earliest_consolidation_epoch;
Ok(state.earliest_consolidation_epoch)
}
BeaconState::Fulu(_) => {
let state = self.as_fulu_mut()?;
// Consume the balance and update state variables.
state.consolidation_balance_to_consume =
consolidation_balance_to_consume.safe_sub(consolidation_balance)?;
state.earliest_consolidation_epoch = earliest_consolidation_epoch;
Ok(state.earliest_consolidation_epoch)
*self.earliest_consolidation_epoch_mut()? = earliest_consolidation_epoch;
self.earliest_consolidation_epoch()
}
}
}