mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-06 10:11:44 +00:00
Electra other containers (#5652)
* add new fields to execution payload and header
* beacon state changes
* partial beacon state
* safe arith in upgrade to electra
* initialize balances cache in interop genesis state
* Revert "initialize balances cache in interop genesis state"
This reverts commit c60b522865.
* always initialize balances cache if necessary in electra upgrade
* build cache earlier
* fix block test
* per fork NUM_FIELDS_POW2
* Merge branch 'unstable' of https://github.com/sigp/lighthouse into electra-other-containers
* fix lints
* get fields based on post state, as is spec'd
* fix type and move cache build
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
use safe_arith::SafeArith;
|
||||
use std::mem;
|
||||
use types::{
|
||||
BeaconState, BeaconStateElectra, BeaconStateError as Error, ChainSpec, EpochCache, EthSpec,
|
||||
@@ -10,14 +11,28 @@ pub fn upgrade_to_electra<E: EthSpec>(
|
||||
spec: &ChainSpec,
|
||||
) -> Result<(), Error> {
|
||||
let epoch = pre_state.current_epoch();
|
||||
let pre = pre_state.as_deneb_mut()?;
|
||||
|
||||
let earliest_exit_epoch = pre_state
|
||||
.validators()
|
||||
.iter()
|
||||
.filter(|v| v.exit_epoch != spec.far_future_epoch)
|
||||
.map(|v| v.exit_epoch)
|
||||
.max()
|
||||
.unwrap_or(epoch)
|
||||
.safe_add(1)?;
|
||||
|
||||
// The total active balance cache must be built before the consolidation churn limit
|
||||
// is calculated.
|
||||
pre_state.build_total_active_balance_cache(spec)?;
|
||||
let earliest_consolidation_epoch = spec.compute_activation_exit_epoch(epoch)?;
|
||||
|
||||
let pre = pre_state.as_deneb_mut()?;
|
||||
// Where possible, use something like `mem::take` to move fields from behind the &mut
|
||||
// reference. For other fields that don't have a good default value, use `clone`.
|
||||
//
|
||||
// Fixed size vectors get cloned because replacing them would require the same size
|
||||
// allocation as cloning.
|
||||
let post = BeaconState::Electra(BeaconStateElectra {
|
||||
let mut post = BeaconState::Electra(BeaconStateElectra {
|
||||
// Versioning
|
||||
genesis_time: pre.genesis_time,
|
||||
genesis_validators_root: pre.genesis_validators_root,
|
||||
@@ -62,6 +77,16 @@ pub fn upgrade_to_electra<E: EthSpec>(
|
||||
next_withdrawal_index: pre.next_withdrawal_index,
|
||||
next_withdrawal_validator_index: pre.next_withdrawal_validator_index,
|
||||
historical_summaries: pre.historical_summaries.clone(),
|
||||
// Electra
|
||||
deposit_receipts_start_index: spec.unset_deposit_receipts_start_index,
|
||||
deposit_balance_to_consume: 0,
|
||||
exit_balance_to_consume: 0,
|
||||
earliest_exit_epoch,
|
||||
consolidation_balance_to_consume: 0,
|
||||
earliest_consolidation_epoch,
|
||||
pending_balance_deposits: Default::default(),
|
||||
pending_partial_withdrawals: Default::default(),
|
||||
pending_consolidations: Default::default(),
|
||||
// Caches
|
||||
total_active_balance: pre.total_active_balance,
|
||||
progressive_balances_cache: mem::take(&mut pre.progressive_balances_cache),
|
||||
@@ -71,6 +96,39 @@ pub fn upgrade_to_electra<E: EthSpec>(
|
||||
slashings_cache: mem::take(&mut pre.slashings_cache),
|
||||
epoch_cache: EpochCache::default(),
|
||||
});
|
||||
*post.exit_balance_to_consume_mut()? = post.get_activation_exit_churn_limit(spec)?;
|
||||
*post.consolidation_balance_to_consume_mut()? = post.get_consolidation_churn_limit(spec)?;
|
||||
|
||||
// Add validators that are not yet active to pending balance deposits
|
||||
let validators = post.validators().clone();
|
||||
let mut pre_activation = validators
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter(|(_, validator)| validator.activation_epoch == spec.far_future_epoch)
|
||||
.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)?;
|
||||
}
|
||||
|
||||
// Ensure early adopters of compounding credentials go through the activation churn
|
||||
for (index, validator) in validators.iter().enumerate() {
|
||||
if validator.has_compounding_withdrawal_credential(spec) {
|
||||
post.queue_excess_active_balance(index, spec)?;
|
||||
}
|
||||
}
|
||||
|
||||
*pre_state = post;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user