Use 'super-features' for past forks

This commit is contained in:
Mac L
2024-04-23 10:34:23 +10:00
parent 3b92e0bd9a
commit 5c80d92b22
4 changed files with 36 additions and 23 deletions

View File

@@ -68,7 +68,7 @@ pub struct BeaconBlockBody<E: EthSpec, Payload: AbstractExecPayload<E> = FullPay
pub attestations: VariableList<Attestation<E>, E::MaxAttestations>, pub attestations: VariableList<Attestation<E>, E::MaxAttestations>,
pub deposits: VariableList<Deposit, E::MaxDeposits>, pub deposits: VariableList<Deposit, E::MaxDeposits>,
pub voluntary_exits: VariableList<SignedVoluntaryExit, E::MaxVoluntaryExits>, pub voluntary_exits: VariableList<SignedVoluntaryExit, E::MaxVoluntaryExits>,
#[superstruct(feature(SyncCommittees))] #[superstruct(feature(Altair))]
pub sync_aggregate: SyncAggregate<E>, pub sync_aggregate: SyncAggregate<E>,
// We flatten the execution payload so that serde can use the name of the inner type, // We flatten the execution payload so that serde can use the name of the inner type,
// either `execution_payload` for full payloads, or `execution_payload_header` for blinded // either `execution_payload` for full payloads, or `execution_payload_header` for blinded
@@ -85,10 +85,10 @@ pub struct BeaconBlockBody<E: EthSpec, Payload: AbstractExecPayload<E> = FullPay
#[superstruct(only(Electra), partial_getter(rename = "execution_payload_electra"))] #[superstruct(only(Electra), partial_getter(rename = "execution_payload_electra"))]
#[serde(flatten)] #[serde(flatten)]
pub execution_payload: Payload::Electra, pub execution_payload: Payload::Electra,
#[superstruct(feature(Withdrawals))] #[superstruct(feature(Capella))]
pub bls_to_execution_changes: pub bls_to_execution_changes:
VariableList<SignedBlsToExecutionChange, E::MaxBlsToExecutionChanges>, VariableList<SignedBlsToExecutionChange, E::MaxBlsToExecutionChanges>,
#[superstruct(feature(Blobs))] #[superstruct(feature(Deneb))]
pub blob_kzg_commitments: KzgCommitments<E>, pub blob_kzg_commitments: KzgCommitments<E>,
#[superstruct(feature(not(Merge)))] #[superstruct(feature(not(Merge)))]
#[ssz(skip_serializing, skip_deserializing)] #[ssz(skip_serializing, skip_deserializing)]

View File

@@ -269,15 +269,15 @@ where
pub slashings: FixedVector<u64, E::EpochsPerSlashingsVector>, pub slashings: FixedVector<u64, E::EpochsPerSlashingsVector>,
// Attestations (genesis fork only) // Attestations (genesis fork only)
#[superstruct(feature(not(SyncCommittees)))] #[superstruct(feature(not(Altair)))]
pub previous_epoch_attestations: VariableList<PendingAttestation<E>, E::MaxPendingAttestations>, pub previous_epoch_attestations: VariableList<PendingAttestation<E>, E::MaxPendingAttestations>,
#[superstruct(feature(not(SyncCommittees)))] #[superstruct(feature(not(Altair)))]
pub current_epoch_attestations: VariableList<PendingAttestation<E>, E::MaxPendingAttestations>, pub current_epoch_attestations: VariableList<PendingAttestation<E>, E::MaxPendingAttestations>,
// Participation (Altair and later) // Participation (Altair and later)
#[superstruct(feature(SyncCommittees))] #[superstruct(feature(Altair))]
pub previous_epoch_participation: VariableList<ParticipationFlags, E::ValidatorRegistryLimit>, pub previous_epoch_participation: VariableList<ParticipationFlags, E::ValidatorRegistryLimit>,
#[superstruct(feature(SyncCommittees))] #[superstruct(feature(Altair))]
pub current_epoch_participation: VariableList<ParticipationFlags, E::ValidatorRegistryLimit>, pub current_epoch_participation: VariableList<ParticipationFlags, E::ValidatorRegistryLimit>,
// Finality // Finality
@@ -292,13 +292,13 @@ where
// Inactivity // Inactivity
#[serde(with = "ssz_types::serde_utils::quoted_u64_var_list")] #[serde(with = "ssz_types::serde_utils::quoted_u64_var_list")]
#[superstruct(feature(SyncCommittees))] #[superstruct(feature(Altair))]
pub inactivity_scores: VariableList<u64, E::ValidatorRegistryLimit>, pub inactivity_scores: VariableList<u64, E::ValidatorRegistryLimit>,
// Light-client sync committees // Light-client sync committees
#[superstruct(feature(SyncCommittees))] #[superstruct(feature(Altair))]
pub current_sync_committee: Arc<SyncCommittee<E>>, pub current_sync_committee: Arc<SyncCommittee<E>>,
#[superstruct(feature(SyncCommittees))] #[superstruct(feature(Altair))]
pub next_sync_committee: Arc<SyncCommittee<E>>, pub next_sync_committee: Arc<SyncCommittee<E>>,
// Execution // Execution
@@ -324,14 +324,14 @@ where
pub latest_execution_payload_header: ExecutionPayloadHeaderElectra<E>, pub latest_execution_payload_header: ExecutionPayloadHeaderElectra<E>,
// Capella // Capella
#[superstruct(feature(Withdrawals), partial_getter(copy))] #[superstruct(feature(Capella), partial_getter(copy))]
#[serde(with = "serde_utils::quoted_u64")] #[serde(with = "serde_utils::quoted_u64")]
pub next_withdrawal_index: u64, pub next_withdrawal_index: u64,
#[superstruct(feature(Withdrawals), partial_getter(copy))] #[superstruct(feature(Capella), partial_getter(copy))]
#[serde(with = "serde_utils::quoted_u64")] #[serde(with = "serde_utils::quoted_u64")]
pub next_withdrawal_validator_index: u64, pub next_withdrawal_validator_index: u64,
// Deep history valid from Capella onwards. // Deep history valid from Capella onwards.
#[superstruct(feature(Withdrawals))] #[superstruct(feature(Capella))]
pub historical_summaries: VariableList<HistoricalSummary, E::HistoricalRootsLimit>, pub historical_summaries: VariableList<HistoricalSummary, E::HistoricalRootsLimit>,
// Caching (not in the spec) // Caching (not in the spec)

