small fixes

This commit is contained in:
realbigsean
2023-02-20 09:15:58 -05:00
committed by Pawan Dhananjay
parent c332bc272c
commit 956ac7cbe9
3 changed files with 29 additions and 41 deletions

View File

@@ -2685,7 +2685,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
/// ///
/// Returns an `Err` if the given block was invalid, or an error was encountered during /// Returns an `Err` if the given block was invalid, or an error was encountered during
/// verification. /// verification.
pub async fn process_block<A: IntoAvailableBlock, B: IntoExecutionPendingBlock<T, A>>( pub async fn process_block<A: IntoAvailableBlock<T>, B: IntoExecutionPendingBlock<T, A>>(
self: &Arc<Self>, self: &Arc<Self>,
block_root: Hash256, block_root: Hash256,
unverified_block: B, unverified_block: B,
@@ -2764,7 +2764,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
/// ///
/// An error is returned if the block was unable to be imported. It may be partially imported /// An error is returned if the block was unable to be imported. It may be partially imported
/// (i.e., this function is not atomic). /// (i.e., this function is not atomic).
async fn import_execution_pending_block<B: IntoAvailableBlock>( async fn import_execution_pending_block<B: IntoAvailableBlock<T>>(
self: Arc<Self>, self: Arc<Self>,
execution_pending_block: ExecutionPendingBlock<T, B>, execution_pending_block: ExecutionPendingBlock<T, B>,
count_unrealized: CountUnrealized, count_unrealized: CountUnrealized,

View File

@@ -160,7 +160,6 @@ fn verify_data_availability<T: BeaconChainTypes>(
pub enum BlockWrapper<E: EthSpec> { pub enum BlockWrapper<E: EthSpec> {
Block(Arc<SignedBeaconBlock<E>>), Block(Arc<SignedBeaconBlock<E>>),
BlockAndBlobs(Arc<SignedBeaconBlock<E>>, Arc<BlobsSidecar<E>>), BlockAndBlobs(Arc<SignedBeaconBlock<E>>, Arc<BlobsSidecar<E>>),
BlockAndBlobsFuture(Arc<SignedBeaconBlock<E>>, DataAvailabilityHandle<E>),
} }
impl<E: EthSpec> BlockWrapper<E> { impl<E: EthSpec> BlockWrapper<E> {
@@ -263,8 +262,7 @@ pub trait IntoAvailableBlock<T: BeaconChainTypes> {
/// A wrapper over a [`SignedBeaconBlock`] or a [`SignedBeaconBlockAndBlobsSidecar`]. An /// A wrapper over a [`SignedBeaconBlock`] or a [`SignedBeaconBlockAndBlobsSidecar`]. An
/// `AvailableBlock` has passed any required data availability checks and should be used in /// `AvailableBlock` has passed any required data availability checks and should be used in
/// consensus. This newtype wraps `AvailableBlockInner` to ensure data availability checks /// consensus.
/// cannot be circumvented on construction.
#[derive(Clone, Debug, Derivative)] #[derive(Clone, Debug, Derivative)]
#[derivative(PartialEq, Hash(bound = "E: EthSpec"))] #[derivative(PartialEq, Hash(bound = "E: EthSpec"))]
pub struct AvailabilityPendingBlock<E: EthSpec> { pub struct AvailabilityPendingBlock<E: EthSpec> {
@@ -282,6 +280,26 @@ pub struct AvailableBlock<E: EthSpec> {
blobs: Blobs<E>, blobs: Blobs<E>,
} }
impl <E: EthSpec> AvailableBlock<E> {
pub fn blobs(&self) -> Option<Arc<BlobsSidecar<E>>> {
match &self.blobs {
Blobs::NotRequired | Blobs::None => None,
Blobs::Available(block_sidecar) => {
Some(block_sidecar.clone())
}
}
}
pub fn deconstruct(self) -> (Arc<SignedBeaconBlock<E>>, Option<Arc<BlobsSidecar<E>>>) {
match self.blobs {
Blobs::NotRequired | Blobs::None => (self.block, None),
Blobs::Available(blob_sidecars) => {
(self.block, Some(blob_sidecars))
}
}
}
}
pub enum Blobs<E: EthSpec> { pub enum Blobs<E: EthSpec> {
/// These blobs are available. /// These blobs are available.
Available(Arc<BlobsSidecar<E>>), Available(Arc<BlobsSidecar<E>>),
@@ -292,14 +310,6 @@ pub enum Blobs<E: EthSpec> {
None, None,
} }
/// A wrapper over a [`SignedBeaconBlock`] or a [`SignedBeaconBlockAndBlobsSidecar`].
#[derive(Clone, Debug, Derivative)]
#[derivative(PartialEq, Hash(bound = "E: EthSpec"))]
enum AvailableBlockInner<E: EthSpec> {
Block(Arc<SignedBeaconBlock<E>>),
BlockAndBlob(SignedBeaconBlockAndBlobsSidecar<E>),
}
impl<E: EthSpec> AvailabilityPendingBlock<E> { impl<E: EthSpec> AvailabilityPendingBlock<E> {
pub fn new( pub fn new(
beacon_block: Arc<SignedBeaconBlock<E>>, beacon_block: Arc<SignedBeaconBlock<E>>,
@@ -351,12 +361,11 @@ impl<E: EthSpec> AvailabilityPendingBlock<E> {
| SignedBeaconBlock::Merge(_) => Err(BlobError::InconsistentFork), | SignedBeaconBlock::Merge(_) => Err(BlobError::InconsistentFork),
SignedBeaconBlock::Eip4844(_) => { SignedBeaconBlock::Eip4844(_) => {
match da_check_required { match da_check_required {
DataAvailabilityCheckRequired::Yes => Ok(AvailableBlock( DataAvailabilityCheckRequired::Yes => Ok(AvailableBlock{
AvailableBlockInner::BlockAndBlob(SignedBeaconBlockAndBlobsSidecar { block: beacon_block,
beacon_block, blobs: Blobs::Available(blobs_sidecar),
blobs_sidecar, }
}), ),
)),
DataAvailabilityCheckRequired::No => { DataAvailabilityCheckRequired::No => {
// Blobs were not verified so we drop them, we'll instead just pass around // Blobs were not verified so we drop them, we'll instead just pass around
// an available `Eip4844` block without blobs. // an available `Eip4844` block without blobs.
@@ -367,27 +376,6 @@ impl<E: EthSpec> AvailabilityPendingBlock<E> {
} }
} }
pub fn blobs(&self) -> Option<Arc<BlobsSidecar<E>>> {
match &self.0 {
AvailableBlockInner::Block(_) => None,
AvailableBlockInner::BlockAndBlob(block_sidecar_pair) => {
Some(block_sidecar_pair.blobs_sidecar.clone())
}
}
}
pub fn deconstruct(self) -> (Arc<SignedBeaconBlock<E>>, Option<Arc<BlobsSidecar<E>>>) {
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<E: EthSpec>: AsBlock<E> { pub trait IntoBlockWrapper<E: EthSpec>: AsBlock<E> {

View File

@@ -684,7 +684,7 @@ pub struct ExecutionPendingBlock<
/// Used to allow functions to accept blocks at various stages of verification. /// Used to allow functions to accept blocks at various stages of verification.
pub trait IntoExecutionPendingBlock< pub trait IntoExecutionPendingBlock<
T: BeaconChainTypes, T: BeaconChainTypes,
B: IntoAvailableBlock = AvailableBlock<T::EthSpec>, B: IntoAvailableBlock<T> = AvailableBlock<T::EthSpec>,
>: Sized >: Sized
{ {
fn into_execution_pending_block( fn into_execution_pending_block(