mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-19 13:58:28 +00:00
BeaconBlockBody updates per eip-7732
This commit is contained in:
@@ -672,10 +672,10 @@ impl<E: EthSpec, Payload: AbstractExecPayload<E>> EmptyBlock for BeaconBlockGloa
|
||||
deposits: VariableList::empty(),
|
||||
voluntary_exits: VariableList::empty(),
|
||||
sync_aggregate: SyncAggregate::empty(),
|
||||
execution_payload: Payload::Gloas::default(),
|
||||
bls_to_execution_changes: VariableList::empty(),
|
||||
blob_kzg_commitments: VariableList::empty(),
|
||||
execution_requests: ExecutionRequests::default(),
|
||||
signed_execution_payload_header: SignedExecutionBid::empty(),
|
||||
payload_attestations: VariableList::empty(),
|
||||
_phantom: PhantomData,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,7 +61,11 @@ pub const BLOB_KZG_COMMITMENTS_INDEX: usize = 11;
|
||||
Deneb(metastruct(mappings(beacon_block_body_deneb_fields(groups(fields))))),
|
||||
Electra(metastruct(mappings(beacon_block_body_electra_fields(groups(fields))))),
|
||||
Fulu(metastruct(mappings(beacon_block_body_fulu_fields(groups(fields))))),
|
||||
Gloas(metastruct(mappings(beacon_block_body_gloas_fields(groups(fields))))),
|
||||
// we relax the trait bounds for gloas since it doesn't contain a Payload
|
||||
Gloas(
|
||||
derivative(PartialEq, Hash(bound = "E: EthSpec")),
|
||||
metastruct(mappings(beacon_block_body_gloas_fields(groups(fields))))
|
||||
),
|
||||
),
|
||||
cast_error(ty = "Error", expr = "Error::IncorrectStateVariant"),
|
||||
partial_getter_error(ty = "Error", expr = "Error::IncorrectStateVariant")
|
||||
@@ -127,17 +131,21 @@ pub struct BeaconBlockBody<E: EthSpec, Payload: AbstractExecPayload<E> = FullPay
|
||||
#[superstruct(only(Fulu), partial_getter(rename = "execution_payload_fulu"))]
|
||||
#[serde(flatten)]
|
||||
pub execution_payload: Payload::Fulu,
|
||||
#[superstruct(only(Gloas), partial_getter(rename = "execution_payload_gloas"))]
|
||||
#[serde(flatten)]
|
||||
pub execution_payload: Payload::Gloas,
|
||||
// execution_payload removed from Gloas, replaced with signed_execution_payload_header below
|
||||
#[superstruct(only(Capella, Deneb, Electra, Fulu, Gloas))]
|
||||
pub bls_to_execution_changes:
|
||||
VariableList<SignedBlsToExecutionChange, E::MaxBlsToExecutionChanges>,
|
||||
#[superstruct(only(Deneb, Electra, Fulu, Gloas))]
|
||||
// blob_kzg_commitments removed from Gloas, moved to `ExecutionPayloadEnvelope`
|
||||
#[superstruct(only(Deneb, Electra, Fulu))]
|
||||
pub blob_kzg_commitments: KzgCommitments<E>,
|
||||
#[superstruct(only(Electra, Fulu, Gloas))]
|
||||
// execution_requests removed from Gloas, moved to `ExecutionPayloadEnvelope`
|
||||
#[superstruct(only(Electra, Fulu))]
|
||||
pub execution_requests: ExecutionRequests<E>,
|
||||
#[superstruct(only(Base, Altair))]
|
||||
#[superstruct(only(Gloas))]
|
||||
pub signed_execution_payload_header: SignedExecutionBid,
|
||||
#[superstruct(only(Gloas))]
|
||||
pub payload_attestations: VariableList<PayloadAttestation<E>, E::MaxPayloadAttestations>,
|
||||
#[superstruct(only(Base, Altair, Gloas))]
|
||||
#[metastruct(exclude_from(fields))]
|
||||
#[ssz(skip_serializing, skip_deserializing)]
|
||||
#[tree_hash(skip_hashing)]
|
||||
@@ -160,13 +168,12 @@ impl<E: EthSpec, Payload: AbstractExecPayload<E>> BeaconBlockBody<E, Payload> {
|
||||
impl<'a, E: EthSpec, Payload: AbstractExecPayload<E>> BeaconBlockBodyRef<'a, E, Payload> {
|
||||
pub fn execution_payload(&self) -> Result<Payload::Ref<'a>, Error> {
|
||||
match self {
|
||||
Self::Base(_) | Self::Altair(_) => Err(Error::IncorrectStateVariant),
|
||||
Self::Base(_) | Self::Altair(_) | Self::Gloas(_) => Err(Error::IncorrectStateVariant),
|
||||
Self::Bellatrix(body) => Ok(Payload::Ref::from(&body.execution_payload)),
|
||||
Self::Capella(body) => Ok(Payload::Ref::from(&body.execution_payload)),
|
||||
Self::Deneb(body) => Ok(Payload::Ref::from(&body.execution_payload)),
|
||||
Self::Electra(body) => Ok(Payload::Ref::from(&body.execution_payload)),
|
||||
Self::Fulu(body) => Ok(Payload::Ref::from(&body.execution_payload)),
|
||||
Self::Gloas(body) => Ok(Payload::Ref::from(&body.execution_payload)),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -230,10 +237,12 @@ impl<'a, E: EthSpec, Payload: AbstractExecPayload<E>> BeaconBlockBodyRef<'a, E,
|
||||
kzg_commitments_proof: &[Hash256],
|
||||
) -> Result<FixedVector<Hash256, E::KzgCommitmentInclusionProofDepth>, Error> {
|
||||
match self {
|
||||
Self::Base(_) | Self::Altair(_) | Self::Bellatrix(_) | Self::Capella(_) => {
|
||||
Err(Error::IncorrectStateVariant)
|
||||
}
|
||||
Self::Deneb(_) | Self::Electra(_) | Self::Fulu(_) | Self::Gloas(_) => {
|
||||
Self::Base(_)
|
||||
| Self::Altair(_)
|
||||
| Self::Bellatrix(_)
|
||||
| Self::Capella(_)
|
||||
| Self::Gloas(_) => Err(Error::IncorrectStateVariant),
|
||||
Self::Deneb(_) | Self::Electra(_) | Self::Fulu(_) => {
|
||||
// We compute the branches by generating 2 merkle trees:
|
||||
// 1. Merkle tree for the `blob_kzg_commitments` List object
|
||||
// 2. Merkle tree for the `BeaconBlockBody` container
|
||||
@@ -512,6 +521,45 @@ impl<E: EthSpec> From<BeaconBlockBodyAltair<E, BlindedPayload<E>>>
|
||||
}
|
||||
}
|
||||
|
||||
// Post-Fulu block bodies without payloads can be converted into block bodies with payloads
|
||||
impl<E: EthSpec> From<BeaconBlockBodyGloas<E, BlindedPayload<E>>>
|
||||
for BeaconBlockBodyGloas<E, FullPayload<E>>
|
||||
{
|
||||
fn from(body: BeaconBlockBodyGloas<E, BlindedPayload<E>>) -> Self {
|
||||
let BeaconBlockBodyGloas {
|
||||
randao_reveal,
|
||||
eth1_data,
|
||||
graffiti,
|
||||
proposer_slashings,
|
||||
attester_slashings,
|
||||
attestations,
|
||||
deposits,
|
||||
voluntary_exits,
|
||||
sync_aggregate,
|
||||
bls_to_execution_changes,
|
||||
signed_execution_payload_header,
|
||||
payload_attestations,
|
||||
_phantom,
|
||||
} = body;
|
||||
|
||||
BeaconBlockBodyGloas {
|
||||
randao_reveal,
|
||||
eth1_data,
|
||||
graffiti,
|
||||
proposer_slashings,
|
||||
attester_slashings,
|
||||
attestations,
|
||||
deposits,
|
||||
voluntary_exits,
|
||||
sync_aggregate,
|
||||
bls_to_execution_changes,
|
||||
signed_execution_payload_header,
|
||||
payload_attestations,
|
||||
_phantom: PhantomData,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Likewise bodies with payloads can be transformed into bodies without.
|
||||
impl<E: EthSpec> From<BeaconBlockBodyBase<E, FullPayload<E>>>
|
||||
for (
|
||||
@@ -822,10 +870,10 @@ impl<E: EthSpec> From<BeaconBlockBodyGloas<E, FullPayload<E>>>
|
||||
deposits,
|
||||
voluntary_exits,
|
||||
sync_aggregate,
|
||||
execution_payload: FullPayloadGloas { execution_payload },
|
||||
bls_to_execution_changes,
|
||||
blob_kzg_commitments,
|
||||
execution_requests,
|
||||
signed_execution_payload_header,
|
||||
payload_attestations,
|
||||
_phantom,
|
||||
} = body;
|
||||
|
||||
(
|
||||
@@ -839,14 +887,12 @@ impl<E: EthSpec> From<BeaconBlockBodyGloas<E, FullPayload<E>>>
|
||||
deposits,
|
||||
voluntary_exits,
|
||||
sync_aggregate,
|
||||
execution_payload: BlindedPayloadGloas {
|
||||
execution_payload_header: From::from(&execution_payload),
|
||||
},
|
||||
bls_to_execution_changes,
|
||||
blob_kzg_commitments: blob_kzg_commitments.clone(),
|
||||
execution_requests,
|
||||
signed_execution_payload_header,
|
||||
payload_attestations,
|
||||
_phantom: PhantomData,
|
||||
},
|
||||
Some(execution_payload),
|
||||
None,
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1046,39 +1092,8 @@ impl<E: EthSpec> BeaconBlockBodyFulu<E, FullPayload<E>> {
|
||||
|
||||
impl<E: EthSpec> BeaconBlockBodyGloas<E, FullPayload<E>> {
|
||||
pub fn clone_as_blinded(&self) -> BeaconBlockBodyGloas<E, BlindedPayload<E>> {
|
||||
let BeaconBlockBodyGloas {
|
||||
randao_reveal,
|
||||
eth1_data,
|
||||
graffiti,
|
||||
proposer_slashings,
|
||||
attester_slashings,
|
||||
attestations,
|
||||
deposits,
|
||||
voluntary_exits,
|
||||
sync_aggregate,
|
||||
execution_payload: FullPayloadGloas { execution_payload },
|
||||
bls_to_execution_changes,
|
||||
blob_kzg_commitments,
|
||||
execution_requests,
|
||||
} = self;
|
||||
|
||||
BeaconBlockBodyGloas {
|
||||
randao_reveal: randao_reveal.clone(),
|
||||
eth1_data: eth1_data.clone(),
|
||||
graffiti: *graffiti,
|
||||
proposer_slashings: proposer_slashings.clone(),
|
||||
attester_slashings: attester_slashings.clone(),
|
||||
attestations: attestations.clone(),
|
||||
deposits: deposits.clone(),
|
||||
voluntary_exits: voluntary_exits.clone(),
|
||||
sync_aggregate: sync_aggregate.clone(),
|
||||
execution_payload: BlindedPayloadGloas {
|
||||
execution_payload_header: execution_payload.into(),
|
||||
},
|
||||
bls_to_execution_changes: bls_to_execution_changes.clone(),
|
||||
blob_kzg_commitments: blob_kzg_commitments.clone(),
|
||||
execution_requests: execution_requests.clone(),
|
||||
}
|
||||
let (block_body, _payload) = self.clone().into();
|
||||
block_body
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ use merkle_proof::MerkleTree;
|
||||
use serde::{Deserialize, Deserializer, Serialize};
|
||||
use ssz_derive::{Decode, Encode};
|
||||
use std::fmt;
|
||||
use std::marker::PhantomData;
|
||||
use superstruct::superstruct;
|
||||
use test_random_derive::TestRandom;
|
||||
use tree_hash::TreeHash;
|
||||
@@ -648,10 +649,11 @@ impl<E: EthSpec> SignedBeaconBlockFulu<E, BlindedPayload<E>> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Gloas doesn't support BlindedPayload, but we keep this impl for compatibility purposes of the SignedBeaconBlock type
|
||||
impl<E: EthSpec> SignedBeaconBlockGloas<E, BlindedPayload<E>> {
|
||||
pub fn into_full_block(
|
||||
self,
|
||||
execution_payload: ExecutionPayloadGloas<E>,
|
||||
_execution_payload: ExecutionPayloadGloas<E>,
|
||||
) -> SignedBeaconBlockGloas<E, FullPayload<E>> {
|
||||
let SignedBeaconBlockGloas {
|
||||
message:
|
||||
@@ -671,10 +673,10 @@ impl<E: EthSpec> SignedBeaconBlockGloas<E, BlindedPayload<E>> {
|
||||
deposits,
|
||||
voluntary_exits,
|
||||
sync_aggregate,
|
||||
execution_payload: BlindedPayloadGloas { .. },
|
||||
bls_to_execution_changes,
|
||||
blob_kzg_commitments,
|
||||
execution_requests,
|
||||
signed_execution_payload_header,
|
||||
payload_attestations,
|
||||
..
|
||||
},
|
||||
},
|
||||
signature,
|
||||
@@ -695,10 +697,10 @@ impl<E: EthSpec> SignedBeaconBlockGloas<E, BlindedPayload<E>> {
|
||||
deposits,
|
||||
voluntary_exits,
|
||||
sync_aggregate,
|
||||
execution_payload: FullPayloadGloas { execution_payload },
|
||||
bls_to_execution_changes,
|
||||
blob_kzg_commitments,
|
||||
execution_requests,
|
||||
signed_execution_payload_header,
|
||||
payload_attestations,
|
||||
_phantom: PhantomData,
|
||||
},
|
||||
},
|
||||
signature,
|
||||
|
||||
Reference in New Issue
Block a user