Skip to content

Commit

Permalink
Remove block types with both execute and availability properties
Browse files Browse the repository at this point in the history
  • Loading branch information
dapplion committed Mar 17, 2024
1 parent eab3672 commit 6365e38
Show file tree
Hide file tree
Showing 7 changed files with 156 additions and 122 deletions.
20 changes: 8 additions & 12 deletions beacon_node/beacon_chain/src/beacon_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ use crate::block_verification_types::{
pub use crate::canonical_head::CanonicalHead;
use crate::chain_config::ChainConfig;
use crate::data_availability_checker::{
Availability, AvailabilityCheckError, AvailableBlock, DataAvailabilityChecker,
Availability, AvailabilityCheckError, AvailableBlock, BlockAvailability,
DataAvailabilityChecker,
};
use crate::early_attester_cache::EarlyAttesterCache;
use crate::errors::{BeaconChainError as Error, BlockProductionError};
Expand Down Expand Up @@ -69,8 +70,7 @@ use crate::validator_monitor::{
};
use crate::validator_pubkey_cache::ValidatorPubkeyCache;
use crate::{
kzg_utils, metrics, AvailabilityPendingExecutedBlock, BeaconChainError, BeaconForkChoiceStore,
BeaconSnapshot, CachedHead,
kzg_utils, metrics, BeaconChainError, BeaconForkChoiceStore, BeaconSnapshot, CachedHead,
};
use eth2::types::{EventKind, SseBlobSidecar, SseBlock, SseExtendedPayloadAttributes, SyncDuty};
use execution_layer::{
Expand Down Expand Up @@ -3018,14 +3018,8 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
)?;
publish_fn()?;
let executed_block = chain.into_executed_block(execution_pending).await?;
match executed_block {
ExecutedBlock::Available(block) => {
self.import_available_block(Box::new(block)).await
}
ExecutedBlock::AvailabilityPending(block) => {
self.check_block_availability_and_import(block).await
}
}
self.check_block_availability_and_import(executed_block)
.await
};

// Verify and import the block.
Expand Down Expand Up @@ -3095,6 +3089,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
let ExecutionPendingBlock {
block,
import_data,
availability,
payload_verification_handle,
} = execution_pending_block;

