mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-03 00:31:50 +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:
@@ -30,6 +30,7 @@ pub enum EpochProcessingError {
|
||||
MissingEarliestExitEpoch,
|
||||
MissingExitBalanceToConsume,
|
||||
PendingDepositsLogicError,
|
||||
ProposerLookaheadOutOfBounds(usize),
|
||||
}
|
||||
|
||||
impl From<InclusionError> for EpochProcessingError {
|
||||
|
||||
@@ -19,7 +19,7 @@ use types::{
|
||||
milhouse::Cow,
|
||||
ActivationQueue, BeaconState, BeaconStateError, ChainSpec, Checkpoint, DepositData, Epoch,
|
||||
EthSpec, ExitCache, ForkName, List, ParticipationFlags, PendingDeposit,
|
||||
ProgressiveBalancesCache, RelativeEpoch, Unsigned, Validator,
|
||||
ProgressiveBalancesCache, RelativeEpoch, Unsigned, Validator, Vector,
|
||||
};
|
||||
|
||||
pub struct SinglePassConfig {
|
||||
@@ -30,6 +30,7 @@ pub struct SinglePassConfig {
|
||||
pub pending_deposits: bool,
|
||||
pub pending_consolidations: bool,
|
||||
pub effective_balance_updates: bool,
|
||||
pub proposer_lookahead: bool,
|
||||
}
|
||||
|
||||
impl Default for SinglePassConfig {
|
||||
@@ -48,6 +49,7 @@ impl SinglePassConfig {
|
||||
pending_deposits: true,
|
||||
pending_consolidations: true,
|
||||
effective_balance_updates: true,
|
||||
proposer_lookahead: true,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,6 +62,7 @@ impl SinglePassConfig {
|
||||
pending_deposits: false,
|
||||
pending_consolidations: false,
|
||||
effective_balance_updates: false,
|
||||
proposer_lookahead: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -460,9 +463,43 @@ pub fn process_epoch_single_pass<E: EthSpec>(
|
||||
next_epoch_cache.into_epoch_cache(next_epoch_activation_queue, spec)?;
|
||||
}
|
||||
|
||||
if conf.proposer_lookahead && fork_name.fulu_enabled() {
|
||||
process_proposer_lookahead(state, spec)?;
|
||||
}
|
||||
|
||||
Ok(summary)
|
||||
}
|
||||
|
||||
// TOOO(EIP-7917): use balances cache
|
||||
pub fn process_proposer_lookahead<E: EthSpec>(
|
||||
state: &mut BeaconState<E>,
|
||||
spec: &ChainSpec,
|
||||
) -> Result<(), Error> {
|
||||
let mut lookahead = state.proposer_lookahead()?.clone().to_vec();
|
||||
|
||||
// Shift out proposers in the first epoch
|
||||
lookahead.copy_within((E::slots_per_epoch() as usize).., 0);
|
||||
|
||||
let next_epoch = state
|
||||
.current_epoch()
|
||||
.safe_add(spec.min_seed_lookahead.as_u64())?
|
||||
.safe_add(1)?;
|
||||
let last_epoch_proposers = state.get_beacon_proposer_indices(next_epoch, spec)?;
|
||||
|
||||
// Fill in the last epoch with new proposer indices
|
||||
let last_epoch_start = E::proposer_lookahead_slots().safe_sub(E::slots_per_epoch() as usize)?;
|
||||
for (i, proposer) in last_epoch_proposers.into_iter().enumerate() {
|
||||
let index = last_epoch_start.safe_add(i)?;
|
||||
*lookahead
|
||||
.get_mut(index)
|
||||
.ok_or(Error::ProposerLookaheadOutOfBounds(index))? = proposer as u64;
|
||||
}
|
||||
|
||||
*state.proposer_lookahead_mut()? = Vector::new(lookahead)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn process_single_inactivity_update(
|
||||
inactivity_score: &mut Cow<u64>,
|
||||
validator_info: &ValidatorInfo,
|
||||
|
||||
@@ -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