Add syntax to more types

This commit is contained in:
Mac L
2024-05-01 13:09:42 +10:00
parent 5c80d92b22
commit 2bac4b8a19
18 changed files with 181 additions and 75 deletions

View File

@@ -0,0 +1,2 @@
// Dummy build.rs file to enable OUT_DIR usage by superstruct
fn main() {}

View File

@@ -45,8 +45,8 @@ pub fn calculate_execution_block_hash<E: EthSpec>(
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,
);

View File

@@ -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<E: EthSpec> {
#[serde(rename = "hash")]
pub block_hash: ExecutionBlockHash,
pub transactions: Vec<Transaction>,
#[superstruct(only(Capella, Deneb, Electra))]
#[superstruct(feature(Capella))]
pub withdrawals: Vec<JsonWithdrawal>,
#[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<E: EthSpec> {
#[superstruct(only(Electra), partial_getter(rename = "execution_payload_electra"))]
pub execution_payload: ExecutionPayloadElectra<E>,
pub block_value: Uint256,
#[superstruct(only(Deneb, Electra))]
#[superstruct(feature(Deneb))]
pub blobs_bundle: BlobsBundle<E>,
#[superstruct(only(Deneb, Electra), partial_getter(copy))]
#[superstruct(feature(Deneb), partial_getter(copy))]
pub should_override_builder: bool,
}

View File

@@ -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<E>,
#[superstruct(only(Electra), partial_getter(rename = "execution_payload_electra"))]
pub execution_payload: &'block ExecutionPayloadElectra<E>,
#[superstruct(only(Deneb, Electra))]
#[superstruct(feature(Deneb))]
pub versioned_hashes: Vec<VersionedHash>,
#[superstruct(only(Deneb, Electra))]
#[superstruct(feature(Deneb))]
pub parent_beacon_block_root: Hash256,
}

View File

@@ -0,0 +1,2 @@
// Dummy build.rs file to enable OUT_DIR usage by superstruct
fn main() {}

View File

@@ -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<PendingAttestation<E>, E::MaxPendingAttestations>,
// Participation (Altair and later)
#[superstruct(only(Altair, Merge, Capella, Deneb, Electra))]
#[superstruct(feature(Altair))]
pub previous_epoch_participation: VariableList<ParticipationFlags, E::ValidatorRegistryLimit>,
#[superstruct(only(Altair, Merge, Capella, Deneb, Electra))]
#[superstruct(feature(Altair))]
pub current_epoch_participation: VariableList<ParticipationFlags, E::ValidatorRegistryLimit>,
// 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<u64, E::ValidatorRegistryLimit>,
// Light-client sync committees
#[superstruct(only(Altair, Merge, Capella, Deneb, Electra))]
#[superstruct(feature(Altair))]
pub current_sync_committee: Arc<SyncCommittee<E>>,
#[superstruct(only(Altair, Merge, Capella, Deneb, Electra))]
#[superstruct(feature(Altair))]
pub next_sync_committee: Arc<SyncCommittee<E>>,
// Execution
@@ -110,13 +117,13 @@ where
pub latest_execution_payload_header: ExecutionPayloadHeaderElectra<E>,
// 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<VariableList<HistoricalSummary, E::HistoricalRootsLimit>>,
}