Electra alpha8 spec updates (#6496)

* Fix partial withdrawals count

* Remove get_active_balance

* Remove queue_entire_balance_and_reset_validator

* Switch to compounding when consolidating with source==target

* Queue deposit requests and apply them during epoch processing

* Fix ef tests

* Clear todos

* Fix engine api formatting issues

* Merge branch 'unstable' into electra-alpha7

* Make add_validator_to_registry more in line with the spec

* Address some review comments

* Cleanup

* Update initialize_beacon_state_from_eth1

* Merge branch 'unstable' into electra-alpha7

* Fix rpc decoding for blobs by range/root

* Fix block hash computation

* Fix process_deposits bug

* Merge branch 'unstable' into electra-alpha7

* Fix topup deposit processing bug

* Update builder api for electra

* Refactor mock builder to separate functionality

* Merge branch 'unstable' into electra-alpha7

* Address review comments

* Use copied for reference rather than cloned

* Optimise and simplify PendingDepositsContext::new

* Merge remote-tracking branch 'origin/unstable' into electra-alpha7

* Fix processing of deposits with invalid signatures

* Remove redundant code in genesis init

* Revert "Refactor mock builder to separate functionality"

This reverts commit 6d10456912.

* Revert "Update builder api for electra"

This reverts commit c5c9aca6db.

* Simplify pre-activation sorting

* Fix stale validators used in upgrade_to_electra

* Merge branch 'unstable' into electra-alpha7
This commit is contained in:
Pawan Dhananjay
2024-12-17 07:44:24 +05:30
committed by GitHub
parent 02cb2d68ff
commit d74b2d96f5
25 changed files with 519 additions and 337 deletions

View File

@@ -1,8 +1,10 @@
use bls::Signature;
use itertools::Itertools;
use safe_arith::SafeArith;
use std::mem;
use types::{
BeaconState, BeaconStateElectra, BeaconStateError as Error, ChainSpec, Epoch, EpochCache,
EthSpec, Fork,
EthSpec, Fork, PendingDeposit,
};
/// Transform a `Deneb` state into an `Electra` state.
@@ -38,29 +40,44 @@ pub fn upgrade_to_electra<E: EthSpec>(
// Add validators that are not yet active to pending balance deposits
let validators = post.validators().clone();
let mut pre_activation = validators
let pre_activation = validators
.iter()
.enumerate()
.filter(|(_, validator)| validator.activation_epoch == spec.far_future_epoch)
.sorted_by_key(|(index, validator)| (validator.activation_eligibility_epoch, *index))
.collect::<Vec<_>>();
// Sort the indices by activation_eligibility_epoch and then by index
pre_activation.sort_by(|(index_a, val_a), (index_b, val_b)| {
if val_a.activation_eligibility_epoch == val_b.activation_eligibility_epoch {
index_a.cmp(index_b)
} else {
val_a
.activation_eligibility_epoch
.cmp(&val_b.activation_eligibility_epoch)
}
});
// 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;
let pubkey = validator.pubkey;
let withdrawal_credentials = validator.withdrawal_credentials;
post.pending_deposits_mut()?
.push(PendingDeposit {
pubkey,
withdrawal_credentials,
amount: balance_copy,
signature: Signature::infinity()?.into(),
slot: spec.genesis_slot,
})
.map_err(Error::MilhouseError)?;
}
// Ensure early adopters of compounding credentials go through the activation churn
let validators = post.validators().clone();
for (index, validator) in validators.iter().enumerate() {
if validator.has_compounding_withdrawal_credential(spec) {
post.queue_excess_active_balance(index, spec)?;
@@ -137,7 +154,7 @@ pub fn upgrade_state_to_electra<E: EthSpec>(
earliest_exit_epoch,
consolidation_balance_to_consume: 0,
earliest_consolidation_epoch,
pending_balance_deposits: Default::default(),
pending_deposits: Default::default(),
pending_partial_withdrawals: Default::default(),
pending_consolidations: Default::default(),
// Caches