Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement EIP-7688: Forward compatible consensus data structures [WIP] #5920

Open
wants to merge 11 commits into
base: unstable
Choose a base branch
from
25 changes: 11 additions & 14 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ error-chain = "0.12"
ethereum-types = "0.14"
ethereum_hashing = "0.6.0"
ethereum_serde_utils = "0.5.2"
ethereum_ssz = "0.5"
ethereum_ssz_derive = "0.5"
ethereum_ssz = { git = "https://github.com/macladson/ethereum_ssz", branch = "stable-container" }
ethereum_ssz_derive = { git = "https://github.com/macladson/ethereum_ssz", branch = "stable-container" }
ethers-core = "1"
ethers-providers = { version = "1", default-features = false }
exit-future = "0.2"
Expand All @@ -134,7 +134,7 @@ libsecp256k1 = "0.7"
log = "0.4"
lru = "0.12"
maplit = "1"
milhouse = "0.1"
milhouse = { git = "https://github.com/macladson/milhouse", branch = "stable-container" }
num_cpus = "1"
parking_lot = "0.12"
paste = "1"
Expand All @@ -160,7 +160,7 @@ slog-term = "2"
sloggers = { version = "2", features = ["json"] }
smallvec = "1.11.2"
snap = "1"
ssz_types = "0.6"
ssz_types = { git = "https://github.com/macladson/ssz_types", branch = "stable-container" }
strum = { version = "0.24", features = ["derive"] }
superstruct = "0.8"
syn = "1"
Expand All @@ -174,8 +174,8 @@ tracing-appender = "0.2"
tracing-core = "0.1"
tracing-log = "0.2"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
tree_hash = "0.6"
tree_hash_derive = "0.6"
tree_hash = { git = "https://github.com/macladson/tree_hash", branch = "stable-container" }
tree_hash_derive = { git = "https://github.com/macladson/tree_hash", branch = "stable-container" }
url = "2"
uuid = { version = "0.8", features = ["serde", "v4"] }
warp = { version = "0.3.7", default-features = false, features = ["tls"] }
Expand Down
2 changes: 1 addition & 1 deletion beacon_node/beacon_chain/src/beacon_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3286,7 +3286,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
{
let mut slashable_cache = self.observed_slashable.write();
for header in blobs
.into_iter()
.iter()
.filter_map(|b| b.as_ref().map(|b| b.signed_block_header.clone()))
.unique()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ impl<E: EthSpec> PendingComponents<E> {
};
let num_blobs_expected = diet_executed_block.num_blobs_expected();
let Some(verified_blobs) = verified_blobs
.into_iter()
.iter()
.cloned()
.map(|b| b.map(|b| b.to_blob()))
.take(num_blobs_expected)
Expand Down
11 changes: 10 additions & 1 deletion consensus/types/src/attestation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ pub enum Error {
serde(bound = "E: EthSpec", deny_unknown_fields),
arbitrary(bound = "E: EthSpec"),
),
specific_variant_attributes(tree_hash(
struct_behaviour = "profile",
max_fields = "typenum::U8"
)),
ref_attributes(derive(TreeHash), tree_hash(enum_behaviour = "transparent")),
cast_error(ty = "Error", expr = "Error::IncorrectStateVariant"),
partial_getter_error(ty = "Error", expr = "Error::IncorrectStateVariant")
Expand All @@ -67,13 +71,18 @@ pub enum Error {
#[arbitrary(bound = "E: EthSpec")]
pub struct Attestation<E: EthSpec> {
#[superstruct(only(Base), partial_getter(rename = "aggregation_bits_base"))]
#[tree_hash(stable_index = 0)]
pub aggregation_bits: BitList<E::MaxValidatorsPerCommittee>,
#[superstruct(only(Electra), partial_getter(rename = "aggregation_bits_electra"))]
#[tree_hash(stable_index = 0)]
pub aggregation_bits: BitList<E::MaxValidatorsPerSlot>,
#[tree_hash(stable_index = 1)]
pub data: AttestationData,
#[tree_hash(stable_index = 2)]
pub signature: AggregateSignature,
#[superstruct(only(Electra))]
#[tree_hash(stable_index = 3)]
pub committee_bits: BitVector<E::MaxCommitteesPerSlot>,
pub signature: AggregateSignature,
}

impl<E: EthSpec> Hash for Attestation<E> {
Expand Down
6 changes: 6 additions & 0 deletions consensus/types/src/attester_slashing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ use tree_hash_derive::TreeHash;
serde(bound = "E: EthSpec"),
arbitrary(bound = "E: EthSpec")
),
specific_variant_attributes(tree_hash(
struct_behaviour = "profile",
max_fields = "typenum::U8"
)),
ref_attributes(derive(Debug))
)]
#[derive(
Expand All @@ -40,8 +44,10 @@ use tree_hash_derive::TreeHash;
#[tree_hash(enum_behaviour = "transparent")]
pub struct AttesterSlashing<E: EthSpec> {
#[superstruct(flatten)]
#[tree_hash(stable_index = 0)]
pub attestation_1: IndexedAttestation<E>,
#[superstruct(flatten)]
#[tree_hash(stable_index = 1)]
pub attestation_2: IndexedAttestation<E>,
}

