mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-18 04:13:00 +00:00
add intoavailableblock trait
This commit is contained in:
committed by
Pawan Dhananjay
parent
110eaf92c4
commit
c332bc272c
@@ -7,7 +7,7 @@ use crate::attester_cache::{AttesterCache, AttesterCacheKey};
|
||||
use crate::beacon_proposer_cache::compute_proposer_duties_from_head;
|
||||
use crate::beacon_proposer_cache::BeaconProposerCache;
|
||||
use crate::blob_cache::BlobCache;
|
||||
use crate::blob_verification::{AsBlock, AvailabilityPendingBlock, BlockWrapper};
|
||||
use crate::blob_verification::{AsBlock, AvailabilityPendingBlock, AvailableBlock, BlockWrapper, IntoAvailableBlock};
|
||||
use crate::block_times_cache::BlockTimesCache;
|
||||
use crate::block_verification::{
|
||||
check_block_is_finalized_checkpoint_or_descendant, check_block_relevancy, get_block_root,
|
||||
@@ -2685,7 +2685,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
|
||||
///
|
||||
/// Returns an `Err` if the given block was invalid, or an error was encountered during
|
||||
/// verification.
|
||||
pub async fn process_block<B: IntoExecutionPendingBlock<T>>(
|
||||
pub async fn process_block<A: IntoAvailableBlock, B: IntoExecutionPendingBlock<T, A>>(
|
||||
self: &Arc<Self>,
|
||||
block_root: Hash256,
|
||||
unverified_block: B,
|
||||
@@ -2764,9 +2764,9 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
|
||||
///
|
||||
/// 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<B: IntoAvailableBlock>(
|
||||
self: Arc<Self>,
|
||||
execution_pending_block: ExecutionPendingBlock<T>,
|
||||
execution_pending_block: ExecutionPendingBlock<T, B>,
|
||||
count_unrealized: CountUnrealized,
|
||||
) -> Result<Hash256, BlockError<T::EthSpec>> {
|
||||
let ExecutionPendingBlock {
|
||||
@@ -2818,14 +2818,14 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
let available_block = block.into_available_block()?;
|
||||
|
||||
let chain = self.clone();
|
||||
let block_hash = self
|
||||
.spawn_blocking_handle(
|
||||
move || {
|
||||
chain.import_block(
|
||||
block,
|
||||
available_block,
|
||||
block_root,
|
||||
state,
|
||||
confirmed_state_roots,
|
||||
@@ -2851,7 +2851,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn import_block(
|
||||
&self,
|
||||
signed_block: AvailabilityPendingBlock<T::EthSpec>,
|
||||
signed_block: AvailableBlock<T::EthSpec>,
|
||||
block_root: Hash256,
|
||||
mut state: BeaconState<T::EthSpec>,
|
||||
confirmed_state_roots: Vec<Hash256>,
|
||||
|
||||
@@ -4,6 +4,7 @@ use std::sync::Arc;
|
||||
use tokio::task::JoinHandle;
|
||||
|
||||
use crate::beacon_chain::{BeaconChain, BeaconChainTypes, MAXIMUM_GOSSIP_CLOCK_DISPARITY};
|
||||
use crate::block_verification::PayloadVerificationOutcome;
|
||||
use crate::{kzg_utils, BeaconChainError, BlockError};
|
||||
use state_processing::per_block_processing::eip4844::eip4844::verify_kzg_commitments_against_transactions;
|
||||
use types::signed_beacon_block::BlobReconstructionError;
|
||||
@@ -13,7 +14,6 @@ use types::{
|
||||
Transactions,
|
||||
};
|
||||
use types::{Epoch, ExecPayload};
|
||||
use crate::block_verification::PayloadVerificationOutcome;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum BlobError {
|
||||
@@ -220,7 +220,9 @@ impl<T: BeaconChainTypes> BlockWrapper<T::EthSpec> {
|
||||
}
|
||||
});
|
||||
match self {
|
||||
BlockWrapper::Block(block) => AvailabilityPendingBlock::new(block, block_root, da_check_required),
|
||||
BlockWrapper::Block(block) => {
|
||||
AvailabilityPendingBlock::new(block, block_root, da_check_required)
|
||||
}
|
||||
BlockWrapper::BlockAndBlobs(block, blobs_sidecar) => {
|
||||
if matches!(da_check_required, DataAvailabilityCheckRequired::Yes) {
|
||||
let kzg_commitments = block
|
||||
@@ -251,15 +253,23 @@ impl<T: BeaconChainTypes> BlockWrapper<T::EthSpec> {
|
||||
}
|
||||
}
|
||||
|
||||
pub trait IntoAvailableBlock<T: BeaconChainTypes> {
|
||||
fn into_available_block(
|
||||
self,
|
||||
block_root: Hash256,
|
||||
chain: &BeaconChain<T>,
|
||||
) -> Result<AvailableBlock<T::EthSpec>, BlobError>;
|
||||
}
|
||||
|
||||
/// 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.
|
||||
#[derive(Clone, Debug, Derivative)]
|
||||
#[derivative(PartialEq, Hash(bound = "E: EthSpec"))]
|
||||
pub struct AvailabilityPendingBlock<E: EthSpec>{
|
||||
pub struct AvailabilityPendingBlock<E: EthSpec> {
|
||||
block: Arc<SignedBeaconBlock<E>>,
|
||||
data_availability_handle: DataAvailabilityHandle<E>
|
||||
data_availability_handle: DataAvailabilityHandle<E>,
|
||||
}
|
||||
|
||||
/// Used to await the result of data availability check.
|
||||
|
||||
@@ -24,9 +24,6 @@
|
||||
//! ▼
|
||||
//! SignedBeaconBlock
|
||||
//! |
|
||||
//! ▼
|
||||
//! AvailableBlock
|
||||
//! |
|
||||
//! |---------------
|
||||
//! | |
|
||||
//! | ▼
|
||||
@@ -52,8 +49,8 @@
|
||||
#![allow(clippy::result_large_err)]
|
||||
|
||||
use crate::blob_verification::{
|
||||
validate_blob_for_gossip, AsBlock, AvailabilityPendingBlock, BlobError, BlockWrapper, IntoAvailableBlock,
|
||||
IntoBlockWrapper,
|
||||
validate_blob_for_gossip, AsBlock, AvailabilityPendingBlock, AvailableBlock, BlobError,
|
||||
BlockWrapper, IntoAvailableBlock, IntoBlockWrapper,
|
||||
};
|
||||
use crate::eth1_finalization_cache::Eth1FinalizationData;
|
||||
use crate::execution_payload::{
|
||||
@@ -668,7 +665,10 @@ type PayloadVerificationHandle<E> =
|
||||
/// Note: a `ExecutionPendingBlock` is not _forever_ valid to be imported, it may later become invalid
|
||||
/// 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, B: IntoAvailablBlock> {
|
||||
pub struct ExecutionPendingBlock<
|
||||
T: BeaconChainTypes,
|
||||
B: IntoAvailablBlockk = AvailableBlock<T::EthSpec>,
|
||||
> {
|
||||
pub block: B,
|
||||
pub block_root: Hash256,
|
||||
pub state: BeaconState<T::EthSpec>,
|
||||
@@ -682,13 +682,17 @@ pub struct ExecutionPendingBlock<T: BeaconChainTypes, B: IntoAvailablBlock> {
|
||||
/// Implemented on types that can be converted into a `ExecutionPendingBlock`.
|
||||
///
|
||||
/// Used to allow functions to accept blocks at various stages of verification.
|
||||
pub trait IntoExecutionPendingBlock<T: BeaconChainTypes>: Sized {
|
||||
pub trait IntoExecutionPendingBlock<
|
||||
T: BeaconChainTypes,
|
||||
B: IntoAvailableBlock = AvailableBlock<T::EthSpec>,
|
||||
>: Sized
|
||||
{
|
||||
fn into_execution_pending_block(
|
||||
self,
|
||||
block_root: Hash256,
|
||||
chain: &Arc<BeaconChain<T>>,
|
||||
notify_execution_layer: NotifyExecutionLayer,
|
||||
) -> Result<ExecutionPendingBlock<T>, BlockError<T::EthSpec>> {
|
||||
) -> Result<ExecutionPendingBlock<T, B>, BlockError<T::EthSpec>> {
|
||||
self.into_execution_pending_block_slashable(block_root, chain, notify_execution_layer)
|
||||
.map(|execution_pending| {
|
||||
// Supply valid block to slasher.
|
||||
@@ -706,7 +710,7 @@ pub trait IntoExecutionPendingBlock<T: BeaconChainTypes>: Sized {
|
||||
block_root: Hash256,
|
||||
chain: &Arc<BeaconChain<T>>,
|
||||
notify_execution_layer: NotifyExecutionLayer,
|
||||
) -> Result<ExecutionPendingBlock<T>, BlockSlashInfo<BlockError<T::EthSpec>>>;
|
||||
) -> Result<ExecutionPendingBlock<T, B>, BlockSlashInfo<BlockError<T::EthSpec>>>;
|
||||
|
||||
fn block(&self) -> &SignedBeaconBlock<T::EthSpec>;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::blob_verification::AvailabilityPendingBlock;
|
||||
use crate::blob_verification::{AvailabilityPendingBlock, AvailableBlock};
|
||||
use crate::{
|
||||
attester_cache::{CommitteeLengths, Error},
|
||||
metrics,
|
||||
@@ -51,7 +51,7 @@ impl<E: EthSpec> EarlyAttesterCache<E> {
|
||||
pub fn add_head_block(
|
||||
&self,
|
||||
beacon_block_root: Hash256,
|
||||
block: AvailabilityPendingBlock<E>,
|
||||
block: AvailableBlock<E>,
|
||||
proto_block: ProtoBlock,
|
||||
state: &BeaconState<E>,
|
||||
spec: &ChainSpec,
|
||||
|
||||
Reference in New Issue
Block a user