This commit is contained in:
Mac L
2024-05-02 16:06:28 +10:00
parent 689cdaef61
commit d9a0c3d6c2
10 changed files with 139 additions and 157 deletions

View File

@@ -15,8 +15,8 @@ use std::time::Duration;
use types::{
consts::bellatrix::INTERVALS_PER_SLOT, AbstractExecPayload, AttestationShufflingId,
AttesterSlashing, BeaconBlockRef, BeaconState, BeaconStateError, ChainSpec, Checkpoint, Epoch,
EthSpec, ExecPayload, ExecutionBlockHash, Hash256, IndexedAttestation, RelativeEpoch,
SignedBeaconBlock, Slot,
EthSpec, ExecPayload, ExecutionBlockHash, FeatureName, Hash256, IndexedAttestation,
RelativeEpoch, SignedBeaconBlock, Slot,
};
#[derive(Debug)]
@@ -747,20 +747,15 @@ where
if let Some((parent_justified, parent_finalized)) = parent_checkpoints {
(parent_justified, parent_finalized)
} else {
let justification_and_finalization_state = match block {
BeaconBlockRef::Electra(_)
| BeaconBlockRef::Deneb(_)
| BeaconBlockRef::Capella(_)
| BeaconBlockRef::Bellatrix(_)
| BeaconBlockRef::Altair(_) => {
let justification_and_finalization_state =
if block.fork_name_unchecked().has_feature(FeatureName::Altair) {
// NOTE: Processing justification & finalization requires the progressive
// balances cache, but we cannot initialize it here as we only have an
// immutable reference. The state *should* have come straight from block
// processing, which initialises the cache, but if we add other `on_block`
// calls in future it could be worth passing a mutable reference.
per_epoch_processing::altair::process_justification_and_finalization(state)?
}
BeaconBlockRef::Base(_) => {
} else {
let mut validator_statuses =
per_epoch_processing::base::ValidatorStatuses::new(state, spec)
.map_err(Error::ValidatorStatuses)?;
@@ -772,8 +767,7 @@ where
&validator_statuses.total_balances,
spec,
)?
}
};
};
(
justification_and_finalization_state.current_justified_checkpoint(),

View File

@@ -50,13 +50,13 @@ impl ForkName {
}
pub fn list_all_enabled_features(self) -> Vec<FeatureName> {
let mut res = vec![];
let mut all_features = vec![];
for (fork, features) in FORK_ORDER {
if *fork <= self {
res.extend(features.iter());
all_features.extend(features.iter());
}
}
res
all_features
}
pub fn has_feature(self, feature: FeatureName) -> bool {

View File

@@ -37,7 +37,14 @@ impl From<SignedBeaconBlockHash> for Hash256 {
/// A `BeaconBlock` and a signature from its proposer.
#[superstruct(
variants(Base, Altair, Bellatrix, Capella, Deneb, Electra),
variants_and_features_from = "FORK_ORDER",
feature_dependencies = "FEATURE_DEPENDENCIES",
variant_type(name = "ForkName", getter = "fork_name_outer"),
feature_type(
name = "FeatureName",
list = "list_all_features",
check = "has_feature"
),
variant_attributes(
derive(
Debug,