Capella eip 4844 cleanup (#3652)

* add capella gossip boiler plate

* get everything compiling

Co-authored-by: realbigsean <sean@sigmaprime.io
Co-authored-by: Mark Mackey <mark@sigmaprime.io>

* small cleanup

* small cleanup

* cargo fix + some test cleanup

* improve block production

* add fixme for potential panic

Co-authored-by: Mark Mackey <mark@sigmaprime.io>
This commit is contained in:
realbigsean
2022-10-26 15:15:26 -04:00
committed by GitHub
parent 221c433d62
commit 137f230344
52 changed files with 1392 additions and 630 deletions

View File

@@ -326,9 +326,9 @@ pub fn partially_verify_execution_payload<'payload, T: EthSpec, Payload: Abstrac
) -> Result<(), BlockProcessingError> {
if is_merge_transition_complete(state) {
block_verify!(
payload.parent_hash() == *state.latest_execution_payload_header()?.block_hash(),
payload.parent_hash() == state.latest_execution_payload_header()?.block_hash(),
BlockProcessingError::ExecutionHashChainIncontiguous {
expected: *state.latest_execution_payload_header()?.block_hash(),
expected: state.latest_execution_payload_header()?.block_hash(),
found: payload.parent_hash(),
}
);

View File

@@ -3,7 +3,7 @@ use types::beacon_state::BeaconState;
use types::eth_spec::EthSpec;
pub fn process_full_withdrawals<T: EthSpec>(
state: &mut BeaconState<T>,
_state: &mut BeaconState<T>,
) -> Result<(), EpochProcessingError> {
todo!("implement this");
Ok(())

View File

@@ -3,7 +3,7 @@ use types::beacon_state::BeaconState;
use types::eth_spec::EthSpec;
pub fn process_partial_withdrawals<T: EthSpec>(
state: &mut BeaconState<T>,
_state: &mut BeaconState<T>,
) -> Result<(), EpochProcessingError> {
todo!("implement this");
Ok(())

View File

@@ -253,11 +253,14 @@ impl ChainSpec {
pub fn fork_name_at_epoch(&self, epoch: Epoch) -> ForkName {
match self.eip4844_fork_epoch {
Some(fork_epoch) if epoch >= fork_epoch => ForkName::Eip4844,
_ => match self.bellatrix_fork_epoch {
Some(fork_epoch) if epoch >= fork_epoch => ForkName::Merge,
_ => match self.altair_fork_epoch {
Some(fork_epoch) if epoch >= fork_epoch => ForkName::Altair,
_ => ForkName::Base,
_ => match self.capella_fork_epoch {
Some(fork_epoch) if epoch >= fork_epoch => ForkName::Capella,
_ => match self.bellatrix_fork_epoch {
Some(fork_epoch) if epoch >= fork_epoch => ForkName::Merge,
_ => match self.altair_fork_epoch {
Some(fork_epoch) if epoch >= fork_epoch => ForkName::Altair,
_ => ForkName::Base,
},
},
},
}

View File

@@ -43,28 +43,40 @@ pub type Transactions<T> = VariableList<
#[tree_hash(enum_behaviour = "transparent")]
#[cfg_attr(feature = "arbitrary-fuzz", derive(arbitrary::Arbitrary))]
pub struct ExecutionPayload<T: EthSpec> {
#[superstruct(getter(copy))]
pub parent_hash: ExecutionBlockHash,
#[superstruct(getter(copy))]
pub fee_recipient: Address,
#[superstruct(getter(copy))]
pub state_root: Hash256,
#[superstruct(getter(copy))]
pub receipts_root: Hash256,
#[serde(with = "ssz_types::serde_utils::hex_fixed_vec")]
pub logs_bloom: FixedVector<u8, T::BytesPerLogsBloom>,
#[superstruct(getter(copy))]
pub prev_randao: Hash256,
#[serde(with = "eth2_serde_utils::quoted_u64")]
#[superstruct(getter(copy))]
pub block_number: u64,
#[serde(with = "eth2_serde_utils::quoted_u64")]
#[superstruct(getter(copy))]
pub gas_limit: u64,
#[serde(with = "eth2_serde_utils::quoted_u64")]
#[superstruct(getter(copy))]
pub gas_used: u64,
#[serde(with = "eth2_serde_utils::quoted_u64")]
#[superstruct(getter(copy))]
pub timestamp: u64,
#[serde(with = "ssz_types::serde_utils::hex_var_list")]
pub extra_data: VariableList<u8, T::MaxExtraDataBytes>,
#[serde(with = "eth2_serde_utils::quoted_u256")]
#[superstruct(getter(copy))]
pub base_fee_per_gas: Uint256,
#[superstruct(only(Eip4844))]
#[serde(with = "eth2_serde_utils::quoted_u64")]
#[superstruct(getter(copy))]
pub excess_blobs: u64,
#[superstruct(getter(copy))]
pub block_hash: ExecutionBlockHash,
#[serde(with = "ssz_types::serde_utils::list_of_hex_var_list")]
pub transactions: Transactions<T>,
@@ -94,8 +106,7 @@ impl<T: EthSpec> ExecutionPayload<T> {
// Max size of variable length `transactions` field
+ (T::max_transactions_per_payload() * (ssz::BYTES_PER_LENGTH_OFFSET + T::max_bytes_per_transaction()))
// Max size of variable length `withdrawals` field
// TODO: check this
+ (T::max_withdrawals_per_payload() * (ssz::BYTES_PER_LENGTH_OFFSET + <Withdrawal as Encode>::ssz_fixed_len()))
+ (T::max_withdrawals_per_payload() * <Withdrawal as Encode>::ssz_fixed_len())
}
#[allow(clippy::integer_arithmetic)]
@@ -108,8 +119,7 @@ impl<T: EthSpec> ExecutionPayload<T> {
// Max size of variable length `transactions` field
+ (T::max_transactions_per_payload() * (ssz::BYTES_PER_LENGTH_OFFSET + T::max_bytes_per_transaction()))
// Max size of variable length `withdrawals` field
// TODO: check this
+ (T::max_withdrawals_per_payload() * (ssz::BYTES_PER_LENGTH_OFFSET + <Withdrawal as Encode>::ssz_fixed_len()))
+ (T::max_withdrawals_per_payload() * <Withdrawal as Encode>::ssz_fixed_len())
}
pub fn blob_txns_iter(&self) -> Iter<'_, Transaction<T::MaxBytesPerTransaction>> {

View File

@@ -37,31 +37,45 @@ use BeaconStateError;
#[ssz(enum_behaviour = "transparent")]
#[cfg_attr(feature = "arbitrary-fuzz", derive(arbitrary::Arbitrary))]
pub struct ExecutionPayloadHeader<T: EthSpec> {
#[superstruct(getter(copy))]
pub parent_hash: ExecutionBlockHash,
#[superstruct(getter(copy))]
pub fee_recipient: Address,
#[superstruct(getter(copy))]
pub state_root: Hash256,
#[superstruct(getter(copy))]
pub receipts_root: Hash256,
#[serde(with = "ssz_types::serde_utils::hex_fixed_vec")]
pub logs_bloom: FixedVector<u8, T::BytesPerLogsBloom>,
#[superstruct(getter(copy))]
pub prev_randao: Hash256,
#[serde(with = "eth2_serde_utils::quoted_u64")]
#[superstruct(getter(copy))]
pub block_number: u64,
#[serde(with = "eth2_serde_utils::quoted_u64")]
#[superstruct(getter(copy))]
pub gas_limit: u64,
#[serde(with = "eth2_serde_utils::quoted_u64")]
#[superstruct(getter(copy))]
pub gas_used: u64,
#[serde(with = "eth2_serde_utils::quoted_u64")]
#[superstruct(getter(copy))]
pub timestamp: u64,
#[serde(with = "ssz_types::serde_utils::hex_var_list")]
pub extra_data: VariableList<u8, T::MaxExtraDataBytes>,
#[serde(with = "eth2_serde_utils::quoted_u256")]
#[superstruct(getter(copy))]
pub base_fee_per_gas: Uint256,
#[superstruct(only(Eip4844))]
#[serde(with = "eth2_serde_utils::quoted_u64")]
#[superstruct(getter(copy))]
pub excess_blobs: u64,
#[superstruct(getter(copy))]
pub block_hash: ExecutionBlockHash,
#[superstruct(getter(copy))]
pub transactions_root: Hash256,
#[superstruct(only(Capella, Eip4844))]
#[superstruct(getter(copy))]
pub withdrawals_root: Hash256,
}

View File

@@ -47,6 +47,13 @@ impl ForkContext {
));
}
if spec.capella_fork_epoch.is_some() {
fork_to_digest.push((
ForkName::Capella,
ChainSpec::compute_fork_digest(spec.capella_fork_version, genesis_validators_root),
));
}
if spec.eip4844_fork_epoch.is_some() {
fork_to_digest.push((
ForkName::Eip4844,

View File

@@ -1,5 +1,4 @@
//! Ethereum 2.0 types
#![feature(generic_associated_types)]
// Required for big type-level numbers
#![recursion_limit = "128"]
// Clippy lint set up
@@ -153,7 +152,7 @@ pub use crate::participation_list::ParticipationList;
pub use crate::payload::{
AbstractExecPayload, BlindedPayload, BlindedPayloadCapella, BlindedPayloadEip4844,
BlindedPayloadMerge, BlindedPayloadRef, BlockType, ExecPayload, FullPayload,
FullPayloadCapella, FullPayloadEip4844, FullPayloadMerge, FullPayloadRef,
FullPayloadCapella, FullPayloadEip4844, FullPayloadMerge, FullPayloadRef, OwnedExecPayload,
};
pub use crate::pending_attestation::PendingAttestation;
pub use crate::preset::{AltairPreset, BasePreset, BellatrixPreset};
@@ -164,8 +163,9 @@ pub use crate::selection_proof::SelectionProof;
pub use crate::shuffling_id::AttestationShufflingId;
pub use crate::signed_aggregate_and_proof::SignedAggregateAndProof;
pub use crate::signed_beacon_block::{
SignedBeaconBlock, SignedBeaconBlockAltair, SignedBeaconBlockBase, SignedBeaconBlockEip4844,
SignedBeaconBlockHash, SignedBeaconBlockMerge, SignedBlindedBeaconBlock,
SignedBeaconBlock, SignedBeaconBlockAltair, SignedBeaconBlockBase, SignedBeaconBlockCapella,
SignedBeaconBlockEip4844, SignedBeaconBlockHash, SignedBeaconBlockMerge,
SignedBlindedBeaconBlock,
};
pub use crate::signed_beacon_block_header::SignedBeaconBlockHeader;
pub use crate::signed_blobs_sidecar::SignedBlobsSidecar;

View File

@@ -57,7 +57,13 @@ impl<T: EthSpec, P> OwnedExecPayload<T> for P where
}
pub trait AbstractExecPayload<T: EthSpec>:
ExecPayload<T> + Sized + From<ExecutionPayload<T>> + TryFrom<ExecutionPayloadHeader<T>>
ExecPayload<T>
+ Sized
+ From<ExecutionPayload<T>>
+ TryFrom<ExecutionPayloadHeader<T>>
+ TryInto<Self::Merge>
+ TryInto<Self::Capella>
+ TryInto<Self::Eip4844>
{
type Ref<'a>: ExecPayload<T>
+ Copy
@@ -77,6 +83,8 @@ pub trait AbstractExecPayload<T: EthSpec>:
+ Into<Self>
+ From<ExecutionPayloadEip4844<T>>
+ TryFrom<ExecutionPayloadHeaderEip4844<T>>;
fn default_at_fork(fork_name: ForkName) -> Self;
}
#[superstruct(
@@ -128,6 +136,22 @@ impl<T: EthSpec> From<FullPayload<T>> for ExecutionPayload<T> {
}
}
impl<'a, T: EthSpec> From<FullPayloadRef<'a, T>> for ExecutionPayload<T> {
fn from(full_payload: FullPayloadRef<'a, T>) -> Self {
match full_payload {
FullPayloadRef::Merge(payload) => {
ExecutionPayload::Merge(payload.execution_payload.clone())
}
FullPayloadRef::Capella(payload) => {
ExecutionPayload::Capella(payload.execution_payload.clone())
}
FullPayloadRef::Eip4844(payload) => {
ExecutionPayload::Eip4844(payload.execution_payload.clone())
}
}
}
}
impl<T: EthSpec> ExecPayload<T> for FullPayloadMerge<T> {
fn block_type() -> BlockType {
BlockType::Full
@@ -425,6 +449,51 @@ impl<T: EthSpec> AbstractExecPayload<T> for FullPayload<T> {
type Merge = FullPayloadMerge<T>;
type Capella = FullPayloadCapella<T>;
type Eip4844 = FullPayloadEip4844<T>;
fn default_at_fork(fork_name: ForkName) -> Self {
match fork_name {
//FIXME(sean) error handling
ForkName::Base | ForkName::Altair => panic!(),
ForkName::Merge => FullPayloadMerge::default().into(),
ForkName::Capella => FullPayloadCapella::default().into(),
ForkName::Eip4844 => FullPayloadEip4844::default().into(),
}
}
}
//FIXME(sean) fix errors
impl<T: EthSpec> TryInto<FullPayloadMerge<T>> for FullPayload<T> {
type Error = ();
fn try_into(self) -> Result<FullPayloadMerge<T>, Self::Error> {
match self {
FullPayload::Merge(payload) => Ok(payload),
FullPayload::Capella(_) => Err(()),
FullPayload::Eip4844(_) => Err(()),
}
}
}
impl<T: EthSpec> TryInto<FullPayloadCapella<T>> for FullPayload<T> {
type Error = ();
fn try_into(self) -> Result<FullPayloadCapella<T>, Self::Error> {
match self {
FullPayload::Merge(_) => Err(()),
FullPayload::Capella(payload) => Ok(payload),
FullPayload::Eip4844(_) => Err(()),
}
}
}
impl<T: EthSpec> TryInto<FullPayloadEip4844<T>> for FullPayload<T> {
type Error = ();
fn try_into(self) -> Result<FullPayloadEip4844<T>, Self::Error> {
match self {
FullPayload::Merge(_) => Err(()),
FullPayload::Capella(_) => Err(()),
FullPayload::Eip4844(payload) => Ok(payload),
}
}
}
impl<T: EthSpec> From<ExecutionPayload<T>> for FullPayload<T> {
@@ -855,6 +924,51 @@ impl<T: EthSpec> AbstractExecPayload<T> for BlindedPayload<T> {
type Merge = BlindedPayloadMerge<T>;
type Capella = BlindedPayloadCapella<T>;
type Eip4844 = BlindedPayloadEip4844<T>;
fn default_at_fork(fork_name: ForkName) -> Self {
match fork_name {
//FIXME(sean) error handling
ForkName::Base | ForkName::Altair => panic!(),
ForkName::Merge => BlindedPayloadMerge::default().into(),
ForkName::Capella => BlindedPayloadCapella::default().into(),
ForkName::Eip4844 => BlindedPayloadEip4844::default().into(),
}
}
}
//FIXME(sean) fix errors
impl<T: EthSpec> TryInto<BlindedPayloadMerge<T>> for BlindedPayload<T> {
type Error = ();
fn try_into(self) -> Result<BlindedPayloadMerge<T>, Self::Error> {
match self {
BlindedPayload::Merge(payload) => Ok(payload),
BlindedPayload::Capella(_) => Err(()),
BlindedPayload::Eip4844(_) => Err(()),
}
}
}
impl<T: EthSpec> TryInto<BlindedPayloadCapella<T>> for BlindedPayload<T> {
type Error = ();
fn try_into(self) -> Result<BlindedPayloadCapella<T>, Self::Error> {
match self {
BlindedPayload::Merge(_) => Err(()),
BlindedPayload::Capella(payload) => Ok(payload),
BlindedPayload::Eip4844(_) => Err(()),
}
}
}
impl<T: EthSpec> TryInto<BlindedPayloadEip4844<T>> for BlindedPayload<T> {
type Error = ();
fn try_into(self) -> Result<BlindedPayloadEip4844<T>, Self::Error> {
match self {
BlindedPayload::Merge(_) => Err(()),
BlindedPayload::Capella(_) => Err(()),
BlindedPayload::Eip4844(payload) => Ok(payload),
}
}
}
impl<T: EthSpec> Default for FullPayloadMerge<T> {