process withdrawals updates

This commit is contained in:
realbigsean
2024-05-06 18:56:16 -04:00
parent 2c2e44c4ed
commit e2e82ff1b9
8 changed files with 99 additions and 17 deletions

View File

@@ -159,6 +159,7 @@ pub enum Error {
IndexNotSupported(usize),
InvalidFlagIndex(usize),
MerkleTreeError(merkle_proof::MerkleTreeError),
PartialWithdrawalCountInvalid(usize),
}
/// Control whether an epoch-indexed field can be indexed at the next epoch or not.
@@ -2097,11 +2098,12 @@ impl<E: EthSpec> BeaconState<E> {
&self,
validator_index: usize,
spec: &ChainSpec,
current_fork: ForkName,
) -> Result<u64, Error> {
let max_effective_balance = self
.validators()
.get(validator_index)
.map(|validator| validator.get_validator_max_effective_balance(spec))
.map(|validator| validator.get_validator_max_effective_balance(spec, current_fork))
.ok_or(Error::UnknownValidator(validator_index))?;
Ok(std::cmp::min(
*self

View File

@@ -203,7 +203,7 @@ impl Validator {
current_fork: ForkName,
) -> bool {
if current_fork >= ForkName::Electra {
self.is_partially_withdrawable_validator_electra(balance, spec)
self.is_partially_withdrawable_validator_electra(balance, spec, current_fork)
} else {
self.is_partially_withdrawable_validator_capella(balance, spec)
}
@@ -223,8 +223,9 @@ impl Validator {
&self,
balance: u64,
spec: &ChainSpec,
current_fork: ForkName,
) -> bool {
let max_effective_balance = self.get_validator_max_effective_balance(spec);
let max_effective_balance = self.get_validator_max_effective_balance(spec, current_fork);
let has_max_effective_balance = self.effective_balance == max_effective_balance;
let has_excess_balance = balance > max_effective_balance;
self.has_execution_withdrawal_credential(spec)
@@ -239,11 +240,19 @@ impl Validator {
}
/// Returns the max effective balance for a validator in gwei.
pub fn get_validator_max_effective_balance(&self, spec: &ChainSpec) -> u64 {
if self.has_compounding_withdrawal_credential(spec) {
spec.max_effective_balance_electra
pub fn get_validator_max_effective_balance(
&self,
spec: &ChainSpec,
current_fork: ForkName,
) -> u64 {
if current_fork >= ForkName::Electra {
if self.has_compounding_withdrawal_credential(spec) {
spec.max_effective_balance_electra
} else {
spec.min_activation_balance
}
} else {
spec.min_activation_balance
spec.max_effective_balance
}
}
}