From 246d52d209ef1ddf5659450e37b4462d1c0555d7 Mon Sep 17 00:00:00 2001 From: realbigsean Date: Thu, 6 Jul 2023 11:40:58 -0400 Subject: [PATCH] remove into gossip verified block --- .../beacon_chain/src/block_verification.rs | 34 ----------------- beacon_node/beacon_chain/src/lib.rs | 2 +- beacon_node/http_api/src/publish_blocks.rs | 37 +++++++++---------- 3 files changed, 19 insertions(+), 54 deletions(-) diff --git a/beacon_node/beacon_chain/src/block_verification.rs b/beacon_node/beacon_chain/src/block_verification.rs index 492f49252..206822de8 100644 --- a/beacon_node/beacon_chain/src/block_verification.rs +++ b/beacon_node/beacon_chain/src/block_verification.rs @@ -632,40 +632,6 @@ pub struct ExecutionPendingBlock { pub payload_verification_handle: PayloadVerificationHandle, } -pub trait IntoGossipVerifiedBlock: Sized { - fn into_gossip_verified_block( - self, - chain: &BeaconChain, - ) -> Result, BlockError>; - fn inner(&self) -> Arc>; -} - -impl IntoGossipVerifiedBlock for GossipVerifiedBlock { - fn into_gossip_verified_block( - self, - _chain: &BeaconChain, - ) -> Result, BlockError> { - Ok(self) - } - - fn inner(&self) -> Arc> { - self.block.clone() - } -} - -impl IntoGossipVerifiedBlock for Arc> { - fn into_gossip_verified_block( - self, - chain: &BeaconChain, - ) -> Result, BlockError> { - GossipVerifiedBlock::new(self, chain) - } - - fn inner(&self) -> Arc> { - self.clone() - } -} - /// Implemented on types that can be converted into a `ExecutionPendingBlock`. /// /// Used to allow functions to accept blocks at various stages of verification. diff --git a/beacon_node/beacon_chain/src/lib.rs b/beacon_node/beacon_chain/src/lib.rs index c5cf74e17..d672c1682 100644 --- a/beacon_node/beacon_chain/src/lib.rs +++ b/beacon_node/beacon_chain/src/lib.rs @@ -64,7 +64,7 @@ pub use attestation_verification::Error as AttestationError; pub use beacon_fork_choice_store::{BeaconForkChoiceStore, Error as ForkChoiceStoreError}; pub use block_verification::{ get_block_root, BlockError, ExecutionPayloadError, GossipVerifiedBlock, - IntoExecutionPendingBlock, IntoGossipVerifiedBlock, + IntoExecutionPendingBlock, }; pub use canonical_head::{CachedHead, CanonicalHead, CanonicalHeadRwLock}; pub use eth1_chain::{Eth1Chain, Eth1ChainBackend}; diff --git a/beacon_node/http_api/src/publish_blocks.rs b/beacon_node/http_api/src/publish_blocks.rs index 0f2f7b361..affca5f28 100644 --- a/beacon_node/http_api/src/publish_blocks.rs +++ b/beacon_node/http_api/src/publish_blocks.rs @@ -1,7 +1,7 @@ use crate::metrics; use beacon_chain::validator_monitor::{get_block_delay_ms, timestamp_now}; use beacon_chain::{ - BeaconChain, BeaconChainError, BeaconChainTypes, BlockError, IntoGossipVerifiedBlock, + BeaconChain, BeaconChainError, BeaconChainTypes, BlockError, GossipVerifiedBlock, NotifyExecutionLayer, }; use eth2::types::BroadcastValidation; @@ -10,7 +10,6 @@ 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; @@ -21,28 +20,28 @@ use types::{ }; use warp::Rejection; -pub enum ProvenancedBlock> { +pub enum ProvenancedBlock { /// The payload was built using a local EE. - Local(B, PhantomData), + Local(Arc>), /// The payload was build using a remote builder (e.g., via a mev-boost /// compatible relay). - Builder(B, PhantomData), + Builder(Arc>), } -impl> ProvenancedBlock { - pub fn local(block: B) -> Self { - Self::Local(block, PhantomData) +impl ProvenancedBlock { + pub fn local(block: Arc>) -> Self { + Self::Local(block) } - pub fn builder(block: B) -> Self { - Self::Builder(block, PhantomData) + pub fn builder(block: Arc>) -> Self { + Self::Builder(block) } } /// Handles a request from the HTTP API for full blocks. -pub async fn publish_block>( +pub async fn publish_block( block_root: Option, - provenanced_block: ProvenancedBlock, + provenanced_block: ProvenancedBlock, chain: Arc>, network_tx: &UnboundedSender>, log: Logger, @@ -50,10 +49,10 @@ pub async fn publish_block>( ) -> Result<(), Rejection> { let seen_timestamp = timestamp_now(); let (block, is_locally_built_block) = match provenanced_block { - ProvenancedBlock::Local(block, _) => (block, true), - ProvenancedBlock::Builder(block, _) => (block, false), + ProvenancedBlock::Local(block) => (block, true), + ProvenancedBlock::Builder(block) => (block, false), }; - let beacon_block = block.inner(); + let beacon_block = block.clone(); let delay = get_block_delay_ms(seen_timestamp, beacon_block.message(), &chain.slot_clock); debug!(log, "Signed block received in HTTP API"; "slot" => beacon_block.slot()); @@ -75,7 +74,7 @@ pub async fn publish_block>( }; /* if we can form a `GossipVerifiedBlock`, we've passed our basic gossip checks */ - let gossip_verified_block = block.into_gossip_verified_block(&chain).map_err(|e| { + let gossip_verified_block = GossipVerifiedBlock::new(block, &chain).map_err(|e| { warn!(log, "Not publishing block, not gossip verified"; "slot" => beacon_block.slot(), "error" => ?e); warp_utils::reject::custom_bad_request(e.to_string()) })?; @@ -210,9 +209,9 @@ pub async fn publish_blinded_block( validation_level: BroadcastValidation, ) -> Result<(), Rejection> { let block_root = block.canonical_root(); - let full_block: ProvenancedBlock>> = + let full_block: ProvenancedBlock = reconstruct_block(chain.clone(), block_root, block, log.clone()).await?; - publish_block::( + publish_block::( Some(block_root), full_block, chain, @@ -231,7 +230,7 @@ pub async fn reconstruct_block( block_root: Hash256, block: SignedBeaconBlock>, log: Logger, -) -> Result>>, Rejection> { +) -> Result, Rejection> { let full_payload_opt = if let Ok(payload_header) = block.message().body().execution_payload() { let el = chain.execution_layer.as_ref().ok_or_else(|| { warp_utils::reject::custom_server_error("Missing execution layer".to_string())