From 3d595e6c0f39ea293dff90a966e087a4e993c8d3 Mon Sep 17 00:00:00 2001 From: Pawan Dhananjay Date: Thu, 10 Oct 2024 13:57:42 -0700 Subject: [PATCH] Remove queue_entire_balance_and_reset_validator --- .../state_processing/src/upgrade/electra.rs | 23 ++++++++++++++-- consensus/types/src/beacon_state.rs | 27 ------------------- 2 files changed, 21 insertions(+), 29 deletions(-) diff --git a/consensus/state_processing/src/upgrade/electra.rs b/consensus/state_processing/src/upgrade/electra.rs index 1e532d9f10..8d5a2feb11 100644 --- a/consensus/state_processing/src/upgrade/electra.rs +++ b/consensus/state_processing/src/upgrade/electra.rs @@ -2,7 +2,7 @@ use safe_arith::SafeArith; use std::mem; use types::{ BeaconState, BeaconStateElectra, BeaconStateError as Error, ChainSpec, Epoch, EpochCache, - EthSpec, Fork, + EthSpec, Fork, PendingBalanceDeposit, }; /// Transform a `Deneb` state into an `Electra` state. @@ -57,7 +57,26 @@ pub fn upgrade_to_electra( // Process validators to queue entire balance and reset them for (index, _) in pre_activation { - post.queue_entire_balance_and_reset_validator(index, spec)?; + let balance = post + .balances_mut() + .get_mut(index) + .ok_or(Error::UnknownValidator(index))?; + let balance_copy = *balance; + *balance = 0_u64; + + let validator = post + .validators_mut() + .get_mut(index) + .ok_or(Error::UnknownValidator(index))?; + validator.effective_balance = 0; + validator.activation_eligibility_epoch = spec.far_future_epoch; + + post.pending_balance_deposits_mut()? + .push(PendingBalanceDeposit { + index: index as u64, + amount: balance_copy, + }) + .map_err(Error::MilhouseError)?; } // Ensure early adopters of compounding credentials go through the activation churn diff --git a/consensus/types/src/beacon_state.rs b/consensus/types/src/beacon_state.rs index d96752e0bf..0119c6a554 100644 --- a/consensus/types/src/beacon_state.rs +++ b/consensus/types/src/beacon_state.rs @@ -2156,33 +2156,6 @@ impl BeaconState { Ok(()) } - pub fn queue_entire_balance_and_reset_validator( - &mut self, - validator_index: usize, - spec: &ChainSpec, - ) -> Result<(), Error> { - let balance = self - .balances_mut() - .get_mut(validator_index) - .ok_or(Error::UnknownValidator(validator_index))?; - let balance_copy = *balance; - *balance = 0_u64; - - let validator = self - .validators_mut() - .get_mut(validator_index) - .ok_or(Error::UnknownValidator(validator_index))?; - validator.effective_balance = 0; - validator.activation_eligibility_epoch = spec.far_future_epoch; - - self.pending_balance_deposits_mut()? - .push(PendingBalanceDeposit { - index: validator_index as u64, - amount: balance_copy, - }) - .map_err(Into::into) - } - /// Change the withdrawal prefix of the given `validator_index` to the compounding withdrawal validator prefix. pub fn switch_to_compounding_validator( &mut self,