Electra minor refactorings (#6839)

N/A


  Fix some typos and other minor refactorings in the electra code. Thanks @jtraglia for bringing them up.

Note to reviewiers: 47803496de is the commit that needs looking into in detail. The rest are very minor refactorings
This commit is contained in:
Pawan Dhananjay
2025-01-22 16:34:22 -08:00
committed by GitHub
parent 54e37096b6
commit 266b241123
6 changed files with 33 additions and 62 deletions

View File

@@ -161,7 +161,7 @@ pub enum Error {
InvalidFlagIndex(usize),
MerkleTreeError(merkle_proof::MerkleTreeError),
PartialWithdrawalCountInvalid(usize),
NonExecutionAddresWithdrawalCredential,
NonExecutionAddressWithdrawalCredential,
NoCommitteeFound(CommitteeIndex),
InvalidCommitteeIndex(CommitteeIndex),
InvalidSelectionProof {
@@ -2214,7 +2214,7 @@ impl<E: EthSpec> BeaconState<E> {
// ******* Electra accessors *******
/// Return the churn limit for the current epoch.
/// Return the churn limit for the current epoch.
pub fn get_balance_churn_limit(&self, spec: &ChainSpec) -> Result<u64, Error> {
let total_active_balance = self.get_total_active_balance()?;
let churn = std::cmp::max(
@@ -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()
}
}
}

View File

@@ -56,7 +56,7 @@ impl Validator {
};
let max_effective_balance = validator.get_max_effective_balance(spec, fork_name);
// safe math is unnecessary here since the spec.effecive_balance_increment is never <= 0
// safe math is unnecessary here since the spec.effective_balance_increment is never <= 0
validator.effective_balance = std::cmp::min(
amount - (amount % spec.effective_balance_increment),
max_effective_balance,
@@ -195,7 +195,7 @@ impl Validator {
/// Returns `true` if the validator is fully withdrawable at some epoch.
///
/// Calls the correct function depending on the provided `fork_name`.
pub fn is_fully_withdrawable_at(
pub fn is_fully_withdrawable_validator(
&self,
balance: u64,
epoch: Epoch,
@@ -203,14 +203,14 @@ impl Validator {
current_fork: ForkName,
) -> bool {
if current_fork.electra_enabled() {
self.is_fully_withdrawable_at_electra(balance, epoch, spec)
self.is_fully_withdrawable_validator_electra(balance, epoch, spec)
} else {
self.is_fully_withdrawable_at_capella(balance, epoch, spec)
self.is_fully_withdrawable_validator_capella(balance, epoch, spec)
}
}
/// Returns `true` if the validator is fully withdrawable at some epoch.
fn is_fully_withdrawable_at_capella(
fn is_fully_withdrawable_validator_capella(
&self,
balance: u64,
epoch: Epoch,
@@ -222,7 +222,7 @@ impl Validator {
/// Returns `true` if the validator is fully withdrawable at some epoch.
///
/// Modified in electra as part of EIP 7251.
fn is_fully_withdrawable_at_electra(
fn is_fully_withdrawable_validator_electra(
&self,
balance: u64,
epoch: Epoch,