Revert "remove into gossip verified block"

This reverts commit 246d52d209.
This commit is contained in:
realbigsean 2023-07-10 10:17:31 -04:00
parent c4da1ba450
commit 6fd2ef49e4
No known key found for this signature in database
GPG Key ID: BE1B3DB104F6C788
3 changed files with 55 additions and 20 deletions

View File

@ -796,6 +796,40 @@ pub struct BlockImportData<E: EthSpec> {
pub consensus_context: ConsensusContext<E>,
}
pub trait IntoGossipVerifiedBlock<T: BeaconChainTypes>: Sized {
fn into_gossip_verified_block(
self,
chain: &BeaconChain<T>,
) -> Result<GossipVerifiedBlock<T>, BlockError<T::EthSpec>>;
fn inner(&self) -> Arc<SignedBeaconBlock<T::EthSpec>>;
}
impl<T: BeaconChainTypes> IntoGossipVerifiedBlock<T> for GossipVerifiedBlock<T> {
fn into_gossip_verified_block(
self,
_chain: &BeaconChain<T>,
) -> Result<GossipVerifiedBlock<T>, BlockError<T::EthSpec>> {
Ok(self)
}
fn inner(&self) -> Arc<SignedBeaconBlock<T::EthSpec>> {
self.block.clone()
}
}
impl<T: BeaconChainTypes> IntoGossipVerifiedBlock<T> for Arc<SignedBeaconBlock<T::EthSpec>> {
fn into_gossip_verified_block(
self,
chain: &BeaconChain<T>,
) -> Result<GossipVerifiedBlock<T>, BlockError<T::EthSpec>> {
GossipVerifiedBlock::new(self, chain)
}
fn inner(&self) -> Arc<SignedBeaconBlock<T::EthSpec>> {
self.clone()
}
}
/// Implemented on types that can be converted into a `ExecutionPendingBlock`.
///
/// Used to allow functions to accept blocks at various stages of verification.

View File

@ -71,7 +71,7 @@ pub use beacon_fork_choice_store::{BeaconForkChoiceStore, Error as ForkChoiceSto
pub use block_verification::{
get_block_root, AvailabilityPendingExecutedBlock, BlockError, ExecutedBlock,
ExecutionPayloadError, ExecutionPendingBlock, GossipVerifiedBlock, IntoExecutionPendingBlock,
PayloadVerificationOutcome, PayloadVerificationStatus,
PayloadVerificationOutcome, PayloadVerificationStatus,IntoGossipVerifiedBlock,
};
pub use canonical_head::{CachedHead, CanonicalHead, CanonicalHeadRwLock};
pub use eth1_chain::{Eth1Chain, Eth1ChainBackend};

View File

@ -3,7 +3,7 @@ use crate::metrics;
use beacon_chain::blob_verification::BlockWrapper;
use beacon_chain::validator_monitor::{get_block_delay_ms, timestamp_now};
use beacon_chain::{
AvailabilityProcessingStatus, BeaconChain, BeaconChainError, BeaconChainTypes, BlockError,
AvailabilityProcessingStatus, BeaconChain, BeaconChainError, BeaconChainTypes, BlockError,IntoGossipVerifiedBlock,
GossipVerifiedBlock, NotifyExecutionLayer,
};
use eth2::types::BroadcastValidation;
@ -13,6 +13,7 @@ use lighthouse_network::PubsubMessage;
use network::NetworkMessage;
use slog::{debug, error, info, warn, Logger};
use slot_clock::SlotClock;
use std::marker::PhantomData;
use std::sync::Arc;
use std::time::Duration;
use tokio::sync::mpsc::UnboundedSender;
@ -23,28 +24,28 @@ use types::{
};
use warp::Rejection;
pub enum ProvenancedBlock<T: EthSpec> {
pub enum ProvenancedBlock<T: BeaconChainTypes, B: IntoGossipVerifiedBlock<T>> {
/// The payload was built using a local EE.
Local(SignedBlockContents<T, FullPayload<T>>),
Local(B, PhantomData<T>),
/// The payload was build using a remote builder (e.g., via a mev-boost
/// compatible relay).
Builder(SignedBlockContents<T, FullPayload<T>>),
Builder(B, PhantomData<T>),
}
impl<T: EthSpec> ProvenancedBlock<T> {
pub fn local(block: SignedBlockContents<T>) -> Self {
Self::Local(block)
impl<T: BeaconChainTypes, B: IntoGossipVerifiedBlock<T>> ProvenancedBlock<T, B> {
pub fn local(block: B) -> Self {
Self::Local(block, PhantomData)
}
pub fn builder(block: SignedBlockContents<T>) -> Self {
Self::Builder(block)
pub fn builder(block: B) -> Self {
Self::Builder(block, PhantomData)
}
}
/// Handles a request from the HTTP API for full blocks.
pub async fn publish_block<T: BeaconChainTypes>(
pub async fn publish_block<T: BeaconChainTypes, B: IntoGossipVerifiedBlock<T>>(
block_root: Option<Hash256>,
provenanced_block: ProvenancedBlock<T::EthSpec>,
provenanced_block: ProvenancedBlock<T, B>,
chain: Arc<BeaconChain<T>>,
network_tx: &UnboundedSender<NetworkMessage<T::EthSpec>>,
log: Logger,
@ -53,11 +54,11 @@ pub async fn publish_block<T: BeaconChainTypes>(
let seen_timestamp = timestamp_now();
let (block, blobs_opt, is_locally_built_block) = match provenanced_block {
ProvenancedBlock::Local(block_contents) => {
let (block, maybe_blobs) = block_contents.deconstruct();
ProvenancedBlock::Local(block_contents, _) => {
let (block, maybe_blobs, ) = block_contents.deconstruct();
(Arc::new(block), maybe_blobs, true)
}
ProvenancedBlock::Builder(block_contents) => {
ProvenancedBlock::Builder(block_contents, _) => {
let (block, maybe_blobs) = block_contents.deconstruct();
(Arc::new(block), maybe_blobs, false)
}
@ -124,8 +125,8 @@ pub async fn publish_block<T: BeaconChainTypes>(
let log_clone = log.clone();
/* if we can form a `GossipVerifiedBlock`, we've passed our basic gossip checks */
let gossip_verified_block = GossipVerifiedBlock::new(
BlockWrapper::new(block.clone(), mapped_blobs),
let gossip_verified_block =
BlockWrapper::new(block.clone(), mapped_blobs).into_gossip_verified_block(
&chain,
)
.map_err(|e| {
@ -270,8 +271,8 @@ pub async fn publish_blinded_block<T: BeaconChainTypes>(
validation_level: BroadcastValidation,
) -> Result<(), Rejection> {
let block_root = block.signed_block().canonical_root();
let full_block = reconstruct_block(chain.clone(), block_root, block, log.clone()).await?;
publish_block::<T>(
let full_block: ProvenancedBlock<T, SignedBlockContents<T::EthSpec>> = reconstruct_block(chain.clone(), block_root, block, log.clone()).await?;
publish_block::<T, _>(
Some(block_root),
full_block,
chain,
@ -290,7 +291,7 @@ pub async fn reconstruct_block<T: BeaconChainTypes>(
block_root: Hash256,
block: SignedBlockContents<T::EthSpec, BlindedPayload<T::EthSpec>>,
log: Logger,
) -> Result<ProvenancedBlock<T::EthSpec>, Rejection> {
) -> Result<ProvenancedBlock<T::EthSpec, SignedBlockContents<T::EthSpec>>, Rejection> {
let full_payload_opt = if let Ok(payload_header) =
block.signed_block().message().body().execution_payload()
{