Add even more

This commit is contained in:
Mac L
2024-05-02 18:07:56 +10:00
parent d9a0c3d6c2
commit 5a4be377d4
18 changed files with 251 additions and 334 deletions

View File

@@ -30,7 +30,7 @@ use store::consts::altair::{
TIMELY_TARGET_FLAG_INDEX, TIMELY_TARGET_FLAG_INDEX,
}; };
use types::consts::altair::WEIGHT_DENOMINATOR; use types::consts::altair::WEIGHT_DENOMINATOR;
use types::{BeaconState, Epoch, EthSpec, RelativeEpoch}; use types::{BeaconState, Epoch, EthSpec, FeatureName, RelativeEpoch};
impl<T: BeaconChainTypes> BeaconChain<T> { impl<T: BeaconChainTypes> BeaconChain<T> {
pub fn compute_attestation_rewards( pub fn compute_attestation_rewards(
@@ -51,13 +51,10 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
.get_state(&state_root, Some(state_slot))? .get_state(&state_root, Some(state_slot))?
.ok_or(BeaconChainError::MissingBeaconState(state_root))?; .ok_or(BeaconChainError::MissingBeaconState(state_root))?;
match state { if state.has_feature(FeatureName::Altair) {
BeaconState::Base(_) => self.compute_attestation_rewards_base(state, validators), self.compute_attestation_rewards_altair(state, validators)
BeaconState::Altair(_) } else {
| BeaconState::Bellatrix(_) self.compute_attestation_rewards_base(state, validators)
| BeaconState::Capella(_)
| BeaconState::Deneb(_)
| BeaconState::Electra(_) => self.compute_attestation_rewards_altair(state, validators),
} }
} }

View File

@@ -4838,12 +4838,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
// If required, start the process of loading an execution payload from the EL early. This // If required, start the process of loading an execution payload from the EL early. This
// allows it to run concurrently with things like attestation packing. // allows it to run concurrently with things like attestation packing.
let prepare_payload_handle = match &state { let prepare_payload_handle = if state.has_feature(FeatureName::Bellatrix) {
BeaconState::Base(_) | BeaconState::Altair(_) => None,
BeaconState::Bellatrix(_)
| BeaconState::Capella(_)
| BeaconState::Deneb(_)
| BeaconState::Electra(_) => {
let prepare_payload_handle = get_execution_payload( let prepare_payload_handle = get_execution_payload(
self.clone(), self.clone(),
&state, &state,
@@ -4854,7 +4849,8 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
block_production_version, block_production_version,
)?; )?;
Some(prepare_payload_handle) Some(prepare_payload_handle)
} } else {
None
}; };
let (mut proposer_slashings, mut attester_slashings, mut voluntary_exits) = let (mut proposer_slashings, mut attester_slashings, mut voluntary_exits) =

View File

@@ -411,19 +411,16 @@ pub fn get_execution_payload<T: BeaconChainTypes>(
let random = *state.get_randao_mix(current_epoch)?; let random = *state.get_randao_mix(current_epoch)?;
let latest_execution_payload_header_block_hash = let latest_execution_payload_header_block_hash =
state.latest_execution_payload_header()?.block_hash(); state.latest_execution_payload_header()?.block_hash();
let withdrawals = match state { let withdrawals = if state.has_feature(FeatureName::Capella) {
&BeaconState::Capella(_) | &BeaconState::Deneb(_) | &BeaconState::Electra(_) => {
Some(get_expected_withdrawals(state, spec)?.into()) Some(get_expected_withdrawals(state, spec)?.into())
} } else {
&BeaconState::Bellatrix(_) => None, None
// These shouldn't happen but they're here to make the pattern irrefutable
&BeaconState::Base(_) | &BeaconState::Altair(_) => None,
}; };
let parent_beacon_block_root = match state {
BeaconState::Deneb(_) | BeaconState::Electra(_) => Some(parent_block_root), let parent_beacon_block_root = if state.has_feature(FeatureName::Deneb) {
BeaconState::Bellatrix(_) | BeaconState::Capella(_) => None, Some(parent_block_root)
// These shouldn't happen but they're here to make the pattern irrefutable } else {
BeaconState::Base(_) | BeaconState::Altair(_) => None, None
}; };
// Spawn a task to obtain the execution payload from the EL via a series of async calls. The // Spawn a task to obtain the execution payload from the EL via a series of async calls. The

View File

@@ -747,8 +747,8 @@ where
if let Some((parent_justified, parent_finalized)) = parent_checkpoints { if let Some((parent_justified, parent_finalized)) = parent_checkpoints {
(parent_justified, parent_finalized) (parent_justified, parent_finalized)
} else { } else {
let justification_and_finalization_state = let justification_and_finalization_state = if block.has_feature(FeatureName::Altair)
if block.fork_name_unchecked().has_feature(FeatureName::Altair) { {
// NOTE: Processing justification & finalization requires the progressive // NOTE: Processing justification & finalization requires the progressive
// balances cache, but we cannot initialize it here as we only have an // balances cache, but we cannot initialize it here as we only have an
// immutable reference. The state *should* have come straight from block // immutable reference. The state *should* have come straight from block

View File

@@ -7,7 +7,7 @@ use types::{
}, },
BeaconStateError as Error, BeaconStateError as Error,
}; };
use types::{AttestationData, BeaconState, ChainSpec, EthSpec}; use types::{AttestationData, BeaconState, ChainSpec, EthSpec, FeatureName};
/// Get the participation flags for a valid attestation. /// Get the participation flags for a valid attestation.
/// ///
@@ -44,22 +44,14 @@ pub fn get_attestation_participation_flag_indices<E: EthSpec>(
if is_matching_source && inclusion_delay <= E::slots_per_epoch().integer_sqrt() { if is_matching_source && inclusion_delay <= E::slots_per_epoch().integer_sqrt() {
participation_flag_indices.push(TIMELY_SOURCE_FLAG_INDEX); participation_flag_indices.push(TIMELY_SOURCE_FLAG_INDEX);
} }
match state {
&BeaconState::Base(_) if state.has_feature(FeatureName::Deneb) && is_matching_target {
| &BeaconState::Altair(_)
| &BeaconState::Bellatrix(_)
| &BeaconState::Capella(_) => {
if is_matching_target && inclusion_delay <= E::slots_per_epoch() {
participation_flag_indices.push(TIMELY_TARGET_FLAG_INDEX);
}
}
&BeaconState::Deneb(_) | &BeaconState::Electra(_) => {
if is_matching_target {
// [Modified in Deneb:EIP7045] // [Modified in Deneb:EIP7045]
participation_flag_indices.push(TIMELY_TARGET_FLAG_INDEX); participation_flag_indices.push(TIMELY_TARGET_FLAG_INDEX);
} else if is_matching_target && inclusion_delay <= E::slots_per_epoch() {
participation_flag_indices.push(TIMELY_TARGET_FLAG_INDEX);
} }
}
}
if is_matching_head && inclusion_delay == spec.min_attestation_inclusion_delay { if is_matching_head && inclusion_delay == spec.min_attestation_inclusion_delay {
participation_flag_indices.push(TIMELY_HEAD_FLAG_INDEX); participation_flag_indices.push(TIMELY_HEAD_FLAG_INDEX);
} }

View File

@@ -55,15 +55,12 @@ pub fn slash_validator<E: EthSpec>(
let whistleblower_index = opt_whistleblower_index.unwrap_or(proposer_index); let whistleblower_index = opt_whistleblower_index.unwrap_or(proposer_index);
let whistleblower_reward = let whistleblower_reward =
validator_effective_balance.safe_div(spec.whistleblower_reward_quotient)?; validator_effective_balance.safe_div(spec.whistleblower_reward_quotient)?;
let proposer_reward = match state { let proposer_reward = if state.has_feature(FeatureName::Altair) {
BeaconState::Base(_) => whistleblower_reward.safe_div(spec.proposer_reward_quotient)?, whistleblower_reward
BeaconState::Altair(_)
| BeaconState::Bellatrix(_)
| BeaconState::Capella(_)
| BeaconState::Deneb(_)
| BeaconState::Electra(_) => whistleblower_reward
.safe_mul(PROPOSER_WEIGHT)? .safe_mul(PROPOSER_WEIGHT)?
.safe_div(WEIGHT_DENOMINATOR)?, .safe_div(WEIGHT_DENOMINATOR)?
} else {
whistleblower_reward.safe_div(spec.proposer_reward_quotient)?
}; };
// Ensure the whistleblower index is in the validator registry. // Ensure the whistleblower index is in the validator registry.

View File

@@ -6,8 +6,8 @@ use crate::metrics::{
use crate::{BlockProcessingError, EpochProcessingError}; use crate::{BlockProcessingError, EpochProcessingError};
use lighthouse_metrics::set_gauge; use lighthouse_metrics::set_gauge;
use types::{ use types::{
is_progressive_balances_enabled, BeaconState, BeaconStateError, ChainSpec, Epoch, BeaconState, BeaconStateError, ChainSpec, Epoch, EpochTotalBalances, EthSpec, FeatureName,
EpochTotalBalances, EthSpec, ParticipationFlags, ProgressiveBalancesCache, Validator, ParticipationFlags, ProgressiveBalancesCache, Validator,
}; };
/// Initializes the `ProgressiveBalancesCache` if it is unbuilt. /// Initializes the `ProgressiveBalancesCache` if it is unbuilt.
@@ -15,7 +15,7 @@ pub fn initialize_progressive_balances_cache<E: EthSpec>(
state: &mut BeaconState<E>, state: &mut BeaconState<E>,
spec: &ChainSpec, spec: &ChainSpec,
) -> Result<(), BeaconStateError> { ) -> Result<(), BeaconStateError> {
if !is_progressive_balances_enabled(state) if !state.has_feature(FeatureName::Altair)
|| state.progressive_balances_cache().is_initialized() || state.progressive_balances_cache().is_initialized()
{ {
return Ok(()); return Ok(());
@@ -92,7 +92,7 @@ pub fn update_progressive_balances_on_attestation<E: EthSpec>(
validator_effective_balance: u64, validator_effective_balance: u64,
validator_slashed: bool, validator_slashed: bool,
) -> Result<(), BlockProcessingError> { ) -> Result<(), BlockProcessingError> {
if is_progressive_balances_enabled(state) { if state.has_feature(FeatureName::Altair) {
state.progressive_balances_cache_mut().on_new_attestation( state.progressive_balances_cache_mut().on_new_attestation(
epoch, epoch,
validator_slashed, validator_slashed,
@@ -109,7 +109,7 @@ pub fn update_progressive_balances_on_slashing<E: EthSpec>(
validator_index: usize, validator_index: usize,
validator_effective_balance: u64, validator_effective_balance: u64,
) -> Result<(), BlockProcessingError> { ) -> Result<(), BlockProcessingError> {
if is_progressive_balances_enabled(state) { if state.has_feature(FeatureName::Altair) {
let previous_epoch_participation = *state let previous_epoch_participation = *state
.previous_epoch_participation()? .previous_epoch_participation()?
.get(validator_index) .get(validator_index)
@@ -135,7 +135,7 @@ pub fn update_progressive_balances_on_epoch_transition<E: EthSpec>(
state: &mut BeaconState<E>, state: &mut BeaconState<E>,
spec: &ChainSpec, spec: &ChainSpec,
) -> Result<(), EpochProcessingError> { ) -> Result<(), EpochProcessingError> {
if is_progressive_balances_enabled(state) { if state.has_feature(FeatureName::Altair) {
state state
.progressive_balances_cache_mut() .progressive_balances_cache_mut()
.on_epoch_transition(spec)?; .on_epoch_transition(spec)?;

View File

@@ -188,7 +188,7 @@ pub fn per_block_processing<E: EthSpec, Payload: AbstractExecPayload<E>>(
)?; )?;
} }
if is_progressive_balances_enabled(state) { if state.has_feature(FeatureName::Altair) {
update_progressive_balances_metrics(state.progressive_balances_cache())?; update_progressive_balances_metrics(state.progressive_balances_cache())?;
} }
@@ -453,15 +453,17 @@ pub fn process_execution_payload<E: EthSpec, Payload: AbstractExecPayload<E>>(
/// repeatedly write code to treat these errors as false. /// repeatedly write code to treat these errors as false.
/// https://github.com/ethereum/consensus-specs/blob/dev/specs/bellatrix/beacon-chain.md#is_merge_transition_complete /// https://github.com/ethereum/consensus-specs/blob/dev/specs/bellatrix/beacon-chain.md#is_merge_transition_complete
pub fn is_merge_transition_complete<E: EthSpec>(state: &BeaconState<E>) -> bool { pub fn is_merge_transition_complete<E: EthSpec>(state: &BeaconState<E>) -> bool {
match state { if state.has_feature(FeatureName::Capella) {
true
} else if state.has_feature(FeatureName::Bellatrix) {
// We must check defaultness against the payload header with 0x0 roots, as that's what's meant // We must check defaultness against the payload header with 0x0 roots, as that's what's meant
// by `ExecutionPayloadHeader()` in the spec. // by `ExecutionPayloadHeader()` in the spec.
BeaconState::Bellatrix(_) => state state
.latest_execution_payload_header() .latest_execution_payload_header()
.map(|header| !header.is_default_with_zero_roots()) .map(|header| !header.is_default_with_zero_roots())
.unwrap_or(false), .unwrap_or(false)
BeaconState::Electra(_) | BeaconState::Deneb(_) | BeaconState::Capella(_) => true, } else {
BeaconState::Base(_) | BeaconState::Altair(_) => false, false
} }
} }
/// https://github.com/ethereum/consensus-specs/blob/dev/specs/bellatrix/beacon-chain.md#is_merge_transition_block /// https://github.com/ethereum/consensus-specs/blob/dev/specs/bellatrix/beacon-chain.md#is_merge_transition_block
@@ -556,9 +558,7 @@ pub fn process_withdrawals<E: EthSpec, Payload: AbstractExecPayload<E>>(
payload: Payload::Ref<'_>, payload: Payload::Ref<'_>,
spec: &ChainSpec, spec: &ChainSpec,
) -> Result<(), BlockProcessingError> { ) -> Result<(), BlockProcessingError> {
match state { if state.has_feature(FeatureName::Capella) {
BeaconState::Bellatrix(_) => Ok(()),
BeaconState::Capella(_) | BeaconState::Deneb(_) | BeaconState::Electra(_) => {
let expected_withdrawals = get_expected_withdrawals(state, spec)?; let expected_withdrawals = get_expected_withdrawals(state, spec)?;
let expected_root = expected_withdrawals.tree_hash_root(); let expected_root = expected_withdrawals.tree_hash_root();
let withdrawals_root = payload.withdrawals_root()?; let withdrawals_root = payload.withdrawals_root()?;
@@ -603,8 +603,7 @@ pub fn process_withdrawals<E: EthSpec, Payload: AbstractExecPayload<E>>(
} }
Ok(()) Ok(())
} } else {
// these shouldn't even be encountered but they're here for completeness Ok(())
BeaconState::Base(_) | BeaconState::Altair(_) => Ok(()),
} }
} }

View File

@@ -262,21 +262,7 @@ pub fn process_attestations<E: EthSpec, Payload: AbstractExecPayload<E>>(
ctxt: &mut ConsensusContext<E>, ctxt: &mut ConsensusContext<E>,
spec: &ChainSpec, spec: &ChainSpec,
) -> Result<(), BlockProcessingError> { ) -> Result<(), BlockProcessingError> {
match block_body { if block_body.has_feature(FeatureName::Altair) {
BeaconBlockBodyRef::Base(_) => {
base::process_attestations(
state,
block_body.attestations(),
verify_signatures,
ctxt,
spec,
)?;
}
BeaconBlockBodyRef::Altair(_)
| BeaconBlockBodyRef::Bellatrix(_)
| BeaconBlockBodyRef::Capella(_)
| BeaconBlockBodyRef::Deneb(_)
| BeaconBlockBodyRef::Electra(_) => {
altair_deneb::process_attestations( altair_deneb::process_attestations(
state, state,
block_body.attestations(), block_body.attestations(),
@@ -284,7 +270,14 @@ pub fn process_attestations<E: EthSpec, Payload: AbstractExecPayload<E>>(
ctxt, ctxt,
spec, spec,
)?; )?;
} } else {
base::process_attestations(
state,
block_body.attestations(),
verify_signatures,
ctxt,
spec,
)?;
} }
Ok(()) Ok(())
} }

View File

@@ -8,7 +8,7 @@ use std::borrow::Cow;
use tree_hash::TreeHash; use tree_hash::TreeHash;
use types::{ use types::{
AbstractExecPayload, AggregateSignature, AttesterSlashing, BeaconBlockRef, BeaconState, AbstractExecPayload, AggregateSignature, AttesterSlashing, BeaconBlockRef, BeaconState,
BeaconStateError, ChainSpec, DepositData, Domain, Epoch, EthSpec, Fork, Hash256, BeaconStateError, ChainSpec, DepositData, Domain, Epoch, EthSpec, FeatureName, Fork, Hash256,
InconsistentFork, IndexedAttestation, ProposerSlashing, PublicKey, PublicKeyBytes, Signature, InconsistentFork, IndexedAttestation, ProposerSlashing, PublicKey, PublicKeyBytes, Signature,
SignedAggregateAndProof, SignedBeaconBlock, SignedBeaconBlockHeader, SignedAggregateAndProof, SignedBeaconBlock, SignedBeaconBlockHeader,
SignedBlsToExecutionChange, SignedContributionAndProof, SignedRoot, SignedVoluntaryExit, SignedBlsToExecutionChange, SignedContributionAndProof, SignedRoot, SignedVoluntaryExit,
@@ -387,22 +387,20 @@ where
let exit = &signed_exit.message; let exit = &signed_exit.message;
let proposer_index = exit.validator_index as usize; let proposer_index = exit.validator_index as usize;
let domain = match state { let domain = if state.has_feature(FeatureName::Deneb) {
BeaconState::Base(_) // EIP-7044
| BeaconState::Altair(_) spec.compute_domain(
| BeaconState::Bellatrix(_) Domain::VoluntaryExit,
| BeaconState::Capella(_) => spec.get_domain( spec.capella_fork_version,
state.genesis_validators_root(),
)
} else {
spec.get_domain(
exit.epoch, exit.epoch,
Domain::VoluntaryExit, Domain::VoluntaryExit,
&state.fork(), &state.fork(),
state.genesis_validators_root(), state.genesis_validators_root(),
), )
// EIP-7044
BeaconState::Deneb(_) | BeaconState::Electra(_) => spec.compute_domain(
Domain::VoluntaryExit,
spec.capella_fork_version,
state.genesis_validators_root(),
),
}; };
let message = exit.signing_root(domain); let message = exit.signing_root(domain);

View File

@@ -32,11 +32,10 @@ pub fn verify_attestation_for_block_inclusion<'ctxt, E: EthSpec>(
attestation: data.slot, attestation: data.slot,
} }
); );
match state { if state.has_feature(FeatureName::Deneb) {
BeaconState::Base(_) // [Modified in Deneb:EIP7045]
| BeaconState::Altair(_) {}
| BeaconState::Bellatrix(_) } else {
| BeaconState::Capella(_) => {
verify!( verify!(
state.slot() <= data.slot.safe_add(E::slots_per_epoch())?, state.slot() <= data.slot.safe_add(E::slots_per_epoch())?,
Invalid::IncludedTooLate { Invalid::IncludedTooLate {
@@ -45,9 +44,6 @@ pub fn verify_attestation_for_block_inclusion<'ctxt, E: EthSpec>(
} }
); );
} }
// [Modified in Deneb:EIP7045]
BeaconState::Deneb(_) | BeaconState::Electra(_) => {}
}
verify_attestation_for_state(state, attestation, ctxt, verify_signatures, spec) verify_attestation_for_state(state, attestation, ctxt, verify_signatures, spec)
} }

View File

@@ -5,7 +5,7 @@ pub use epoch_processing_summary::{EpochProcessingSummary, ParticipationEpochSum
use errors::EpochProcessingError as Error; use errors::EpochProcessingError as Error;
pub use justification_and_finalization_state::JustificationAndFinalizationState; pub use justification_and_finalization_state::JustificationAndFinalizationState;
use safe_arith::SafeArith; use safe_arith::SafeArith;
use types::{BeaconState, ChainSpec, EthSpec}; use types::{BeaconState, ChainSpec, EthSpec, FeatureName};
pub use registry_updates::{process_registry_updates, process_registry_updates_slow}; pub use registry_updates::{process_registry_updates, process_registry_updates_slow};
pub use slashings::{process_slashings, process_slashings_slow}; pub use slashings::{process_slashings, process_slashings_slow};
@@ -41,13 +41,10 @@ pub fn process_epoch<E: EthSpec>(
.fork_name(spec) .fork_name(spec)
.map_err(Error::InconsistentStateFork)?; .map_err(Error::InconsistentStateFork)?;
match state { if state.has_feature(FeatureName::Altair) {
BeaconState::Base(_) => base::process_epoch(state, spec), altair::process_epoch(state, spec)
BeaconState::Altair(_) } else {
| BeaconState::Bellatrix(_) base::process_epoch(state, spec)
| BeaconState::Capella(_)
| BeaconState::Deneb(_)
| BeaconState::Electra(_) => altair::process_epoch(state, spec),
} }
} }

View File

@@ -235,6 +235,10 @@ impl<'a, E: EthSpec, Payload: AbstractExecPayload<E>> BeaconBlockRef<'a, E, Payl
} }
} }
pub fn has_feature(self, feature: FeatureName) -> bool {
self.fork_name_unchecked().has_feature(feature)
}
/// Convenience accessor for the `body` as a `BeaconBlockBodyRef`. /// Convenience accessor for the `body` as a `BeaconBlockBodyRef`.
pub fn body(&self) -> BeaconBlockBodyRef<'a, E, Payload> { pub fn body(&self) -> BeaconBlockBodyRef<'a, E, Payload> {
map_beacon_block_ref_into_beacon_block_body_ref!(&'a _, *self, |block, cons| cons( map_beacon_block_ref_into_beacon_block_body_ref!(&'a _, *self, |block, cons| cons(

View File

@@ -263,6 +263,10 @@ impl<'a, E: EthSpec, Payload: AbstractExecPayload<E>> BeaconBlockBodyRef<'a, E,
self.blob_kzg_commitments() self.blob_kzg_commitments()
.map_or(false, |blobs| !blobs.is_empty()) .map_or(false, |blobs| !blobs.is_empty())
} }
pub fn has_feature(self, feature: FeatureName) -> bool {
self.fork_name().has_feature(feature)
}
} }
impl<'a, E: EthSpec, Payload: AbstractExecPayload<E>> BeaconBlockBodyRef<'a, E, Payload> { impl<'a, E: EthSpec, Payload: AbstractExecPayload<E>> BeaconBlockBodyRef<'a, E, Payload> {

View File

@@ -1579,16 +1579,14 @@ impl<E: EthSpec> BeaconState<E> {
/// ///
/// Uses the current epoch committee cache, and will error if it isn't initialized. /// Uses the current epoch committee cache, and will error if it isn't initialized.
pub fn get_activation_churn_limit(&self, spec: &ChainSpec) -> Result<u64, Error> { pub fn get_activation_churn_limit(&self, spec: &ChainSpec) -> Result<u64, Error> {
Ok(match self { if self.has_feature(FeatureName::Deneb) {
BeaconState::Base(_) Ok(std::cmp::min(
| BeaconState::Altair(_)
| BeaconState::Bellatrix(_)
| BeaconState::Capella(_) => self.get_validator_churn_limit(spec)?,
BeaconState::Deneb(_) | BeaconState::Electra(_) => std::cmp::min(
spec.max_per_epoch_activation_churn_limit, spec.max_per_epoch_activation_churn_limit,
self.get_validator_churn_limit(spec)?, self.get_validator_churn_limit(spec)?,
), ))
}) } else {
Ok(self.get_validator_churn_limit(spec)?)
}
} }
/// Returns the `slot`, `index`, `committee_position` and `committee_len` for which a validator must produce an /// Returns the `slot`, `index`, `committee_position` and `committee_len` for which a validator must produce an

View File

@@ -4,7 +4,7 @@ use crate::{
NUM_FLAG_INDICES, TIMELY_HEAD_FLAG_INDEX, TIMELY_SOURCE_FLAG_INDEX, NUM_FLAG_INDICES, TIMELY_HEAD_FLAG_INDEX, TIMELY_SOURCE_FLAG_INDEX,
TIMELY_TARGET_FLAG_INDEX, TIMELY_TARGET_FLAG_INDEX,
}, },
BeaconState, BeaconStateError, ChainSpec, Epoch, EthSpec, ParticipationFlags, BeaconStateError, ChainSpec, Epoch, ParticipationFlags,
}; };
use arbitrary::Arbitrary; use arbitrary::Arbitrary;
use safe_arith::SafeArith; use safe_arith::SafeArith;
@@ -282,15 +282,3 @@ impl ProgressiveBalancesCache {
.ok_or(BeaconStateError::ProgressiveBalancesCacheNotInitialized) .ok_or(BeaconStateError::ProgressiveBalancesCacheNotInitialized)
} }
} }
/// `ProgressiveBalancesCache` is only enabled from `Altair` as it uses Altair-specific logic.
pub fn is_progressive_balances_enabled<E: EthSpec>(state: &BeaconState<E>) -> bool {
match state {
BeaconState::Base(_) => false,
BeaconState::Altair(_)
| BeaconState::Bellatrix(_)
| BeaconState::Capella(_)
| BeaconState::Deneb(_)
| BeaconState::Electra(_) => true,
}
}

View File

@@ -19,7 +19,7 @@ use state_processing::per_epoch_processing::{
}; };
use state_processing::EpochProcessingError; use state_processing::EpochProcessingError;
use std::marker::PhantomData; use std::marker::PhantomData;
use types::BeaconState; use types::{BeaconState, FeatureName};
#[derive(Debug, Clone, Default, Deserialize)] #[derive(Debug, Clone, Default, Deserialize)]
pub struct Metadata { pub struct Metadata {
@@ -91,8 +91,13 @@ type_name!(ParticipationFlagUpdates, "participation_flag_updates");
impl<E: EthSpec> EpochTransition<E> for JustificationAndFinalization { impl<E: EthSpec> EpochTransition<E> for JustificationAndFinalization {
fn run(state: &mut BeaconState<E>, spec: &ChainSpec) -> Result<(), EpochProcessingError> { fn run(state: &mut BeaconState<E>, spec: &ChainSpec) -> Result<(), EpochProcessingError> {
match state { if state.has_feature(FeatureName::Altair) {
BeaconState::Base(_) => { initialize_progressive_balances_cache(state, spec)?;
let justification_and_finalization_state =
altair::process_justification_and_finalization(state)?;
justification_and_finalization_state.apply_changes_to_state(state);
Ok(())
} else {
let mut validator_statuses = base::ValidatorStatuses::new(state, spec)?; let mut validator_statuses = base::ValidatorStatuses::new(state, spec)?;
validator_statuses.process_attestations(state)?; validator_statuses.process_attestations(state)?;
let justification_and_finalization_state = let justification_and_finalization_state =
@@ -104,35 +109,18 @@ impl<E: EthSpec> EpochTransition<E> for JustificationAndFinalization {
justification_and_finalization_state.apply_changes_to_state(state); justification_and_finalization_state.apply_changes_to_state(state);
Ok(()) Ok(())
} }
BeaconState::Altair(_)
| BeaconState::Bellatrix(_)
| BeaconState::Capella(_)
| BeaconState::Deneb(_)
| BeaconState::Electra(_) => {
initialize_progressive_balances_cache(state, spec)?;
let justification_and_finalization_state =
altair::process_justification_and_finalization(state)?;
justification_and_finalization_state.apply_changes_to_state(state);
Ok(())
}
}
} }
} }
impl<E: EthSpec> EpochTransition<E> for RewardsAndPenalties { impl<E: EthSpec> EpochTransition<E> for RewardsAndPenalties {
fn run(state: &mut BeaconState<E>, spec: &ChainSpec) -> Result<(), EpochProcessingError> { fn run(state: &mut BeaconState<E>, spec: &ChainSpec) -> Result<(), EpochProcessingError> {
match state { if state.has_feature(FeatureName::Altair) {
BeaconState::Base(_) => { altair::process_rewards_and_penalties_slow(state, spec)
} else {
let mut validator_statuses = base::ValidatorStatuses::new(state, spec)?; let mut validator_statuses = base::ValidatorStatuses::new(state, spec)?;
validator_statuses.process_attestations(state)?; validator_statuses.process_attestations(state)?;
base::process_rewards_and_penalties(state, &validator_statuses, spec) base::process_rewards_and_penalties(state, &validator_statuses, spec)
} }
BeaconState::Altair(_)
| BeaconState::Bellatrix(_)
| BeaconState::Capella(_)
| BeaconState::Deneb(_)
| BeaconState::Electra(_) => altair::process_rewards_and_penalties_slow(state, spec),
}
} }
} }
@@ -150,8 +138,9 @@ impl<E: EthSpec> EpochTransition<E> for RegistryUpdates {
impl<E: EthSpec> EpochTransition<E> for Slashings { impl<E: EthSpec> EpochTransition<E> for Slashings {
fn run(state: &mut BeaconState<E>, spec: &ChainSpec) -> Result<(), EpochProcessingError> { fn run(state: &mut BeaconState<E>, spec: &ChainSpec) -> Result<(), EpochProcessingError> {
match state { if state.has_feature(FeatureName::Altair) {
BeaconState::Base(_) => { process_slashings_slow(state, spec)?;
} else {
let mut validator_statuses = base::ValidatorStatuses::new(state, spec)?; let mut validator_statuses = base::ValidatorStatuses::new(state, spec)?;
validator_statuses.process_attestations(state)?; validator_statuses.process_attestations(state)?;
process_slashings( process_slashings(
@@ -160,14 +149,7 @@ impl<E: EthSpec> EpochTransition<E> for Slashings {
spec, spec,
)?; )?;
} }
BeaconState::Altair(_)
| BeaconState::Bellatrix(_)
| BeaconState::Capella(_)
| BeaconState::Deneb(_)
| BeaconState::Electra(_) => {
process_slashings_slow(state, spec)?;
}
};
Ok(()) Ok(())
} }
} }
@@ -202,22 +184,20 @@ impl<E: EthSpec> EpochTransition<E> for RandaoMixesReset {
impl<E: EthSpec> EpochTransition<E> for HistoricalRootsUpdate { impl<E: EthSpec> EpochTransition<E> for HistoricalRootsUpdate {
fn run(state: &mut BeaconState<E>, _spec: &ChainSpec) -> Result<(), EpochProcessingError> { fn run(state: &mut BeaconState<E>, _spec: &ChainSpec) -> Result<(), EpochProcessingError> {
match state { if state.has_feature(FeatureName::Capella) {
BeaconState::Base(_) | BeaconState::Altair(_) | BeaconState::Bellatrix(_) => { Ok(())
} else {
process_historical_roots_update(state) process_historical_roots_update(state)
} }
_ => Ok(()),
}
} }
} }
impl<E: EthSpec> EpochTransition<E> for HistoricalSummariesUpdate { impl<E: EthSpec> EpochTransition<E> for HistoricalSummariesUpdate {
fn run(state: &mut BeaconState<E>, _spec: &ChainSpec) -> Result<(), EpochProcessingError> { fn run(state: &mut BeaconState<E>, _spec: &ChainSpec) -> Result<(), EpochProcessingError> {
match state { if state.has_feature(FeatureName::Capella) {
BeaconState::Capella(_) | BeaconState::Deneb(_) | BeaconState::Electra(_) => {
process_historical_summaries_update(state) process_historical_summaries_update(state)
} } else {
_ => Ok(()), Ok(())
} }
} }
} }
@@ -234,39 +214,30 @@ impl<E: EthSpec> EpochTransition<E> for ParticipationRecordUpdates {
impl<E: EthSpec> EpochTransition<E> for SyncCommitteeUpdates { impl<E: EthSpec> EpochTransition<E> for SyncCommitteeUpdates {
fn run(state: &mut BeaconState<E>, spec: &ChainSpec) -> Result<(), EpochProcessingError> { fn run(state: &mut BeaconState<E>, spec: &ChainSpec) -> Result<(), EpochProcessingError> {
match state { if state.has_feature(FeatureName::Altair) {
BeaconState::Base(_) => Ok(()), altair::process_sync_committee_updates(state, spec)
BeaconState::Altair(_) } else {
| BeaconState::Bellatrix(_) Ok(())
| BeaconState::Capella(_)
| BeaconState::Deneb(_)
| BeaconState::Electra(_) => altair::process_sync_committee_updates(state, spec),
} }
} }
} }
impl<E: EthSpec> EpochTransition<E> for InactivityUpdates { impl<E: EthSpec> EpochTransition<E> for InactivityUpdates {
fn run(state: &mut BeaconState<E>, spec: &ChainSpec) -> Result<(), EpochProcessingError> { fn run(state: &mut BeaconState<E>, spec: &ChainSpec) -> Result<(), EpochProcessingError> {
match state { if state.has_feature(FeatureName::Altair) {
BeaconState::Base(_) => Ok(()), altair::process_inactivity_updates_slow(state, spec)
BeaconState::Altair(_) } else {
| BeaconState::Bellatrix(_) Ok(())
| BeaconState::Capella(_)
| BeaconState::Deneb(_)
| BeaconState::Electra(_) => altair::process_inactivity_updates_slow(state, spec),
} }
} }
} }
impl<E: EthSpec> EpochTransition<E> for ParticipationFlagUpdates { impl<E: EthSpec> EpochTransition<E> for ParticipationFlagUpdates {
fn run(state: &mut BeaconState<E>, _: &ChainSpec) -> Result<(), EpochProcessingError> { fn run(state: &mut BeaconState<E>, _: &ChainSpec) -> Result<(), EpochProcessingError> {
match state { if state.has_feature(FeatureName::Altair) {
BeaconState::Base(_) => Ok(()), altair::process_participation_flag_updates(state)
BeaconState::Altair(_) } else {
| BeaconState::Bellatrix(_) Ok(())
| BeaconState::Capella(_)
| BeaconState::Deneb(_)
| BeaconState::Electra(_) => altair::process_participation_flag_updates(state),
} }
} }
} }
@@ -304,24 +275,19 @@ impl<E: EthSpec, T: EpochTransition<E>> Case for EpochProcessing<E, T> {
} }
fn is_enabled_for_fork(fork_name: ForkName) -> bool { fn is_enabled_for_fork(fork_name: ForkName) -> bool {
match fork_name { // No phase0 tests for Altair and later.
if fork_name.has_feature(FeatureName::Capella) {
T::name() != "participation_record_updates" && T::name() != "historical_roots_update"
} else if fork_name.has_feature(FeatureName::Altair) {
T::name() != "participation_record_updates"
&& T::name() != "historical_summaries_update"
} else {
// No Altair tests for genesis fork. // No Altair tests for genesis fork.
ForkName::Base => {
T::name() != "sync_committee_updates" T::name() != "sync_committee_updates"
&& T::name() != "inactivity_updates" && T::name() != "inactivity_updates"
&& T::name() != "participation_flag_updates" && T::name() != "participation_flag_updates"
&& T::name() != "historical_summaries_update" && T::name() != "historical_summaries_update"
} }
// No phase0 tests for Altair and later.
ForkName::Altair | ForkName::Bellatrix => {
T::name() != "participation_record_updates"
&& T::name() != "historical_summaries_update"
}
ForkName::Capella | ForkName::Deneb | ForkName::Electra => {
T::name() != "participation_record_updates"
&& T::name() != "historical_roots_update"
}
}
} }
fn result(&self, _case_index: usize, fork_name: ForkName) -> Result<(), Error> { fn result(&self, _case_index: usize, fork_name: ForkName) -> Result<(), Error> {

View File

@@ -22,7 +22,7 @@ use std::fmt::Debug;
use types::{ use types::{
Attestation, AttesterSlashing, BeaconBlock, BeaconBlockBody, BeaconBlockBodyBellatrix, Attestation, AttesterSlashing, BeaconBlock, BeaconBlockBody, BeaconBlockBodyBellatrix,
BeaconBlockBodyCapella, BeaconBlockBodyDeneb, BeaconState, BlindedPayload, Deposit, BeaconBlockBodyCapella, BeaconBlockBodyDeneb, BeaconState, BlindedPayload, Deposit,
ExecutionPayload, FullPayload, ProposerSlashing, SignedBlsToExecutionChange, ExecutionPayload, FeatureName, FullPayload, ProposerSlashing, SignedBlsToExecutionChange,
SignedVoluntaryExit, SyncAggregate, SignedVoluntaryExit, SyncAggregate,
}; };
@@ -90,19 +90,7 @@ impl<E: EthSpec> Operation<E> for Attestation<E> {
) -> Result<(), BlockProcessingError> { ) -> Result<(), BlockProcessingError> {
initialize_epoch_cache(state, spec)?; initialize_epoch_cache(state, spec)?;
let mut ctxt = ConsensusContext::new(state.slot()); let mut ctxt = ConsensusContext::new(state.slot());
match state { if state.has_feature(FeatureName::Altair) {
BeaconState::Base(_) => base::process_attestations(
state,
&[self.clone()],
VerifySignatures::True,
&mut ctxt,
spec,
),
BeaconState::Altair(_)
| BeaconState::Bellatrix(_)
| BeaconState::Capella(_)
| BeaconState::Deneb(_)
| BeaconState::Electra(_) => {
initialize_progressive_balances_cache(state, spec)?; initialize_progressive_balances_cache(state, spec)?;
altair_deneb::process_attestation( altair_deneb::process_attestation(
state, state,
@@ -112,7 +100,14 @@ impl<E: EthSpec> Operation<E> for Attestation<E> {
VerifySignatures::True, VerifySignatures::True,
spec, spec,
) )
} } else {
base::process_attestations(
state,
&[self.clone()],
VerifySignatures::True,
&mut ctxt,
spec,
)
} }
} }
} }