Rename PendingPartialWithdraw index field to validator_index

This commit is contained in:
Eitan Seri-Levi
2025-01-02 09:42:12 +07:00
parent 52e602dca8
commit 293db28ca1
4 changed files with 11 additions and 11 deletions

View File

@@ -522,8 +522,8 @@ pub fn get_expected_withdrawals<E: EthSpec>(
break; break;
} }
let withdrawal_balance = state.get_balance(withdrawal.index as usize)?; let withdrawal_balance = state.get_balance(withdrawal.validator_index as usize)?;
let validator = state.get_validator(withdrawal.index as usize)?; let validator = state.get_validator(withdrawal.validator_index as usize)?;
let has_sufficient_effective_balance = let has_sufficient_effective_balance =
validator.effective_balance >= spec.min_activation_balance; validator.effective_balance >= spec.min_activation_balance;
@@ -539,7 +539,7 @@ pub fn get_expected_withdrawals<E: EthSpec>(
); );
withdrawals.push(Withdrawal { withdrawals.push(Withdrawal {
index: withdrawal_index, index: withdrawal_index,
validator_index: withdrawal.index, validator_index: withdrawal.validator_index,
address: validator address: validator
.get_execution_withdrawal_address(spec) .get_execution_withdrawal_address(spec)
.ok_or(BeaconStateError::NonExecutionAddresWithdrawalCredential)?, .ok_or(BeaconStateError::NonExecutionAddresWithdrawalCredential)?,

View File

@@ -514,11 +514,11 @@ pub fn process_withdrawal_requests<E: EthSpec>(
} }
// Verify pubkey exists // Verify pubkey exists
let Some(index) = state.pubkey_cache().get(&request.validator_pubkey) else { let Some(validator_index) = state.pubkey_cache().get(&request.validator_pubkey) else {
continue; continue;
}; };
let validator = state.get_validator(index)?; let validator = state.get_validator(validator_index)?;
// Verify withdrawal credentials // Verify withdrawal credentials
let has_correct_credential = validator.has_execution_withdrawal_credential(spec); let has_correct_credential = validator.has_execution_withdrawal_credential(spec);
let is_correct_source_address = validator let is_correct_source_address = validator
@@ -549,16 +549,16 @@ pub fn process_withdrawal_requests<E: EthSpec>(
continue; continue;
} }
let pending_balance_to_withdraw = state.get_pending_balance_to_withdraw(index)?; let pending_balance_to_withdraw = state.get_pending_balance_to_withdraw(validator_index)?;
if is_full_exit_request { if is_full_exit_request {
// Only exit validator if it has no pending withdrawals in the queue // Only exit validator if it has no pending withdrawals in the queue
if pending_balance_to_withdraw == 0 { if pending_balance_to_withdraw == 0 {
initiate_validator_exit(state, index, spec)? initiate_validator_exit(state, validator_index, spec)?
} }
continue; continue;
} }
let balance = state.get_balance(index)?; let balance = state.get_balance(validator_index)?;
let has_sufficient_effective_balance = let has_sufficient_effective_balance =
validator.effective_balance >= spec.min_activation_balance; validator.effective_balance >= spec.min_activation_balance;
let has_excess_balance = balance let has_excess_balance = balance
@@ -583,7 +583,7 @@ pub fn process_withdrawal_requests<E: EthSpec>(
state state
.pending_partial_withdrawals_mut()? .pending_partial_withdrawals_mut()?
.push(PendingPartialWithdrawal { .push(PendingPartialWithdrawal {
index: index as u64, validator_index: validator_index as u64,
amount: to_withdraw, amount: to_withdraw,
withdrawable_epoch, withdrawable_epoch,
})?; })?;

View File

@@ -2193,7 +2193,7 @@ impl<E: EthSpec> BeaconState<E> {
for withdrawal in self for withdrawal in self
.pending_partial_withdrawals()? .pending_partial_withdrawals()?
.iter() .iter()
.filter(|withdrawal| withdrawal.index as usize == validator_index) .filter(|withdrawal| withdrawal.validator_index as usize == validator_index)
{ {
pending_balance.safe_add_assign(withdrawal.amount)?; pending_balance.safe_add_assign(withdrawal.amount)?;
} }

View File

@@ -21,7 +21,7 @@ use tree_hash_derive::TreeHash;
)] )]
pub struct PendingPartialWithdrawal { pub struct PendingPartialWithdrawal {
#[serde(with = "serde_utils::quoted_u64")] #[serde(with = "serde_utils::quoted_u64")]
pub index: u64, pub validator_index: u64,
#[serde(with = "serde_utils::quoted_u64")] #[serde(with = "serde_utils::quoted_u64")]
pub amount: u64, pub amount: u64,
pub withdrawable_epoch: Epoch, pub withdrawable_epoch: Epoch,