diff --git a/beacon_node/beacon_chain/src/beacon_chain.rs b/beacon_node/beacon_chain/src/beacon_chain.rs index f1ac907f61..d677a08d1e 100644 --- a/beacon_node/beacon_chain/src/beacon_chain.rs +++ b/beacon_node/beacon_chain/src/beacon_chain.rs @@ -2685,7 +2685,7 @@ impl BeaconChain { /// /// Returns an `Err` if the given block was invalid, or an error was encountered during /// verification. - pub async fn process_block>( + pub async fn process_block, B: IntoExecutionPendingBlock>( self: &Arc, block_root: Hash256, unverified_block: B, @@ -2764,7 +2764,7 @@ impl BeaconChain { /// /// An error is returned if the block was unable to be imported. It may be partially imported /// (i.e., this function is not atomic). - async fn import_execution_pending_block( + async fn import_execution_pending_block>( self: Arc, execution_pending_block: ExecutionPendingBlock, count_unrealized: CountUnrealized, diff --git a/beacon_node/beacon_chain/src/blob_verification.rs b/beacon_node/beacon_chain/src/blob_verification.rs index 6a88a3312d..a5abad7453 100644 --- a/beacon_node/beacon_chain/src/blob_verification.rs +++ b/beacon_node/beacon_chain/src/blob_verification.rs @@ -160,7 +160,6 @@ fn verify_data_availability( pub enum BlockWrapper { Block(Arc>), BlockAndBlobs(Arc>, Arc>), - BlockAndBlobsFuture(Arc>, DataAvailabilityHandle), } impl BlockWrapper { @@ -263,8 +262,7 @@ pub trait IntoAvailableBlock { /// A wrapper over a [`SignedBeaconBlock`] or a [`SignedBeaconBlockAndBlobsSidecar`]. An /// `AvailableBlock` has passed any required data availability checks and should be used in -/// consensus. This newtype wraps `AvailableBlockInner` to ensure data availability checks -/// cannot be circumvented on construction. +/// consensus. #[derive(Clone, Debug, Derivative)] #[derivative(PartialEq, Hash(bound = "E: EthSpec"))] pub struct AvailabilityPendingBlock { @@ -282,6 +280,26 @@ pub struct AvailableBlock { blobs: Blobs, } +impl AvailableBlock { + pub fn blobs(&self) -> Option>> { + match &self.blobs { + Blobs::NotRequired | Blobs::None => None, + Blobs::Available(block_sidecar) => { + Some(block_sidecar.clone()) + } + } + } + + pub fn deconstruct(self) -> (Arc>, Option>>) { + match self.blobs { + Blobs::NotRequired | Blobs::None => (self.block, None), + Blobs::Available(blob_sidecars) => { + (self.block, Some(blob_sidecars)) + } + } + } +} + pub enum Blobs { /// These blobs are available. Available(Arc>), @@ -292,14 +310,6 @@ pub enum Blobs { None, } -/// A wrapper over a [`SignedBeaconBlock`] or a [`SignedBeaconBlockAndBlobsSidecar`]. -#[derive(Clone, Debug, Derivative)] -#[derivative(PartialEq, Hash(bound = "E: EthSpec"))] -enum AvailableBlockInner { - Block(Arc>), - BlockAndBlob(SignedBeaconBlockAndBlobsSidecar), -} - impl AvailabilityPendingBlock { pub fn new( beacon_block: Arc>, @@ -351,12 +361,11 @@ impl AvailabilityPendingBlock { | SignedBeaconBlock::Merge(_) => Err(BlobError::InconsistentFork), SignedBeaconBlock::Eip4844(_) => { match da_check_required { - DataAvailabilityCheckRequired::Yes => Ok(AvailableBlock( - AvailableBlockInner::BlockAndBlob(SignedBeaconBlockAndBlobsSidecar { - beacon_block, - blobs_sidecar, - }), - )), + DataAvailabilityCheckRequired::Yes => Ok(AvailableBlock{ + block: beacon_block, + blobs: Blobs::Available(blobs_sidecar), + } + ), DataAvailabilityCheckRequired::No => { // Blobs were not verified so we drop them, we'll instead just pass around // an available `Eip4844` block without blobs. @@ -367,27 +376,6 @@ impl AvailabilityPendingBlock { } } - pub fn blobs(&self) -> Option>> { - match &self.0 { - AvailableBlockInner::Block(_) => None, - AvailableBlockInner::BlockAndBlob(block_sidecar_pair) => { - Some(block_sidecar_pair.blobs_sidecar.clone()) - } - } - } - - pub fn deconstruct(self) -> (Arc>, Option>>) { - match self.0 { - AvailableBlockInner::Block(block) => (block, None), - AvailableBlockInner::BlockAndBlob(block_sidecar_pair) => { - let SignedBeaconBlockAndBlobsSidecar { - beacon_block, - blobs_sidecar, - } = block_sidecar_pair; - (beacon_block, Some(blobs_sidecar)) - } - } - } } pub trait IntoBlockWrapper: AsBlock { diff --git a/beacon_node/beacon_chain/src/block_verification.rs b/beacon_node/beacon_chain/src/block_verification.rs index a6bce27c1b..449177254f 100644 --- a/beacon_node/beacon_chain/src/block_verification.rs +++ b/beacon_node/beacon_chain/src/block_verification.rs @@ -684,7 +684,7 @@ pub struct ExecutionPendingBlock< /// Used to allow functions to accept blocks at various stages of verification. pub trait IntoExecutionPendingBlock< T: BeaconChainTypes, - B: IntoAvailableBlock = AvailableBlock, + B: IntoAvailableBlock = AvailableBlock, >: Sized { fn into_execution_pending_block(