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

@@ -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`.
pub fn body(&self) -> BeaconBlockBodyRef<'a, E, Payload> {
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()
.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> {

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.
pub fn get_activation_churn_limit(&self, spec: &ChainSpec) -> Result<u64, Error> {
Ok(match self {
BeaconState::Base(_)
| BeaconState::Altair(_)
| BeaconState::Bellatrix(_)
| BeaconState::Capella(_) => self.get_validator_churn_limit(spec)?,
BeaconState::Deneb(_) | BeaconState::Electra(_) => std::cmp::min(
if self.has_feature(FeatureName::Deneb) {
Ok(std::cmp::min(
spec.max_per_epoch_activation_churn_limit,
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

View File

@@ -4,7 +4,7 @@ use crate::{
NUM_FLAG_INDICES, TIMELY_HEAD_FLAG_INDEX, TIMELY_SOURCE_FLAG_INDEX,
TIMELY_TARGET_FLAG_INDEX,
},
BeaconState, BeaconStateError, ChainSpec, Epoch, EthSpec, ParticipationFlags,
BeaconStateError, ChainSpec, Epoch, ParticipationFlags,
};
use arbitrary::Arbitrary;
use safe_arith::SafeArith;
@@ -282,15 +282,3 @@ impl ProgressiveBalancesCache {
.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,
}
}