View File

@@ -1,12 +1,25 @@
// A list of all individual features that are available.
// We can gate parts of the code behind checks that ensure a feature is active.
//
// For now, older Forks have a single "super-feature" which contains all features associated with
// that Fork. It may be worth splitting these up at a later time.
pub enum FeatureName { pub enum FeatureName {
// Altair. // Altair.
SyncCommittees, Altair,
// Bellatrix. // Bellatrix.
Merge, Merge,
// Capella. // Capella.
Withdrawals, Capella,
// Deneb. // Deneb.
Blobs, Deneb,
// Electra. // Electra.
//
// Supply deposits on chain.
EIP6110, EIP6110,
// EL triggerable exits.
EIP7002,
// Increase MAX_EFFECTIVE_BALANCE.
EIP7251,
// Committee index outside Attestation.
EIP7549,
} }

View File

@@ -4,19 +4,19 @@ use superstruct::superstruct;
#[superstruct(variants_and_features_decl = "FORK_ORDER")] #[superstruct(variants_and_features_decl = "FORK_ORDER")]
pub const FORK_ORDER: &[(ForkName, &[FeatureName])] = &[ pub const FORK_ORDER: &[(ForkName, &[FeatureName])] = &[
(ForkName::Base, &[]), (ForkName::Base, &[]),
(ForkName::Altair, &[FeatureName::SyncCommittees]), (ForkName::Altair, &[FeatureName::Altair]),
(ForkName::Merge, &[FeatureName::Merge]), (ForkName::Merge, &[FeatureName::Merge]),
(ForkName::Capella, &[FeatureName::Withdrawals]), (ForkName::Capella, &[FeatureName::Capella]),
(ForkName::Deneb, &[FeatureName::Blobs]), (ForkName::Deneb, &[FeatureName::Deneb]),
(ForkName::Electra, &[]), (ForkName::Electra, &[]),
]; ];
#[superstruct(feature_dependencies_decl = "FEATURE_DEPENDENCIES")] #[superstruct(feature_dependencies_decl = "FEATURE_DEPENDENCIES")]
pub const FEATURE_DEPENDENCIES: &[(FeatureName, &[FeatureName])] = &[ pub const FEATURE_DEPENDENCIES: &[(FeatureName, &[FeatureName])] = &[
(FeatureName::SyncCommittees, &[]), (FeatureName::Altair, &[]),
(FeatureName::Merge, &[FeatureName::SyncCommittees]), (FeatureName::Merge, &[FeatureName::Altair]),
(FeatureName::Withdrawals, &[FeatureName::Merge]), (FeatureName::Capella, &[FeatureName::Merge]),
(FeatureName::Blobs, &[FeatureName::Withdrawals]), (FeatureName::Deneb, &[FeatureName::Capella]),
]; ];
#[cfg(test)] #[cfg(test)]