mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-27 09:43:36 +00:00
Update to spec v1.7.0-alpha.4 (#9046)
Update our consensus code to v1.7.0-alpha.4 Co-Authored-By: Michael Sproul <michael@sigmaprime.io>
This commit is contained in:
@@ -51,8 +51,8 @@ pub fn process_epoch<E: EthSpec>(
|
||||
// without loss of correctness.
|
||||
let current_epoch_progressive_balances = state.progressive_balances_cache().clone();
|
||||
let current_epoch_total_active_balance = state.get_total_active_balance()?;
|
||||
let participation_summary =
|
||||
process_epoch_single_pass(state, spec, SinglePassConfig::default())?;
|
||||
let epoch_result = process_epoch_single_pass(state, spec, SinglePassConfig::default())?;
|
||||
let participation_summary = epoch_result.summary;
|
||||
|
||||
// Reset eth1 data votes.
|
||||
process_eth1_data_reset(state)?;
|
||||
@@ -79,6 +79,13 @@ pub fn process_epoch<E: EthSpec>(
|
||||
|
||||
// Rotate the epoch caches to suit the epoch transition.
|
||||
state.advance_caches()?;
|
||||
|
||||
// Install the lookahead committee cache (built during PTC window processing) as the Next
|
||||
// cache. After advance_caches, the lookahead epoch becomes the Next relative epoch.
|
||||
if let Some(cache) = epoch_result.lookahead_committee_cache {
|
||||
state.set_committee_cache(RelativeEpoch::Next, cache)?;
|
||||
}
|
||||
|
||||
update_progressive_balances_on_epoch_transition(state, spec)?;
|
||||
|
||||
Ok(EpochProcessingSummary::Altair {
|
||||
|
||||
@@ -12,12 +12,13 @@ use milhouse::{Cow, List, Vector};
|
||||
use safe_arith::{SafeArith, SafeArithIter};
|
||||
use std::cmp::{max, min};
|
||||
use std::collections::{BTreeSet, HashMap};
|
||||
use std::sync::Arc;
|
||||
use tracing::instrument;
|
||||
use typenum::Unsigned;
|
||||
use types::{
|
||||
ActivationQueue, BeaconState, BeaconStateError, BuilderPendingPayment, ChainSpec, Checkpoint,
|
||||
DepositData, Epoch, EthSpec, ExitCache, ForkName, ParticipationFlags, PendingDeposit,
|
||||
ProgressiveBalancesCache, RelativeEpoch, Validator,
|
||||
CommitteeCache, DepositData, Epoch, EthSpec, ExitCache, ForkName, ParticipationFlags,
|
||||
PendingDeposit, ProgressiveBalancesCache, RelativeEpoch, Validator,
|
||||
consts::altair::{
|
||||
NUM_FLAG_INDICES, PARTICIPATION_FLAG_WEIGHTS, TIMELY_HEAD_FLAG_INDEX,
|
||||
TIMELY_TARGET_FLAG_INDEX, WEIGHT_DENOMINATOR,
|
||||
@@ -34,6 +35,7 @@ pub struct SinglePassConfig {
|
||||
pub effective_balance_updates: bool,
|
||||
pub proposer_lookahead: bool,
|
||||
pub builder_pending_payments: bool,
|
||||
pub ptc_window: bool,
|
||||
}
|
||||
|
||||
impl Default for SinglePassConfig {
|
||||
@@ -54,6 +56,7 @@ impl SinglePassConfig {
|
||||
effective_balance_updates: true,
|
||||
proposer_lookahead: true,
|
||||
builder_pending_payments: true,
|
||||
ptc_window: true,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,6 +71,7 @@ impl SinglePassConfig {
|
||||
effective_balance_updates: false,
|
||||
proposer_lookahead: false,
|
||||
builder_pending_payments: false,
|
||||
ptc_window: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -139,12 +143,20 @@ impl ValidatorInfo {
|
||||
}
|
||||
}
|
||||
|
||||
/// Result of single-pass epoch processing.
|
||||
pub struct SinglePassEpochResult<E: EthSpec> {
|
||||
pub summary: ParticipationEpochSummary<E>,
|
||||
/// Committee cache for the lookahead epoch, built during PTC window processing.
|
||||
/// Can be installed as the Next committee cache after `advance_caches`.
|
||||
pub lookahead_committee_cache: Option<Arc<CommitteeCache>>,
|
||||
}
|
||||
|
||||
#[instrument(skip_all)]
|
||||
pub fn process_epoch_single_pass<E: EthSpec>(
|
||||
state: &mut BeaconState<E>,
|
||||
spec: &ChainSpec,
|
||||
conf: SinglePassConfig,
|
||||
) -> Result<ParticipationEpochSummary<E>, Error> {
|
||||
) -> Result<SinglePassEpochResult<E>, Error> {
|
||||
initialize_epoch_cache(state, spec)?;
|
||||
initialize_progressive_balances_cache(state, spec)?;
|
||||
state.build_exit_cache(spec)?;
|
||||
@@ -479,7 +491,16 @@ pub fn process_epoch_single_pass<E: EthSpec>(
|
||||
process_proposer_lookahead(state, spec)?;
|
||||
}
|
||||
|
||||
Ok(summary)
|
||||
let lookahead_committee_cache = if conf.ptc_window && fork_name.gloas_enabled() {
|
||||
Some(process_ptc_window(state, spec)?)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
Ok(SinglePassEpochResult {
|
||||
summary,
|
||||
lookahead_committee_cache,
|
||||
})
|
||||
}
|
||||
|
||||
// TOOO(EIP-7917): use balances cache
|
||||
@@ -512,6 +533,53 @@ pub fn process_proposer_lookahead<E: EthSpec>(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Process the PTC window, returning the committee cache built for the lookahead epoch.
|
||||
///
|
||||
/// The returned cache can be injected into the state's Next committee cache slot after
|
||||
/// `advance_caches` is called during the epoch transition, avoiding redundant recomputation.
|
||||
pub fn process_ptc_window<E: EthSpec>(
|
||||
state: &mut BeaconState<E>,
|
||||
spec: &ChainSpec,
|
||||
) -> Result<Arc<CommitteeCache>, Error> {
|
||||
let slots_per_epoch = E::slots_per_epoch() as usize;
|
||||
|
||||
// Convert Vector -> List to use tree-efficient pop_front.
|
||||
let ptc_window = state.ptc_window()?.clone();
|
||||
let mut window: List<_, E::PtcWindowLength> = List::from(ptc_window);
|
||||
|
||||
// Drop the oldest epoch from the front (reuses shared tree nodes).
|
||||
window
|
||||
.pop_front(slots_per_epoch)
|
||||
.map_err(|e| Error::BeaconStateError(BeaconStateError::MilhouseError(e)))?;
|
||||
|
||||
// Compute PTC for the new lookahead epoch
|
||||
let next_epoch = state
|
||||
.current_epoch()
|
||||
.safe_add(spec.min_seed_lookahead.as_u64())?
|
||||
.safe_add(1)?;
|
||||
let start_slot = next_epoch.start_slot(E::slots_per_epoch());
|
||||
|
||||
// Build a committee cache for the lookahead epoch (beyond the normal Next bound)
|
||||
let committee_cache = state.initialize_committee_cache_for_lookahead(next_epoch, spec)?;
|
||||
|
||||
for i in 0..slots_per_epoch {
|
||||
let slot = start_slot.safe_add(i as u64)?;
|
||||
let ptc = state.compute_ptc_with_cache(slot, &committee_cache, spec)?;
|
||||
let ptc_u64: Vec<u64> = ptc.into_iter().map(|v| v as u64).collect();
|
||||
let entry = ssz_types::FixedVector::new(ptc_u64)
|
||||
.map_err(|e| Error::BeaconStateError(BeaconStateError::SszTypesError(e)))?;
|
||||
window
|
||||
.push(entry)
|
||||
.map_err(|e| Error::BeaconStateError(BeaconStateError::MilhouseError(e)))?;
|
||||
}
|
||||
|
||||
// Convert List back to Vector.
|
||||
*state.ptc_window_mut()? = Vector::try_from(window)
|
||||
.map_err(|e| Error::BeaconStateError(BeaconStateError::MilhouseError(e)))?;
|
||||
|
||||
Ok(committee_cache)
|
||||
}
|
||||
|
||||
/// Calculate the quorum threshold for builder payments based on total active balance.
|
||||
fn get_builder_payment_quorum_threshold<E: EthSpec>(
|
||||
state_ctxt: &StateContext,
|
||||
|
||||
@@ -2,7 +2,9 @@ use crate::per_block_processing::{
|
||||
is_valid_deposit_signature, process_operations::apply_deposit_for_builder,
|
||||
};
|
||||
use milhouse::{List, Vector};
|
||||
use safe_arith::SafeArith;
|
||||
use ssz_types::BitVector;
|
||||
use ssz_types::FixedVector;
|
||||
use std::collections::HashSet;
|
||||
use std::mem;
|
||||
use typenum::Unsigned;
|
||||
@@ -102,13 +104,11 @@ pub fn upgrade_state_to_gloas<E: EthSpec>(
|
||||
vec![0xFFu8; E::SlotsPerHistoricalRoot::to_usize() / 8].into(),
|
||||
)
|
||||
.map_err(|_| Error::InvalidBitfield)?,
|
||||
builder_pending_payments: Vector::new(vec![
|
||||
BuilderPendingPayment::default();
|
||||
E::builder_pending_payments_limit()
|
||||
])?,
|
||||
builder_pending_payments: Vector::from_elem(BuilderPendingPayment::default())?,
|
||||
builder_pending_withdrawals: List::default(), // Empty list initially,
|
||||
latest_block_hash: pre.latest_execution_payload_header.block_hash,
|
||||
payload_expected_withdrawals: List::default(),
|
||||
ptc_window: Vector::from_elem(FixedVector::from_elem(0))?, // placeholder, will be initialized below
|
||||
// Caches
|
||||
total_active_balance: pre.total_active_balance,
|
||||
progressive_balances_cache: mem::take(&mut pre.progressive_balances_cache),
|
||||
@@ -120,10 +120,45 @@ pub fn upgrade_state_to_gloas<E: EthSpec>(
|
||||
});
|
||||
// [New in Gloas:EIP7732]
|
||||
onboard_builders_from_pending_deposits(&mut post, spec)?;
|
||||
initialize_ptc_window(&mut post, spec)?;
|
||||
|
||||
Ok(post)
|
||||
}
|
||||
|
||||
/// Initialize the `ptc_window` field in the beacon state at fork transition.
|
||||
///
|
||||
/// The window contains:
|
||||
/// - One epoch of empty entries (previous epoch)
|
||||
/// - Computed PTC for the current epoch through `1 + MIN_SEED_LOOKAHEAD` epochs
|
||||
fn initialize_ptc_window<E: EthSpec>(
|
||||
state: &mut BeaconState<E>,
|
||||
spec: &ChainSpec,
|
||||
) -> Result<(), Error> {
|
||||
let slots_per_epoch = E::slots_per_epoch() as usize;
|
||||
|
||||
let empty_previous_epoch = vec![FixedVector::<u64, E::PTCSize>::from_elem(0); slots_per_epoch];
|
||||
let mut ptcs = empty_previous_epoch;
|
||||
|
||||
// Compute PTC for current epoch + lookahead epochs
|
||||
let current_epoch = state.current_epoch();
|
||||
for e in 0..=spec.min_seed_lookahead.as_u64() {
|
||||
let epoch = current_epoch.safe_add(e)?;
|
||||
let committee_cache = state.initialize_committee_cache_for_lookahead(epoch, spec)?;
|
||||
let start_slot = epoch.start_slot(E::slots_per_epoch());
|
||||
for i in 0..slots_per_epoch {
|
||||
let slot = start_slot.safe_add(i as u64)?;
|
||||
let ptc = state.compute_ptc_with_cache(slot, &committee_cache, spec)?;
|
||||
let ptc_u64: Vec<u64> = ptc.into_iter().map(|v| v as u64).collect();
|
||||
let entry = FixedVector::new(ptc_u64)?;
|
||||
ptcs.push(entry);
|
||||
}
|
||||
}
|
||||
|
||||
*state.ptc_window_mut()? = Vector::new(ptcs)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Applies any pending deposit for builders, effectively onboarding builders at the fork.
|
||||
fn onboard_builders_from_pending_deposits<E: EthSpec>(
|
||||
state: &mut BeaconState<E>,
|
||||
|
||||
@@ -6,9 +6,9 @@ use std::{
|
||||
use safe_arith::{ArithError, SafeArith};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use typenum::{
|
||||
U0, U1, U2, U4, U8, U16, U17, U32, U64, U128, U256, U512, U625, U1024, U2048, U4096, U8192,
|
||||
U16384, U65536, U131072, U262144, U1048576, U16777216, U33554432, U134217728, U1073741824,
|
||||
U1099511627776, UInt, Unsigned, bit::B0,
|
||||
U0, U1, U2, U4, U8, U16, U17, U24, U32, U48, U64, U96, U128, U256, U512, U625, U1024, U2048,
|
||||
U4096, U8192, U16384, U65536, U131072, U262144, U1048576, U16777216, U33554432, U134217728,
|
||||
U1073741824, U1099511627776, UInt, Unsigned, bit::B0,
|
||||
};
|
||||
|
||||
use crate::core::{ChainSpec, Epoch};
|
||||
@@ -176,6 +176,7 @@ pub trait EthSpec: 'static + Default + Sync + Send + Clone + Debug + PartialEq +
|
||||
* New in Gloas
|
||||
*/
|
||||
type PTCSize: Unsigned + Clone + Sync + Send + Debug + PartialEq;
|
||||
type PtcWindowLength: Unsigned + Clone + Sync + Send + Debug + PartialEq;
|
||||
type MaxPayloadAttestations: Unsigned + Clone + Sync + Send + Debug + PartialEq;
|
||||
type BuilderPendingPaymentsLimit: Unsigned + Clone + Sync + Send + Debug + PartialEq;
|
||||
type BuilderPendingWithdrawalsLimit: Unsigned + Clone + Sync + Send + Debug + PartialEq;
|
||||
@@ -428,6 +429,11 @@ pub trait EthSpec: 'static + Default + Sync + Send + Clone + Debug + PartialEq +
|
||||
Self::PTCSize::to_usize()
|
||||
}
|
||||
|
||||
/// Returns the `PtcWindowLength` constant for this specification.
|
||||
fn ptc_window_length() -> usize {
|
||||
Self::PtcWindowLength::to_usize()
|
||||
}
|
||||
|
||||
/// Returns the `MaxPayloadAttestations` constant for this specification.
|
||||
fn max_payload_attestations() -> usize {
|
||||
Self::MaxPayloadAttestations::to_usize()
|
||||
@@ -515,6 +521,7 @@ impl EthSpec for MainnetEthSpec {
|
||||
type MaxWithdrawalRequestsPerPayload = U16;
|
||||
type MaxPendingDepositsPerEpoch = U16;
|
||||
type PTCSize = U512;
|
||||
type PtcWindowLength = U96; // (2 + MIN_SEED_LOOKAHEAD) * SLOTS_PER_EPOCH
|
||||
type MaxPayloadAttestations = U4;
|
||||
type MaxBuildersPerWithdrawalsSweep = U16384;
|
||||
|
||||
@@ -561,6 +568,7 @@ impl EthSpec for MinimalEthSpec {
|
||||
type ProposerLookaheadSlots = U16; // Derived from (MIN_SEED_LOOKAHEAD + 1) * SLOTS_PER_EPOCH
|
||||
type BuilderPendingPaymentsLimit = U16; // 2 * SLOTS_PER_EPOCH = 2 * 8 = 16
|
||||
type PTCSize = U2;
|
||||
type PtcWindowLength = U24; // (2 + MIN_SEED_LOOKAHEAD) * SLOTS_PER_EPOCH
|
||||
type MaxBuildersPerWithdrawalsSweep = U16;
|
||||
|
||||
params_from_eth_spec!(MainnetEthSpec {
|
||||
@@ -668,6 +676,7 @@ impl EthSpec for GnosisEthSpec {
|
||||
type ProposerLookaheadSlots = U32; // Derived from (MIN_SEED_LOOKAHEAD + 1) * SLOTS_PER_EPOCH
|
||||
type BuilderRegistryLimit = U1099511627776;
|
||||
type PTCSize = U512;
|
||||
type PtcWindowLength = U48; // (2 + MIN_SEED_LOOKAHEAD) * SLOTS_PER_EPOCH
|
||||
type MaxPayloadAttestations = U2;
|
||||
type MaxBuildersPerWithdrawalsSweep = U16384;
|
||||
|
||||
@@ -694,6 +703,11 @@ mod test {
|
||||
E::proposer_lookahead_slots(),
|
||||
(spec.min_seed_lookahead.as_usize() + 1) * E::slots_per_epoch() as usize
|
||||
);
|
||||
assert_eq!(
|
||||
E::ptc_window_length(),
|
||||
(spec.min_seed_lookahead.as_usize() + 2) * E::slots_per_epoch() as usize,
|
||||
"PtcWindowLength must equal (2 + MIN_SEED_LOOKAHEAD) * SLOTS_PER_EPOCH"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -667,6 +667,11 @@ where
|
||||
#[superstruct(only(Gloas))]
|
||||
pub payload_expected_withdrawals: List<Withdrawal, E::MaxWithdrawalsPerPayload>,
|
||||
|
||||
#[compare_fields(as_iter)]
|
||||
#[test_random(default)]
|
||||
#[superstruct(only(Gloas))]
|
||||
pub ptc_window: Vector<FixedVector<u64, E::PTCSize>, E::PtcWindowLength>,
|
||||
|
||||
// Caching (not in the spec)
|
||||
#[serde(skip_serializing, skip_deserializing)]
|
||||
#[ssz(skip_serializing, skip_deserializing)]
|
||||
@@ -2431,6 +2436,18 @@ impl<E: EthSpec> BeaconState<E> {
|
||||
CommitteeCache::initialized(self, epoch, spec)
|
||||
}
|
||||
|
||||
/// Like [`initialize_committee_cache`](Self::initialize_committee_cache), but allows epochs
|
||||
/// beyond `current_epoch + 1`. Only checks that the required randao seed is available.
|
||||
///
|
||||
/// Used by PTC window computation which needs shufflings for lookahead epochs.
|
||||
pub fn initialize_committee_cache_for_lookahead(
|
||||
&self,
|
||||
epoch: Epoch,
|
||||
spec: &ChainSpec,
|
||||
) -> Result<Arc<CommitteeCache>, BeaconStateError> {
|
||||
CommitteeCache::initialized_for_lookahead(self, epoch, spec)
|
||||
}
|
||||
|
||||
/// Advances the cache for this state into the next epoch.
|
||||
///
|
||||
/// This should be used if the `slot` of this state is advanced beyond an epoch boundary.
|
||||
@@ -2501,6 +2518,17 @@ impl<E: EthSpec> BeaconState<E> {
|
||||
.ok_or(BeaconStateError::CommitteeCachesOutOfBounds(index))
|
||||
}
|
||||
|
||||
/// Set the committee cache for the given `relative_epoch` to `cache`.
|
||||
pub fn set_committee_cache(
|
||||
&mut self,
|
||||
relative_epoch: RelativeEpoch,
|
||||
cache: Arc<CommitteeCache>,
|
||||
) -> Result<(), BeaconStateError> {
|
||||
let i = Self::committee_cache_index(relative_epoch);
|
||||
*self.committee_cache_at_index_mut(i)? = cache;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Returns the cache for some `RelativeEpoch`. Returns an error if the cache has not been
|
||||
/// initialized.
|
||||
pub fn committee_cache(
|
||||
@@ -3084,12 +3112,55 @@ impl<E: EthSpec> BeaconState<E> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Get the payload timeliness committee for the given `slot`.
|
||||
///
|
||||
/// Requires the committee cache to be initialized.
|
||||
/// TODO(EIP-7732): definitely gonna have to cache this..
|
||||
/// Get the payload timeliness committee for the given `slot` from the `ptc_window`.
|
||||
pub fn get_ptc(&self, slot: Slot, spec: &ChainSpec) -> Result<PTC<E>, BeaconStateError> {
|
||||
let ptc_window = self.ptc_window()?;
|
||||
let epoch = slot.epoch(E::slots_per_epoch());
|
||||
let state_epoch = self.current_epoch();
|
||||
let slots_per_epoch = E::slots_per_epoch() as usize;
|
||||
let slot_in_epoch = slot.as_usize().safe_rem(slots_per_epoch)?;
|
||||
|
||||
let index = if epoch < state_epoch {
|
||||
if epoch.safe_add(1)? != state_epoch {
|
||||
return Err(BeaconStateError::SlotOutOfBounds);
|
||||
}
|
||||
slot_in_epoch
|
||||
} else {
|
||||
if epoch > state_epoch.safe_add(spec.min_seed_lookahead)? {
|
||||
return Err(BeaconStateError::SlotOutOfBounds);
|
||||
}
|
||||
let offset = epoch
|
||||
.safe_sub(state_epoch)?
|
||||
.safe_add(1)?
|
||||
.as_usize()
|
||||
.safe_mul(slots_per_epoch)?;
|
||||
offset.safe_add(slot_in_epoch)?
|
||||
};
|
||||
|
||||
let entry = ptc_window
|
||||
.get(index)
|
||||
.ok_or(BeaconStateError::SlotOutOfBounds)?;
|
||||
|
||||
// Convert from FixedVector<u64, PTCSize> to PTC<E> (FixedVector<usize, PTCSize>)
|
||||
let indices: Vec<usize> = entry.iter().map(|&v| v as usize).collect();
|
||||
Ok(PTC(FixedVector::new(indices)?))
|
||||
}
|
||||
|
||||
/// Compute the payload timeliness committee for the given `slot` from scratch.
|
||||
///
|
||||
/// Requires the committee cache to be initialized for the slot's epoch.
|
||||
pub fn compute_ptc(&self, slot: Slot, spec: &ChainSpec) -> Result<PTC<E>, BeaconStateError> {
|
||||
let committee_cache = self.committee_cache_at_slot(slot)?;
|
||||
self.compute_ptc_with_cache(slot, committee_cache, spec)
|
||||
}
|
||||
|
||||
/// Compute the PTC for a slot using a specific committee cache.
|
||||
pub fn compute_ptc_with_cache(
|
||||
&self,
|
||||
slot: Slot,
|
||||
committee_cache: &CommitteeCache,
|
||||
spec: &ChainSpec,
|
||||
) -> Result<PTC<E>, BeaconStateError> {
|
||||
let committees = committee_cache.get_beacon_committees_at_slot(slot)?;
|
||||
|
||||
let seed = self.get_ptc_attester_seed(slot, spec)?;
|
||||
|
||||
@@ -62,6 +62,9 @@ fn compare_shuffling_positions(xs: &Vec<NonZeroUsizeOption>, ys: &Vec<NonZeroUsi
|
||||
impl CommitteeCache {
|
||||
/// Return a new, fully initialized cache.
|
||||
///
|
||||
/// The epoch must be within the range that the state can service: historic epochs with
|
||||
/// available randao data, up to `current_epoch + 1` (the "next" epoch).
|
||||
///
|
||||
/// Spec v0.12.1
|
||||
pub fn initialized<E: EthSpec>(
|
||||
state: &BeaconState<E>,
|
||||
@@ -81,12 +84,44 @@ impl CommitteeCache {
|
||||
|| epoch
|
||||
> state
|
||||
.current_epoch()
|
||||
.safe_add(1)
|
||||
.safe_add(1u64)
|
||||
.map_err(BeaconStateError::ArithError)?
|
||||
{
|
||||
return Err(BeaconStateError::EpochOutOfBounds);
|
||||
}
|
||||
|
||||
Self::initialized_unchecked(state, epoch, spec)
|
||||
}
|
||||
|
||||
/// Return a new, fully initialized cache for a lookahead epoch.
|
||||
///
|
||||
/// Like [`initialized`](Self::initialized), but allows epochs beyond `current_epoch + 1`.
|
||||
/// The only bound enforced is that the required randao seed is available in the state.
|
||||
///
|
||||
/// This is used by PTC window computation, which needs committee shufflings for
|
||||
/// `current_epoch + 1 + MIN_SEED_LOOKAHEAD`.
|
||||
pub fn initialized_for_lookahead<E: EthSpec>(
|
||||
state: &BeaconState<E>,
|
||||
epoch: Epoch,
|
||||
spec: &ChainSpec,
|
||||
) -> Result<Arc<CommitteeCache>, BeaconStateError> {
|
||||
let reqd_randao_epoch = epoch
|
||||
.saturating_sub(spec.min_seed_lookahead)
|
||||
.saturating_sub(1u64);
|
||||
|
||||
if reqd_randao_epoch < state.min_randao_epoch() {
|
||||
return Err(BeaconStateError::EpochOutOfBounds);
|
||||
}
|
||||
|
||||
Self::initialized_unchecked(state, epoch, spec)
|
||||
}
|
||||
|
||||
/// Core committee cache construction. Callers are responsible for bounds-checking `epoch`.
|
||||
fn initialized_unchecked<E: EthSpec>(
|
||||
state: &BeaconState<E>,
|
||||
epoch: Epoch,
|
||||
spec: &ChainSpec,
|
||||
) -> Result<Arc<CommitteeCache>, BeaconStateError> {
|
||||
// May cause divide-by-zero errors.
|
||||
if E::slots_per_epoch() == 0 {
|
||||
return Err(BeaconStateError::ZeroSlotsPerEpoch);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# To download/extract nightly tests, run:
|
||||
# CONSENSUS_SPECS_TEST_VERSION=nightly make
|
||||
CONSENSUS_SPECS_TEST_VERSION ?= v1.7.0-alpha.3
|
||||
CONSENSUS_SPECS_TEST_VERSION ?= v1.7.0-alpha.4
|
||||
REPO_NAME := consensus-spec-tests
|
||||
OUTPUT_DIR := ./$(REPO_NAME)
|
||||
|
||||
|
||||
@@ -53,6 +53,8 @@ excluded_paths = [
|
||||
"tests/.*/gloas/fork_choice/.*",
|
||||
# Ignore MatrixEntry SSZ tests for now.
|
||||
"tests/.*/.*/ssz_static/MatrixEntry/.*",
|
||||
# TODO: partial data column not implemented yet
|
||||
"tests/.*/.*/ssz_static/PartialDataColumn.*/.*",
|
||||
# TODO(gloas): Ignore Gloas light client stuff for now
|
||||
"tests/.*/gloas/ssz_static/LightClient.*/.*",
|
||||
# Execution payload header is irrelevant after Gloas, this type will probably be deleted.
|
||||
@@ -73,7 +75,9 @@ excluded_paths = [
|
||||
"tests/.*/compute_verify_cell_kzg_proof_batch_challenge/.*",
|
||||
"tests/.*/compute_challenge/.*",
|
||||
# We don't need these manifest files at the moment.
|
||||
"tests/.*/manifest.yaml"
|
||||
"tests/.*/manifest.yaml",
|
||||
# TODO: gossip condition tests not implemented yet
|
||||
"tests/.*/.*/networking/.*"
|
||||
]
|
||||
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ use state_processing::per_epoch_processing::effective_balance_updates::{
|
||||
process_effective_balance_updates, process_effective_balance_updates_slow,
|
||||
};
|
||||
use state_processing::per_epoch_processing::single_pass::{
|
||||
SinglePassConfig, process_epoch_single_pass, process_proposer_lookahead,
|
||||
SinglePassConfig, process_epoch_single_pass, process_proposer_lookahead, process_ptc_window,
|
||||
};
|
||||
use state_processing::per_epoch_processing::{
|
||||
altair, base,
|
||||
@@ -80,6 +80,8 @@ pub struct ParticipationFlagUpdates;
|
||||
#[derive(Debug)]
|
||||
pub struct ProposerLookahead;
|
||||
#[derive(Debug)]
|
||||
pub struct PtcWindow;
|
||||
#[derive(Debug)]
|
||||
pub struct BuilderPendingPayments;
|
||||
|
||||
type_name!(
|
||||
@@ -102,6 +104,7 @@ type_name!(SyncCommitteeUpdates, "sync_committee_updates");
|
||||
type_name!(InactivityUpdates, "inactivity_updates");
|
||||
type_name!(ParticipationFlagUpdates, "participation_flag_updates");
|
||||
type_name!(ProposerLookahead, "proposer_lookahead");
|
||||
type_name!(PtcWindow, "ptc_window");
|
||||
type_name!(BuilderPendingPayments, "builder_pending_payments");
|
||||
|
||||
impl<E: EthSpec> EpochTransition<E> for JustificationAndFinalization {
|
||||
@@ -296,6 +299,16 @@ impl<E: EthSpec> EpochTransition<E> for ProposerLookahead {
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: EthSpec> EpochTransition<E> for PtcWindow {
|
||||
fn run(state: &mut BeaconState<E>, spec: &ChainSpec) -> Result<(), EpochProcessingError> {
|
||||
if state.fork_name_unchecked().gloas_enabled() {
|
||||
process_ptc_window(state, spec).map(|_| ())
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: EthSpec> EpochTransition<E> for BuilderPendingPayments {
|
||||
fn run(state: &mut BeaconState<E>, spec: &ChainSpec) -> Result<(), EpochProcessingError> {
|
||||
process_epoch_single_pass(
|
||||
@@ -373,7 +386,9 @@ impl<E: EthSpec, T: EpochTransition<E>> Case for EpochProcessing<E, T> {
|
||||
return false;
|
||||
}
|
||||
|
||||
if !fork_name.gloas_enabled() && T::name() == "builder_pending_payments" {
|
||||
if !fork_name.gloas_enabled()
|
||||
&& (T::name() == "builder_pending_payments" || T::name() == "ptc_window")
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -717,11 +717,7 @@ impl<E: EthSpec, O: Operation<E>> LoadCase for Operations<E, O> {
|
||||
// Check BLS setting here before SSZ deserialization, as most types require signatures
|
||||
// to be valid.
|
||||
let operation_path = path.join(O::filename());
|
||||
let (operation, bls_error) = if !operation_path.is_file() {
|
||||
// Some test cases (e.g. builder_voluntary_exit__success) have no operation file.
|
||||
// TODO(gloas): remove this once the test vectors are fixed
|
||||
(None, None)
|
||||
} else if metadata.bls_setting.unwrap_or_default().check().is_ok() {
|
||||
let (operation, bls_error) = if metadata.bls_setting.unwrap_or_default().check().is_ok() {
|
||||
match O::decode(&operation_path, fork_name, spec) {
|
||||
Ok(op) => (Some(op), None),
|
||||
Err(Error::InvalidBLSInput(error)) => (None, Some(error)),
|
||||
|
||||
@@ -3,7 +3,7 @@ pub use cases::{
|
||||
BuilderPendingPayments, Case, EffectiveBalanceUpdates, Eth1DataReset, ExecutionPayloadBidBlock,
|
||||
FeatureName, HistoricalRootsUpdate, HistoricalSummariesUpdate, InactivityUpdates,
|
||||
JustificationAndFinalization, ParticipationFlagUpdates, ParticipationRecordUpdates,
|
||||
PendingBalanceDeposits, PendingConsolidations, ProposerLookahead, RandaoMixesReset,
|
||||
PendingBalanceDeposits, PendingConsolidations, ProposerLookahead, PtcWindow, RandaoMixesReset,
|
||||
RegistryUpdates, RewardsAndPenalties, Slashings, SlashingsReset, SyncCommitteeUpdates,
|
||||
WithdrawalsPayload,
|
||||
};
|
||||
|
||||
@@ -960,6 +960,12 @@ fn epoch_processing_proposer_lookahead() {
|
||||
EpochProcessingHandler::<MainnetEthSpec, ProposerLookahead>::default().run();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn epoch_processing_ptc_window() {
|
||||
EpochProcessingHandler::<MinimalEthSpec, PtcWindow>::default().run();
|
||||
EpochProcessingHandler::<MainnetEthSpec, PtcWindow>::default().run();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn epoch_processing_builder_pending_payments() {
|
||||
EpochProcessingHandler::<MinimalEthSpec, BuilderPendingPayments>::default().run();
|
||||
|
||||
Reference in New Issue
Block a user