mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-14 10:22:38 +00:00
Changes for fusaka-devnet-1 (#7559)
Changes for [fusaka-devnet-1](https://notes.ethereum.org/@ethpandaops/fusaka-devnet-1) [Consensus Specs v1.6.0-alpha.1](https://github.com/ethereum/consensus-specs/pull/4346) * [EIP-7917: Deterministic Proposer Lookahead](https://eips.ethereum.org/EIPS/eip-7917) * [EIP-7892: Blob Parameter Only Hardforks](https://eips.ethereum.org/EIPS/eip-7892)
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
use safe_arith::SafeArith;
|
||||
use std::mem;
|
||||
use types::{BeaconState, BeaconStateError as Error, BeaconStateFulu, ChainSpec, EthSpec, Fork};
|
||||
use types::{
|
||||
BeaconState, BeaconStateError as Error, BeaconStateFulu, ChainSpec, EthSpec, Fork, Vector,
|
||||
};
|
||||
|
||||
/// Transform a `Electra` state into an `Fulu` state.
|
||||
pub fn upgrade_to_fulu<E: EthSpec>(
|
||||
@@ -15,11 +18,32 @@ pub fn upgrade_to_fulu<E: EthSpec>(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn initialize_proposer_lookahead<E: EthSpec>(
|
||||
state: &BeaconState<E>,
|
||||
spec: &ChainSpec,
|
||||
) -> Result<Vector<u64, E::ProposerLookaheadSlots>, Error> {
|
||||
let current_epoch = state.current_epoch();
|
||||
let mut lookahead = Vec::with_capacity(E::proposer_lookahead_slots());
|
||||
for i in 0..(spec.min_seed_lookahead.safe_add(1)?.as_u64()) {
|
||||
let target_epoch = current_epoch.safe_add(i)?;
|
||||
lookahead.extend(
|
||||
state
|
||||
.get_beacon_proposer_indices(target_epoch, spec)
|
||||
.map(|vec| vec.into_iter().map(|x| x as u64))?,
|
||||
);
|
||||
}
|
||||
|
||||
Vector::new(lookahead).map_err(|e| {
|
||||
Error::PleaseNotifyTheDevs(format!("Failed to initialize proposer lookahead: {:?}", e))
|
||||
})
|
||||
}
|
||||
|
||||
pub fn upgrade_state_to_fulu<E: EthSpec>(
|
||||
pre_state: &mut BeaconState<E>,
|
||||
spec: &ChainSpec,
|
||||
) -> Result<BeaconState<E>, Error> {
|
||||
let epoch = pre_state.current_epoch();
|
||||
let proposer_lookahead = initialize_proposer_lookahead(pre_state, spec)?;
|
||||
let pre = pre_state.as_electra_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`.
|
||||
@@ -89,6 +113,7 @@ pub fn upgrade_state_to_fulu<E: EthSpec>(
|
||||
exit_cache: mem::take(&mut pre.exit_cache),
|
||||
slashings_cache: mem::take(&mut pre.slashings_cache),
|
||||
epoch_cache: mem::take(&mut pre.epoch_cache),
|
||||
proposer_lookahead,
|
||||
});
|
||||
Ok(post)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user