Expand Down Expand Up @@ -3135,6 +3130,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
Ok(ExecutedBlock::new(
block,
import_data,
availability,
payload_verification_outcome,
))
}
Expand All @@ -3145,7 +3141,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
/// in the data availability checker.
async fn check_block_availability_and_import(
self: &Arc<Self>,
block: AvailabilityPendingExecutedBlock<T::EthSpec>,
block: ExecutedBlock<T::EthSpec>,
) -> Result<AvailabilityProcessingStatus, BlockError<T::EthSpec>> {
let slot = block.block.slot();
let availability = self
Expand Down
15 changes: 10 additions & 5 deletions beacon_node/beacon_chain/src/block_verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ use crate::blob_verification::{GossipBlobError, GossipVerifiedBlob};
use crate::block_verification_types::{
AsBlock, BlockContentsError, BlockImportData, GossipVerifiedBlockContents, RpcBlock,
};
use crate::data_availability_checker::{AvailabilityCheckError, MaybeAvailableBlock};
use crate::data_availability_checker::{
AvailabilityCheckError, BlockAvailability, MaybeAvailableBlock,
};
use crate::eth1_finalization_cache::Eth1FinalizationData;
use crate::execution_payload::{
is_optimistic_candidate_block, validate_execution_payload_for_gossip, validate_merge_block,
Expand Down Expand Up @@ -673,9 +675,10 @@ type PayloadVerificationHandle<E> =
/// due to finality or some other event. A `ExecutionPendingBlock` should be imported into the
/// `BeaconChain` immediately after it is instantiated.
pub struct ExecutionPendingBlock<T: BeaconChainTypes> {
pub block: MaybeAvailableBlock<T::EthSpec>,
pub block: Arc<SignedBeaconBlock<T::EthSpec>>,
pub import_data: BlockImportData<T::EthSpec>,
pub payload_verification_handle: PayloadVerificationHandle<T::EthSpec>,
pub availability: BlockAvailability<T::EthSpec>,
}

pub trait IntoGossipVerifiedBlockContents<T: BeaconChainTypes>: Sized {
Expand Down Expand Up @@ -1115,9 +1118,10 @@ impl<T: BeaconChainTypes> SignatureVerifiedBlock<T> {

if signature_verifier.verify().is_ok() {
Ok(Self {
block: MaybeAvailableBlock::AvailabilityPending {
block_root: from.block_root,
block: MaybeAvailableBlock {
block,
block_root: from.block_root,
availability: BlockAvailability::Pending,
},
block_root: from.block_root,
parent: Some(parent),
Expand Down Expand Up @@ -1645,7 +1649,7 @@ impl<T: BeaconChainTypes> ExecutionPendingBlock<T> {
drop(fork_choice);

Ok(Self {
block,
block: block.block_cloned(),
import_data: BlockImportData {
block_root,
state,
Expand All @@ -1655,6 +1659,7 @@ impl<T: BeaconChainTypes> ExecutionPendingBlock<T> {
consensus_context,
},
payload_verification_handle,
availability: block.availability,
})
}
}
Expand Down
85 changes: 36 additions & 49 deletions beacon_node/beacon_chain/src/block_verification_types.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use crate::blob_verification::{GossipBlobError, GossipVerifiedBlobList};
use crate::block_verification::BlockError;
use crate::data_availability_checker::AvailabilityCheckError;
pub use crate::data_availability_checker::{AvailableBlock, MaybeAvailableBlock};
use crate::data_availability_checker::{
AvailabilityCheckError, AvailableBlock, BlockAvailability, MaybeAvailableBlock,
};
use crate::eth1_finalization_cache::Eth1FinalizationData;
use crate::{get_block_root, GossipVerifiedBlock, PayloadVerificationOutcome};
use derivative::Derivative;
Expand Down Expand Up @@ -172,48 +173,34 @@ impl<E: EthSpec> RpcBlock<E> {
/// required blobs.
/// 2. `AvailabilityPending`: This block hasn't received all required blobs to consider it a
/// fully available block.
pub enum ExecutedBlock<E: EthSpec> {
Available(AvailableExecutedBlock<E>),
AvailabilityPending(AvailabilityPendingExecutedBlock<E>),
pub struct ExecutedBlock<E: EthSpec> {
pub block: Arc<SignedBeaconBlock<E>>,
pub import_data: BlockImportData<E>,
pub availability: BlockAvailability<E>,
pub payload_verification_outcome: PayloadVerificationOutcome,
}

impl<E: EthSpec> ExecutedBlock<E> {
pub fn new(
block: MaybeAvailableBlock<E>,
block: Arc<SignedBeaconBlock<E>>,
import_data: BlockImportData<E>,
availability: BlockAvailability<E>,
payload_verification_outcome: PayloadVerificationOutcome,
) -> Self {
match block {
MaybeAvailableBlock::Available(available_block) => {
Self::Available(AvailableExecutedBlock::new(
available_block,
import_data,
payload_verification_outcome,
))
}
MaybeAvailableBlock::AvailabilityPending {
block_root: _,
block: pending_block,
} => Self::AvailabilityPending(AvailabilityPendingExecutedBlock::new(
pending_block,
import_data,
payload_verification_outcome,
)),
Self {
block,
import_data,
payload_verification_outcome,
availability,
}
}

pub fn as_block(&self) -> &SignedBeaconBlock<E> {
match self {
Self::Available(available) => available.block.block(),
Self::AvailabilityPending(pending) => &pending.block,
}
&self.block
}

pub fn block_root(&self) -> Hash256 {
match self {
ExecutedBlock::AvailabilityPending(pending) => pending.import_data.block_root,
ExecutedBlock::Available(available) => available.import_data.block_root,
}
self.import_data.block_root
}
}

Expand Down Expand Up @@ -416,33 +403,33 @@ impl<E: EthSpec> AsBlock<E> for MaybeAvailableBlock<E> {
self.as_block().message()
}
fn as_block(&self) -> &SignedBeaconBlock<E> {
match &self {
MaybeAvailableBlock::Available(block) => block.as_block(),
MaybeAvailableBlock::AvailabilityPending {
block_root: _,
block,
} => block,
}
&self.block
}
fn block_cloned(&self) -> Arc<SignedBeaconBlock<E>> {
match &self {
MaybeAvailableBlock::Available(block) => block.block_cloned(),
MaybeAvailableBlock::AvailabilityPending {
block_root: _,
block,
} => block.clone(),
}
self.block.clone()
}
fn canonical_root(&self) -> Hash256 {
self.as_block().canonical_root()
}

fn into_rpc_block(self) -> RpcBlock<E> {
match self {
MaybeAvailableBlock::Available(available_block) => available_block.into_rpc_block(),
MaybeAvailableBlock::AvailabilityPending { block_root, block } => {
RpcBlock::new_without_blobs(Some(block_root), block)
}
let Self {
block,
block_root,
availability,
} = self;
// Circumvent the constructor here, because an Available block will have already had
// consistency checks performed.
let inner = match availability {
BlockAvailability::Available { blobs } => match blobs {
Some(blobs) => RpcBlockInner::BlockAndBlobs(block, blobs),
None => RpcBlockInner::Block(block),
},
BlockAvailability::Pending => RpcBlockInner::Block(block),
};
RpcBlock {
block_root,
block: inner,
}
}
}
Expand Down
Loading

0 comments on commit 6365e38

Please sign in to comment.