remove into gossip verified block
This commit is contained in:
parent
dfcb3363c7
commit
246d52d209
@ -632,40 +632,6 @@ pub struct ExecutionPendingBlock<T: BeaconChainTypes> {
|
|||||||
pub payload_verification_handle: PayloadVerificationHandle<T::EthSpec>,
|
pub payload_verification_handle: PayloadVerificationHandle<T::EthSpec>,
|
||||||
}
|
}
|
||||||
|
|
||||||
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`.
|
/// Implemented on types that can be converted into a `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.
|
||||||
|
@ -64,7 +64,7 @@ pub use attestation_verification::Error as AttestationError;
|
|||||||
pub use beacon_fork_choice_store::{BeaconForkChoiceStore, Error as ForkChoiceStoreError};
|
pub use beacon_fork_choice_store::{BeaconForkChoiceStore, Error as ForkChoiceStoreError};
|
||||||
pub use block_verification::{
|
pub use block_verification::{
|
||||||
get_block_root, BlockError, ExecutionPayloadError, GossipVerifiedBlock,
|
get_block_root, BlockError, ExecutionPayloadError, GossipVerifiedBlock,
|
||||||
IntoExecutionPendingBlock, IntoGossipVerifiedBlock,
|
IntoExecutionPendingBlock,
|
||||||
};
|
};
|
||||||
pub use canonical_head::{CachedHead, CanonicalHead, CanonicalHeadRwLock};
|
pub use canonical_head::{CachedHead, CanonicalHead, CanonicalHeadRwLock};
|
||||||
pub use eth1_chain::{Eth1Chain, Eth1ChainBackend};
|
pub use eth1_chain::{Eth1Chain, Eth1ChainBackend};
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use crate::metrics;
|
use crate::metrics;
|
||||||
use beacon_chain::validator_monitor::{get_block_delay_ms, timestamp_now};
|
use beacon_chain::validator_monitor::{get_block_delay_ms, timestamp_now};
|
||||||
use beacon_chain::{
|
use beacon_chain::{
|
||||||
BeaconChain, BeaconChainError, BeaconChainTypes, BlockError, IntoGossipVerifiedBlock,
|
BeaconChain, BeaconChainError, BeaconChainTypes, BlockError, GossipVerifiedBlock,
|
||||||
NotifyExecutionLayer,
|
NotifyExecutionLayer,
|
||||||
};
|
};
|
||||||
use eth2::types::BroadcastValidation;
|
use eth2::types::BroadcastValidation;
|
||||||
@ -10,7 +10,6 @@ use lighthouse_network::PubsubMessage;
|
|||||||
use network::NetworkMessage;
|
use network::NetworkMessage;
|
||||||
use slog::{debug, error, info, warn, Logger};
|
use slog::{debug, error, info, warn, Logger};
|
||||||
use slot_clock::SlotClock;
|
use slot_clock::SlotClock;
|
||||||
use std::marker::PhantomData;
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use tokio::sync::mpsc::UnboundedSender;
|
use tokio::sync::mpsc::UnboundedSender;
|
||||||
@ -21,28 +20,28 @@ use types::{
|
|||||||
};
|
};
|
||||||
use warp::Rejection;
|
use warp::Rejection;
|
||||||
|
|
||||||
pub enum ProvenancedBlock<T: BeaconChainTypes, B: IntoGossipVerifiedBlock<T>> {
|
pub enum ProvenancedBlock<T: BeaconChainTypes> {
|
||||||
/// The payload was built using a local EE.
|
/// The payload was built using a local EE.
|
||||||
Local(B, PhantomData<T>),
|
Local(Arc<SignedBeaconBlock<T::EthSpec>>),
|
||||||
/// The payload was build using a remote builder (e.g., via a mev-boost
|
/// The payload was build using a remote builder (e.g., via a mev-boost
|
||||||
/// compatible relay).
|
/// compatible relay).
|
||||||
Builder(B, PhantomData<T>),
|
Builder(Arc<SignedBeaconBlock<T::EthSpec>>),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: BeaconChainTypes, B: IntoGossipVerifiedBlock<T>> ProvenancedBlock<T, B> {
|
impl<T: BeaconChainTypes> ProvenancedBlock<T> {
|
||||||
pub fn local(block: B) -> Self {
|
pub fn local(block: Arc<SignedBeaconBlock<T::EthSpec>>) -> Self {
|
||||||
Self::Local(block, PhantomData)
|
Self::Local(block)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn builder(block: B) -> Self {
|
pub fn builder(block: Arc<SignedBeaconBlock<T::EthSpec>>) -> Self {
|
||||||
Self::Builder(block, PhantomData)
|
Self::Builder(block)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Handles a request from the HTTP API for full blocks.
|
/// Handles a request from the HTTP API for full blocks.
|
||||||
pub async fn publish_block<T: BeaconChainTypes, B: IntoGossipVerifiedBlock<T>>(
|
pub async fn publish_block<T: BeaconChainTypes>(
|
||||||
block_root: Option<Hash256>,
|
block_root: Option<Hash256>,
|
||||||
provenanced_block: ProvenancedBlock<T, B>,
|
provenanced_block: ProvenancedBlock<T>,
|
||||||
chain: Arc<BeaconChain<T>>,
|
chain: Arc<BeaconChain<T>>,
|
||||||
network_tx: &UnboundedSender<NetworkMessage<T::EthSpec>>,
|
network_tx: &UnboundedSender<NetworkMessage<T::EthSpec>>,
|
||||||
log: Logger,
|
log: Logger,
|
||||||
@ -50,10 +49,10 @@ pub async fn publish_block<T: BeaconChainTypes, B: IntoGossipVerifiedBlock<T>>(
|
|||||||
) -> Result<(), Rejection> {
|
) -> Result<(), Rejection> {
|
||||||
let seen_timestamp = timestamp_now();
|
let seen_timestamp = timestamp_now();
|
||||||
let (block, is_locally_built_block) = match provenanced_block {
|
let (block, is_locally_built_block) = match provenanced_block {
|
||||||
ProvenancedBlock::Local(block, _) => (block, true),
|
ProvenancedBlock::Local(block) => (block, true),
|
||||||
ProvenancedBlock::Builder(block, _) => (block, false),
|
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);
|
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());
|
debug!(log, "Signed block received in HTTP API"; "slot" => beacon_block.slot());
|
||||||
|
|
||||||
@ -75,7 +74,7 @@ pub async fn publish_block<T: BeaconChainTypes, B: IntoGossipVerifiedBlock<T>>(
|
|||||||
};
|
};
|
||||||
|
|
||||||
/* if we can form a `GossipVerifiedBlock`, we've passed our basic gossip checks */
|
/* 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);
|
warn!(log, "Not publishing block, not gossip verified"; "slot" => beacon_block.slot(), "error" => ?e);
|
||||||
warp_utils::reject::custom_bad_request(e.to_string())
|
warp_utils::reject::custom_bad_request(e.to_string())
|
||||||
})?;
|
})?;
|
||||||
@ -210,9 +209,9 @@ pub async fn publish_blinded_block<T: BeaconChainTypes>(
|
|||||||
validation_level: BroadcastValidation,
|
validation_level: BroadcastValidation,
|
||||||
) -> Result<(), Rejection> {
|
) -> Result<(), Rejection> {
|
||||||
let block_root = block.canonical_root();
|
let block_root = block.canonical_root();
|
||||||
let full_block: ProvenancedBlock<T, Arc<SignedBeaconBlock<T::EthSpec>>> =
|
let full_block: ProvenancedBlock<T> =
|
||||||
reconstruct_block(chain.clone(), block_root, block, log.clone()).await?;
|
reconstruct_block(chain.clone(), block_root, block, log.clone()).await?;
|
||||||
publish_block::<T, _>(
|
publish_block::<T>(
|
||||||
Some(block_root),
|
Some(block_root),
|
||||||
full_block,
|
full_block,
|
||||||
chain,
|
chain,
|
||||||
@ -231,7 +230,7 @@ pub async fn reconstruct_block<T: BeaconChainTypes>(
|
|||||||
block_root: Hash256,
|
block_root: Hash256,
|
||||||
block: SignedBeaconBlock<T::EthSpec, BlindedPayload<T::EthSpec>>,
|
block: SignedBeaconBlock<T::EthSpec, BlindedPayload<T::EthSpec>>,
|
||||||
log: Logger,
|
log: Logger,
|
||||||
) -> Result<ProvenancedBlock<T, Arc<SignedBeaconBlock<T::EthSpec>>>, Rejection> {
|
) -> Result<ProvenancedBlock<T>, Rejection> {
|
||||||
let full_payload_opt = if let Ok(payload_header) = block.message().body().execution_payload() {
|
let full_payload_opt = if let Ok(payload_header) = block.message().body().execution_payload() {
|
||||||
let el = chain.execution_layer.as_ref().ok_or_else(|| {
|
let el = chain.execution_layer.as_ref().ok_or_else(|| {
|
||||||
warp_utils::reject::custom_server_error("Missing execution layer".to_string())
|
warp_utils::reject::custom_server_error("Missing execution layer".to_string())
|
||||||
|
Loading…
Reference in New Issue
Block a user