Expand Down
23 changes: 22 additions & 1 deletion consensus/types/src/beacon_block_body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ pub const BLOB_KZG_COMMITMENTS_INDEX: usize = 11;
Bellatrix(metastruct(mappings(beacon_block_body_bellatrix_fields(groups(fields))))),
Capella(metastruct(mappings(beacon_block_body_capella_fields(groups(fields))))),
Deneb(metastruct(mappings(beacon_block_body_deneb_fields(groups(fields))))),
Electra(metastruct(mappings(beacon_block_body_electra_fields(groups(fields))))),
Electra(
metastruct(mappings(beacon_block_body_electra_fields(groups(fields)))),
tree_hash(struct_behaviour = "profile", max_fields = "typenum::U64"),
),
),
cast_error(ty = "Error", expr = "Error::IncorrectStateVariant"),
partial_getter_error(ty = "Error", expr = "Error::IncorrectStateVariant")
Expand All @@ -68,28 +71,39 @@ pub const BLOB_KZG_COMMITMENTS_INDEX: usize = 11;
#[serde(bound = "E: EthSpec, Payload: AbstractExecPayload<E>")]
#[arbitrary(bound = "E: EthSpec, Payload: AbstractExecPayload<E>")]
pub struct BeaconBlockBody<E: EthSpec, Payload: AbstractExecPayload<E> = FullPayload<E>> {
#[tree_hash(stable_index = 0)]
pub randao_reveal: Signature,
#[tree_hash(stable_index = 1)]
pub eth1_data: Eth1Data,
#[tree_hash(stable_index = 2)]
pub graffiti: Graffiti,
#[tree_hash(stable_index = 3)]
pub proposer_slashings: VariableList<ProposerSlashing, E::MaxProposerSlashings>,
#[superstruct(
only(Base, Altair, Bellatrix, Capella, Deneb),
partial_getter(rename = "attester_slashings_base")
)]
#[tree_hash(stable_index = 4)]
pub attester_slashings: VariableList<AttesterSlashingBase<E>, E::MaxAttesterSlashings>,
#[superstruct(only(Electra), partial_getter(rename = "attester_slashings_electra"))]
#[tree_hash(stable_index = 4)]
pub attester_slashings:
VariableList<AttesterSlashingElectra<E>, E::MaxAttesterSlashingsElectra>,
#[superstruct(
only(Base, Altair, Bellatrix, Capella, Deneb),
partial_getter(rename = "attestations_base")
)]
#[tree_hash(stable_index = 5)]
pub attestations: VariableList<AttestationBase<E>, E::MaxAttestations>,
#[superstruct(only(Electra), partial_getter(rename = "attestations_electra"))]
#[tree_hash(stable_index = 5)]
pub attestations: VariableList<AttestationElectra<E>, E::MaxAttestationsElectra>,
#[tree_hash(stable_index = 6)]
pub deposits: VariableList<Deposit, E::MaxDeposits>,
#[tree_hash(stable_index = 7)]
pub voluntary_exits: VariableList<SignedVoluntaryExit, E::MaxVoluntaryExits>,
#[superstruct(only(Altair, Bellatrix, Capella, Deneb, Electra))]
#[tree_hash(stable_index = 8)]
pub sync_aggregate: SyncAggregate<E>,
// 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
Expand All @@ -99,22 +113,29 @@ pub struct BeaconBlockBody<E: EthSpec, Payload: AbstractExecPayload<E> = FullPay
partial_getter(rename = "execution_payload_bellatrix")
)]
#[serde(flatten)]
#[tree_hash(stable_index = 9)]
pub execution_payload: Payload::Bellatrix,
#[superstruct(only(Capella), partial_getter(rename = "execution_payload_capella"))]
#[serde(flatten)]
#[tree_hash(stable_index = 9)]
pub execution_payload: Payload::Capella,
#[superstruct(only(Deneb), partial_getter(rename = "execution_payload_deneb"))]
#[serde(flatten)]
#[tree_hash(stable_index = 9)]
pub execution_payload: Payload::Deneb,
#[superstruct(only(Electra), partial_getter(rename = "execution_payload_electra"))]
#[serde(flatten)]
#[tree_hash(stable_index = 9)]
pub execution_payload: Payload::Electra,
#[superstruct(only(Capella, Deneb, Electra))]
#[tree_hash(stable_index = 10)]
pub bls_to_execution_changes:
VariableList<SignedBlsToExecutionChange, E::MaxBlsToExecutionChanges>,
#[superstruct(only(Deneb, Electra))]
#[tree_hash(stable_index = 11)]
pub blob_kzg_commitments: KzgCommitments<E>,
#[superstruct(only(Electra))]
#[tree_hash(stable_index = 12)]
pub consolidations: VariableList<SignedConsolidation, E::MaxConsolidations>,
#[superstruct(only(Base, Altair))]
#[metastruct(exclude_from(fields))]
Expand Down
Loading
Loading