From 2bac4b8a1958d460ad0bd45e8430a07dfb7668f9 Mon Sep 17 00:00:00 2001 From: Mac L Date: Wed, 1 May 2024 13:09:42 +1000 Subject: [PATCH] Add syntax to more types --- Cargo.lock | 2 +- beacon_node/execution_layer/build.rs | 2 + beacon_node/execution_layer/src/block_hash.rs | 4 +- beacon_node/execution_layer/src/engine_api.rs | 32 ++++++++++++---- .../src/engine_api/new_payload_request.rs | 16 ++++++-- beacon_node/store/build.rs | 2 + beacon_node/store/src/partial_beacon_state.rs | 25 ++++++++----- consensus/types/src/beacon_block.rs | 9 ++++- consensus/types/src/beacon_block_body.rs | 6 +++ consensus/types/src/beacon_state.rs | 26 ++++++++----- consensus/types/src/builder_bid.rs | 15 ++++++-- consensus/types/src/config_and_preset.rs | 16 ++++++-- consensus/types/src/execution_payload.rs | 37 ++++++++++++------- .../types/src/execution_payload_header.rs | 16 ++++++-- consensus/types/src/feature_name.rs | 11 +----- consensus/types/src/fork_order.rs | 3 +- consensus/types/src/light_client_header.rs | 14 +++++-- consensus/types/src/payload.rs | 20 +++++++++- 18 files changed, 181 insertions(+), 75 deletions(-) create mode 100644 beacon_node/execution_layer/build.rs create mode 100644 beacon_node/store/build.rs diff --git a/Cargo.lock b/Cargo.lock index d6ea152d6e..b144fb4108 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7906,7 +7906,7 @@ checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" [[package]] name = "superstruct" version = "0.7.0" -source = "git+https://github.com/sigp/superstruct?branch=features#06132f875603d2985a414e6e3683c42bc9505f49" +source = "git+https://github.com/sigp/superstruct?branch=features#822403d4d415c181aa7f4765e118606c6772dc58" dependencies = [ "darling", "itertools", diff --git a/beacon_node/execution_layer/build.rs b/beacon_node/execution_layer/build.rs new file mode 100644 index 0000000000..76a1c67d1c --- /dev/null +++ b/beacon_node/execution_layer/build.rs @@ -0,0 +1,2 @@ +// Dummy build.rs file to enable OUT_DIR usage by superstruct +fn main() {} diff --git a/beacon_node/execution_layer/src/block_hash.rs b/beacon_node/execution_layer/src/block_hash.rs index 1f8c29f6b2..7784f02a3e 100644 --- a/beacon_node/execution_layer/src/block_hash.rs +++ b/beacon_node/execution_layer/src/block_hash.rs @@ -45,8 +45,8 @@ pub fn calculate_execution_block_hash( KECCAK_EMPTY_LIST_RLP.as_fixed_bytes().into(), rlp_transactions_root, rlp_withdrawals_root, - rlp_blob_gas_used, - rlp_excess_blob_gas, + rlp_blob_gas_used.copied(), + rlp_excess_blob_gas.copied(), parent_beacon_block_root, ); diff --git a/beacon_node/execution_layer/src/engine_api.rs b/beacon_node/execution_layer/src/engine_api.rs index a91f5d6a44..259301dfe1 100644 --- a/beacon_node/execution_layer/src/engine_api.rs +++ b/beacon_node/execution_layer/src/engine_api.rs @@ -27,7 +27,7 @@ pub use types::{ use types::{ ExecutionPayloadCapella, ExecutionPayloadDeneb, ExecutionPayloadElectra, ExecutionPayloadMerge, - KzgProofs, + FeatureName, KzgProofs, }; pub mod auth; @@ -155,7 +155,15 @@ pub struct ExecutionBlock { /// Representation of an execution block with enough detail to reconstruct a payload. #[superstruct( - variants(Merge, Capella, Deneb, Electra), + feature(Merge), + variants_and_features_from = "FORK_ORDER", + feature_dependencies = "FEATURE_DEPENDENCIES", + variant_type(name = "ForkName", getter = "fork_name"), + feature_type( + name = "FeatureName", + list = "list_all_features", + check = "is_feature_enabled" + ), variant_attributes( derive(Clone, Debug, PartialEq, Serialize, Deserialize,), serde(bound = "E: EthSpec", rename_all = "camelCase"), @@ -189,12 +197,12 @@ pub struct ExecutionBlockWithTransactions { #[serde(rename = "hash")] pub block_hash: ExecutionBlockHash, pub transactions: Vec, - #[superstruct(only(Capella, Deneb, Electra))] + #[superstruct(feature(Capella))] pub withdrawals: Vec, - #[superstruct(only(Deneb, Electra))] + #[superstruct(feature(Deneb))] #[serde(with = "serde_utils::u64_hex_be")] pub blob_gas_used: u64, - #[superstruct(only(Deneb, Electra))] + #[superstruct(feature(Deneb))] #[serde(with = "serde_utils::u64_hex_be")] pub excess_blob_gas: u64, } @@ -423,7 +431,15 @@ pub struct ProposeBlindedBlockResponse { } #[superstruct( - variants(Merge, Capella, Deneb, Electra), + feature(Merge), + variants_and_features_from = "FORK_ORDER", + feature_dependencies = "FEATURE_DEPENDENCIES", + variant_type(name = "ForkName", getter = "fork_name"), + feature_type( + name = "FeatureName", + list = "list_all_features", + check = "is_feature_enabled" + ), variant_attributes(derive(Clone, Debug, PartialEq),), map_into(ExecutionPayload), map_ref_into(ExecutionPayloadRef), @@ -441,9 +457,9 @@ pub struct GetPayloadResponse { #[superstruct(only(Electra), partial_getter(rename = "execution_payload_electra"))] pub execution_payload: ExecutionPayloadElectra, pub block_value: Uint256, - #[superstruct(only(Deneb, Electra))] + #[superstruct(feature(Deneb))] pub blobs_bundle: BlobsBundle, - #[superstruct(only(Deneb, Electra), partial_getter(copy))] + #[superstruct(feature(Deneb), partial_getter(copy))] pub should_override_builder: bool, } diff --git a/beacon_node/execution_layer/src/engine_api/new_payload_request.rs b/beacon_node/execution_layer/src/engine_api/new_payload_request.rs index 6b6df13b70..9b4d2d4e79 100644 --- a/beacon_node/execution_layer/src/engine_api/new_payload_request.rs +++ b/beacon_node/execution_layer/src/engine_api/new_payload_request.rs @@ -5,14 +5,22 @@ use state_processing::per_block_processing::deneb::kzg_commitment_to_versioned_h use superstruct::superstruct; use types::{ BeaconBlockRef, BeaconStateError, EthSpec, ExecutionBlockHash, ExecutionPayload, - ExecutionPayloadRef, Hash256, VersionedHash, + ExecutionPayloadRef, FeatureName, ForkName, Hash256, VersionedHash, }; use types::{ ExecutionPayloadCapella, ExecutionPayloadDeneb, ExecutionPayloadElectra, ExecutionPayloadMerge, }; #[superstruct( - variants(Merge, Capella, Deneb, Electra), + feature(Merge), + variants_and_features_from = "FORK_ORDER", + feature_dependencies = "FEATURE_DEPENDENCIES", + variant_type(name = "ForkName", getter = "fork_name"), + feature_type( + name = "FeatureName", + list = "list_all_features", + check = "is_feature_enabled" + ), variant_attributes(derive(Clone, Debug, PartialEq),), map_into(ExecutionPayload), map_ref_into(ExecutionPayloadRef), @@ -35,9 +43,9 @@ pub struct NewPayloadRequest<'block, E: EthSpec> { pub execution_payload: &'block ExecutionPayloadDeneb, #[superstruct(only(Electra), partial_getter(rename = "execution_payload_electra"))] pub execution_payload: &'block ExecutionPayloadElectra, - #[superstruct(only(Deneb, Electra))] + #[superstruct(feature(Deneb))] pub versioned_hashes: Vec, - #[superstruct(only(Deneb, Electra))] + #[superstruct(feature(Deneb))] pub parent_beacon_block_root: Hash256, } diff --git a/beacon_node/store/build.rs b/beacon_node/store/build.rs new file mode 100644 index 0000000000..76a1c67d1c --- /dev/null +++ b/beacon_node/store/build.rs @@ -0,0 +1,2 @@ +// Dummy build.rs file to enable OUT_DIR usage by superstruct +fn main() {} diff --git a/beacon_node/store/src/partial_beacon_state.rs b/beacon_node/store/src/partial_beacon_state.rs index 4e5a2b8e64..8fbb527946 100644 --- a/beacon_node/store/src/partial_beacon_state.rs +++ b/beacon_node/store/src/partial_beacon_state.rs @@ -14,7 +14,14 @@ use types::*; /// /// Utilises lazy-loading from separate storage for its vector fields. #[superstruct( - variants(Base, Altair, Merge, Capella, Deneb, Electra), + variants_and_features_from = "FORK_ORDER", + feature_dependencies = "FEATURE_DEPENDENCIES", + variant_type(name = "ForkName", getter = "fork_name"), + feature_type( + name = "FeatureName", + list = "list_all_features", + check = "is_feature_enabled" + ), variant_attributes(derive(Debug, PartialEq, Clone, Encode, Decode)) )] #[derive(Debug, PartialEq, Clone, Encode)] @@ -66,9 +73,9 @@ where pub current_epoch_attestations: VariableList, E::MaxPendingAttestations>, // Participation (Altair and later) - #[superstruct(only(Altair, Merge, Capella, Deneb, Electra))] + #[superstruct(feature(Altair))] pub previous_epoch_participation: VariableList, - #[superstruct(only(Altair, Merge, Capella, Deneb, Electra))] + #[superstruct(feature(Altair))] pub current_epoch_participation: VariableList, // Finality @@ -78,13 +85,13 @@ where pub finalized_checkpoint: Checkpoint, // Inactivity - #[superstruct(only(Altair, Merge, Capella, Deneb, Electra))] + #[superstruct(feature(Altair))] pub inactivity_scores: VariableList, // Light-client sync committees - #[superstruct(only(Altair, Merge, Capella, Deneb, Electra))] + #[superstruct(feature(Altair))] pub current_sync_committee: Arc>, - #[superstruct(only(Altair, Merge, Capella, Deneb, Electra))] + #[superstruct(feature(Altair))] pub next_sync_committee: Arc>, // Execution @@ -110,13 +117,13 @@ where pub latest_execution_payload_header: ExecutionPayloadHeaderElectra, // Capella - #[superstruct(only(Capella, Deneb, Electra))] + #[superstruct(feature(Capella))] pub next_withdrawal_index: u64, - #[superstruct(only(Capella, Deneb, Electra))] + #[superstruct(feature(Capella))] pub next_withdrawal_validator_index: u64, #[ssz(skip_serializing, skip_deserializing)] - #[superstruct(only(Capella, Deneb, Electra))] + #[superstruct(feature(Capella))] pub historical_summaries: Option>, } diff --git a/consensus/types/src/beacon_block.rs b/consensus/types/src/beacon_block.rs index 14874f0204..4d1d2d4c1d 100644 --- a/consensus/types/src/beacon_block.rs +++ b/consensus/types/src/beacon_block.rs @@ -12,7 +12,14 @@ use tree_hash_derive::TreeHash; /// A block of the `BeaconChain`. #[superstruct( - variants(Base, Altair, Merge, Capella, Deneb, Electra), + variants_and_features_from = "FORK_ORDER", + feature_dependencies = "FEATURE_DEPENDENCIES", + variant_type(name = "ForkName", getter = "fork_name_unchecked"), + feature_type( + name = "FeatureName", + list = "list_all_features", + check = "is_feature_enabled" + ), variant_attributes( derive( Debug, diff --git a/consensus/types/src/beacon_block_body.rs b/consensus/types/src/beacon_block_body.rs index 8f975fc5cf..2aedf1156c 100644 --- a/consensus/types/src/beacon_block_body.rs +++ b/consensus/types/src/beacon_block_body.rs @@ -31,6 +31,12 @@ pub const BLOB_KZG_COMMITMENTS_INDEX: usize = 11; #[superstruct( variants_and_features_from = "FORK_ORDER", feature_dependencies = "FEATURE_DEPENDENCIES", + variant_type(name = "ForkName", getter = "fork_name"), + feature_type( + name = "FeatureName", + list = "list_all_features", + check = "is_feature_enabled" + ), variant_attributes( derive( Debug, diff --git a/consensus/types/src/beacon_state.rs b/consensus/types/src/beacon_state.rs index 4fc685e081..00b605b580 100644 --- a/consensus/types/src/beacon_state.rs +++ b/consensus/types/src/beacon_state.rs @@ -196,6 +196,12 @@ impl From for Hash256 { #[superstruct( variants_and_features_from = "FORK_ORDER", feature_dependencies = "FEATURE_DEPENDENCIES", + variant_type(name = "ForkName", getter = "fork_name_unchecked"), + feature_type( + name = "FeatureName", + list = "list_all_features", + check = "is_feature_enabled" + ), variant_attributes( derive( Derivative, @@ -475,16 +481,16 @@ impl BeaconState { /// Returns the name of the fork pertaining to `self`. /// /// Does not check if `self` is consistent with the fork dictated by `self.slot()`. - pub fn fork_name_unchecked(&self) -> ForkName { - match self { - BeaconState::Base { .. } => ForkName::Base, - BeaconState::Altair { .. } => ForkName::Altair, - BeaconState::Merge { .. } => ForkName::Merge, - BeaconState::Capella { .. } => ForkName::Capella, - BeaconState::Deneb { .. } => ForkName::Deneb, - BeaconState::Electra { .. } => ForkName::Electra, - } - } + //pub fn fork_name_unchecked(&self) -> ForkName { + // match self { + // BeaconState::Base { .. } => ForkName::Base, + // BeaconState::Altair { .. } => ForkName::Altair, + // BeaconState::Merge { .. } => ForkName::Merge, + // BeaconState::Capella { .. } => ForkName::Capella, + // BeaconState::Deneb { .. } => ForkName::Deneb, + // BeaconState::Electra { .. } => ForkName::Electra, + // } + //} /// Specialised deserialisation method that uses the `ChainSpec` as context. #[allow(clippy::arithmetic_side_effects)] diff --git a/consensus/types/src/builder_bid.rs b/consensus/types/src/builder_bid.rs index 121d3f8427..9bf5fbaa4d 100644 --- a/consensus/types/src/builder_bid.rs +++ b/consensus/types/src/builder_bid.rs @@ -2,7 +2,8 @@ use crate::beacon_block_body::KzgCommitments; use crate::{ ChainSpec, EthSpec, ExecutionPayloadHeaderCapella, ExecutionPayloadHeaderDeneb, ExecutionPayloadHeaderElectra, ExecutionPayloadHeaderMerge, ExecutionPayloadHeaderRef, - ExecutionPayloadHeaderRefMut, ForkName, ForkVersionDeserialize, SignedRoot, Uint256, + ExecutionPayloadHeaderRefMut, FeatureName, ForkName, ForkVersionDeserialize, SignedRoot, + Uint256, }; use bls::PublicKeyBytes; use bls::Signature; @@ -11,7 +12,15 @@ use superstruct::superstruct; use tree_hash_derive::TreeHash; #[superstruct( - variants(Merge, Capella, Deneb, Electra), + feature(Merge), + variants_and_features_from = "FORK_ORDER", + feature_dependencies = "FEATURE_DEPENDENCIES", + variant_type(name = "ForkName", getter = "fork_name"), + feature_type( + name = "FeatureName", + list = "list_all_features", + check = "is_feature_enabled" + ), variant_attributes( derive(PartialEq, Debug, Serialize, Deserialize, TreeHash, Clone), serde(bound = "E: EthSpec", deny_unknown_fields) @@ -31,7 +40,7 @@ pub struct BuilderBid { pub header: ExecutionPayloadHeaderDeneb, #[superstruct(only(Electra), partial_getter(rename = "header_electra"))] pub header: ExecutionPayloadHeaderElectra, - #[superstruct(only(Deneb, Electra))] + #[superstruct(feature(Deneb))] pub blob_kzg_commitments: KzgCommitments, #[serde(with = "serde_utils::quoted_u256")] pub value: Uint256, diff --git a/consensus/types/src/config_and_preset.rs b/consensus/types/src/config_and_preset.rs index f2a6e616da..60fe07c513 100644 --- a/consensus/types/src/config_and_preset.rs +++ b/consensus/types/src/config_and_preset.rs @@ -1,6 +1,6 @@ use crate::{ consts::altair, AltairPreset, BasePreset, BellatrixPreset, CapellaPreset, ChainSpec, Config, - DenebPreset, ElectraPreset, EthSpec, ForkName, + DenebPreset, ElectraPreset, EthSpec, FeatureName, ForkName, }; use maplit::hashmap; use serde::{Deserialize, Serialize}; @@ -12,7 +12,15 @@ use superstruct::superstruct; /// /// Mostly useful for the API. #[superstruct( - variants(Capella, Deneb, Electra), + feature(Capella), + variants_and_features_from = "FORK_ORDER", + feature_dependencies = "FEATURE_DEPENDENCIES", + variant_type(name = "ForkName", getter = "fork_name"), + feature_type( + name = "FeatureName", + list = "list_all_features", + check = "is_feature_enabled" + ), variant_attributes(derive(Serialize, Deserialize, Debug, PartialEq, Clone)) )] #[derive(Serialize, Deserialize, Debug, PartialEq, Clone)] @@ -29,10 +37,10 @@ pub struct ConfigAndPreset { pub bellatrix_preset: BellatrixPreset, #[serde(flatten)] pub capella_preset: CapellaPreset, - #[superstruct(only(Deneb, Electra))] + #[superstruct(feature(Deneb))] #[serde(flatten)] pub deneb_preset: DenebPreset, - #[superstruct(only(Electra))] + #[superstruct(feature(Electra))] #[serde(flatten)] pub electra_preset: ElectraPreset, /// The `extra_fields` map allows us to gracefully decode fields intended for future hard forks. diff --git a/consensus/types/src/execution_payload.rs b/consensus/types/src/execution_payload.rs index 27dc8cab0a..48cbfe017a 100644 --- a/consensus/types/src/execution_payload.rs +++ b/consensus/types/src/execution_payload.rs @@ -15,7 +15,16 @@ pub type Transactions = VariableList< pub type Withdrawals = VariableList::MaxWithdrawalsPerPayload>; #[superstruct( - variants(Merge, Capella, Deneb, Electra), + feature(Merge), + variants_and_features_from = "FORK_ORDER", + feature_dependencies = "FEATURE_DEPENDENCIES", + variant_type(name = "ForkName", getter = "fork_name"), + feature_type( + name = "FeatureName", + list = "list_all_features", + check = "is_feature_enabled" + ), + //variants(Merge, Capella, Deneb, Electra), variant_attributes( derive( Default, @@ -81,12 +90,12 @@ pub struct ExecutionPayload { pub block_hash: ExecutionBlockHash, #[serde(with = "ssz_types::serde_utils::list_of_hex_var_list")] pub transactions: Transactions, - #[superstruct(only(Capella, Deneb, Electra))] + #[superstruct(feature(Capella))] pub withdrawals: Withdrawals, - #[superstruct(only(Deneb, Electra), partial_getter(copy))] + #[superstruct(feature(Deneb))] #[serde(with = "serde_utils::quoted_u64")] pub blob_gas_used: u64, - #[superstruct(only(Deneb, Electra), partial_getter(copy))] + #[superstruct(feature(Deneb))] #[serde(with = "serde_utils::quoted_u64")] pub excess_blob_gas: u64, } @@ -189,13 +198,13 @@ impl ForkVersionDeserialize for ExecutionPayload { } } -impl ExecutionPayload { - pub fn fork_name(&self) -> ForkName { - match self { - ExecutionPayload::Merge(_) => ForkName::Merge, - ExecutionPayload::Capella(_) => ForkName::Capella, - ExecutionPayload::Deneb(_) => ForkName::Deneb, - ExecutionPayload::Electra(_) => ForkName::Electra, - } - } -} +//impl ExecutionPayload { +// pub fn fork_name(&self) -> ForkName { +// match self { +// ExecutionPayload::Merge(_) => ForkName::Merge, +// ExecutionPayload::Capella(_) => ForkName::Capella, +// ExecutionPayload::Deneb(_) => ForkName::Deneb, +// ExecutionPayload::Electra(_) => ForkName::Electra, +// } +// } +//} diff --git a/consensus/types/src/execution_payload_header.rs b/consensus/types/src/execution_payload_header.rs index 3d0b0aca41..66d06a1cd5 100644 --- a/consensus/types/src/execution_payload_header.rs +++ b/consensus/types/src/execution_payload_header.rs @@ -8,7 +8,15 @@ use tree_hash::TreeHash; use tree_hash_derive::TreeHash; #[superstruct( - variants(Merge, Capella, Deneb, Electra), + feature(Merge), + variants_and_features_from = "FORK_ORDER", + feature_dependencies = "FEATURE_DEPENDENCIES", + variant_type(name = "ForkName", getter = "fork_name"), + feature_type( + name = "FeatureName", + list = "list_all_features", + check = "is_feature_enabled" + ), variant_attributes( derive( Default, @@ -76,14 +84,14 @@ pub struct ExecutionPayloadHeader { pub block_hash: ExecutionBlockHash, #[superstruct(getter(copy))] pub transactions_root: Hash256, - #[superstruct(only(Capella, Deneb, Electra))] + #[superstruct(feature(Capella))] #[superstruct(getter(copy))] pub withdrawals_root: Hash256, - #[superstruct(only(Deneb, Electra))] + #[superstruct(feature(Deneb))] #[serde(with = "serde_utils::quoted_u64")] #[superstruct(getter(copy))] pub blob_gas_used: u64, - #[superstruct(only(Deneb, Electra))] + #[superstruct(feature(Deneb))] #[serde(with = "serde_utils::quoted_u64")] #[superstruct(getter(copy))] pub excess_blob_gas: u64, diff --git a/consensus/types/src/feature_name.rs b/consensus/types/src/feature_name.rs index aab2353681..14270005a8 100644 --- a/consensus/types/src/feature_name.rs +++ b/consensus/types/src/feature_name.rs @@ -3,6 +3,7 @@ // // 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. +#[derive(PartialEq)] pub enum FeatureName { // Altair. Altair, @@ -13,13 +14,5 @@ pub enum FeatureName { // Deneb. Deneb, // Electra. - // - // Supply deposits on chain. - EIP6110, - // EL triggerable exits. - EIP7002, - // Increase MAX_EFFECTIVE_BALANCE. - EIP7251, - // Committee index outside Attestation. - EIP7549, + Electra, } diff --git a/consensus/types/src/fork_order.rs b/consensus/types/src/fork_order.rs index 220f4ed7a7..c9ffa5c194 100644 --- a/consensus/types/src/fork_order.rs +++ b/consensus/types/src/fork_order.rs @@ -8,7 +8,7 @@ pub const FORK_ORDER: &[(ForkName, &[FeatureName])] = &[ (ForkName::Merge, &[FeatureName::Merge]), (ForkName::Capella, &[FeatureName::Capella]), (ForkName::Deneb, &[FeatureName::Deneb]), - (ForkName::Electra, &[]), + (ForkName::Electra, &[FeatureName::Electra]), ]; #[superstruct(feature_dependencies_decl = "FEATURE_DEPENDENCIES")] @@ -17,6 +17,7 @@ pub const FEATURE_DEPENDENCIES: &[(FeatureName, &[FeatureName])] = &[ (FeatureName::Merge, &[FeatureName::Altair]), (FeatureName::Capella, &[FeatureName::Merge]), (FeatureName::Deneb, &[FeatureName::Capella]), + (FeatureName::Electra, &[FeatureName::Deneb]), ]; #[cfg(test)] diff --git a/consensus/types/src/light_client_header.rs b/consensus/types/src/light_client_header.rs index 647ece9949..73cbd9ad55 100644 --- a/consensus/types/src/light_client_header.rs +++ b/consensus/types/src/light_client_header.rs @@ -1,5 +1,4 @@ use crate::ChainSpec; -use crate::ForkName; use crate::ForkVersionDeserialize; use crate::{light_client_update::*, BeaconBlockBody}; use crate::{ @@ -7,6 +6,7 @@ use crate::{ FixedVector, Hash256, SignedBeaconBlock, }; use crate::{BeaconBlockHeader, ExecutionPayloadHeader}; +use crate::{FeatureName, ForkName}; use derivative::Derivative; use serde::{Deserialize, Serialize}; use ssz::Decode; @@ -17,7 +17,15 @@ use test_random_derive::TestRandom; use tree_hash_derive::TreeHash; #[superstruct( - variants(Altair, Capella, Deneb), + feature(Altair), + variants_and_features_from = "FORK_ORDER", + feature_dependencies = "FEATURE_DEPENDENCIES", + variant_type(name = "ForkName", getter = "fork_name"), + feature_type( + name = "FeatureName", + list = "list_all_features", + check = "is_feature_enabled" + ), variant_attributes( derive( Debug, @@ -55,7 +63,7 @@ pub struct LightClientHeader { #[superstruct(only(Deneb), partial_getter(rename = "execution_payload_header_deneb"))] pub execution: ExecutionPayloadHeaderDeneb, - #[superstruct(only(Capella, Deneb))] + #[superstruct(feature(Capella))] pub execution_branch: FixedVector, #[ssz(skip_serializing, skip_deserializing)] diff --git a/consensus/types/src/payload.rs b/consensus/types/src/payload.rs index 18b3199bd3..3d7f6c2ad6 100644 --- a/consensus/types/src/payload.rs +++ b/consensus/types/src/payload.rs @@ -110,7 +110,15 @@ pub trait AbstractExecPayload: } #[superstruct( - variants(Merge, Capella, Deneb, Electra), + feature(Merge), + variants_and_features_from = "FORK_ORDER", + feature_dependencies = "FEATURE_DEPENDENCIES", + variant_type(name = "ForkName", getter = "fork_name"), + feature_type( + name = "FeatureName", + list = "list_all_features", + check = "is_feature_enabled" + ), variant_attributes( derive( Debug, @@ -442,7 +450,15 @@ impl TryFrom> for FullPayload { } #[superstruct( - variants(Merge, Capella, Deneb, Electra), + feature(Merge), + variants_and_features_from = "FORK_ORDER", + feature_dependencies = "FEATURE_DEPENDENCIES", + variant_type(name = "ForkName", getter = "fork_name"), + feature_type( + name = "FeatureName", + list = "list_all_features", + check = "is_feature_enabled" + ), variant_attributes( derive( Debug,