mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-20 21:34:46 +00:00
Add syntax to more types
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -196,6 +196,12 @@ impl From<BeaconStateHash> 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<E: EthSpec> BeaconState<E> {
|
||||
/// 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)]
|
||||
|
||||
@@ -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<E: EthSpec> {
|
||||
pub header: ExecutionPayloadHeaderDeneb<E>,
|
||||
#[superstruct(only(Electra), partial_getter(rename = "header_electra"))]
|
||||
pub header: ExecutionPayloadHeaderElectra<E>,
|
||||
#[superstruct(only(Deneb, Electra))]
|
||||
#[superstruct(feature(Deneb))]
|
||||
pub blob_kzg_commitments: KzgCommitments<E>,
|
||||
#[serde(with = "serde_utils::quoted_u256")]
|
||||
pub value: Uint256,
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -15,7 +15,16 @@ pub type Transactions<E> = VariableList<
|
||||
pub type Withdrawals<E> = VariableList<Withdrawal, <E as EthSpec>::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<E: EthSpec> {
|
||||
pub block_hash: ExecutionBlockHash,
|
||||
#[serde(with = "ssz_types::serde_utils::list_of_hex_var_list")]
|
||||
pub transactions: Transactions<E>,
|
||||
#[superstruct(only(Capella, Deneb, Electra))]
|
||||
#[superstruct(feature(Capella))]
|
||||
pub withdrawals: Withdrawals<E>,
|
||||
#[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<E: EthSpec> ForkVersionDeserialize for ExecutionPayload<E> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: EthSpec> ExecutionPayload<E> {
|
||||
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<E: EthSpec> ExecutionPayload<E> {
|
||||
// pub fn fork_name(&self) -> ForkName {
|
||||
// match self {
|
||||
// ExecutionPayload::Merge(_) => ForkName::Merge,
|
||||
// ExecutionPayload::Capella(_) => ForkName::Capella,
|
||||
// ExecutionPayload::Deneb(_) => ForkName::Deneb,
|
||||
// ExecutionPayload::Electra(_) => ForkName::Electra,
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
@@ -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<E: EthSpec> {
|
||||
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,
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
|
||||
@@ -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)]
|
||||
|
||||
@@ -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<E: EthSpec> {
|
||||
#[superstruct(only(Deneb), partial_getter(rename = "execution_payload_header_deneb"))]
|
||||
pub execution: ExecutionPayloadHeaderDeneb<E>,
|
||||
|
||||
#[superstruct(only(Capella, Deneb))]
|
||||
#[superstruct(feature(Capella))]
|
||||
pub execution_branch: FixedVector<Hash256, ExecutionPayloadProofLen>,
|
||||
|
||||
#[ssz(skip_serializing, skip_deserializing)]
|
||||
|
||||
@@ -110,7 +110,15 @@ pub trait AbstractExecPayload<E: EthSpec>:
|
||||
}
|
||||
|
||||
#[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<E: EthSpec> TryFrom<ExecutionPayloadHeader<E>> for FullPayload<E> {
|
||||
}
|
||||
|
||||
#[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,
|
||||
|
||||
Reference in New Issue
Block a user