mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-20 22:38:34 +00:00
When a block comes in whose parent is unkown, queue the block for processing and lookup the parent envelope
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
use crate::task_spawner::{Priority, TaskSpawner};
|
||||
use crate::utils::{ChainFilter, EthV1Filter, NetworkTxFilter, ResponseFilter, TaskSpawnerFilter};
|
||||
use beacon_chain::{BeaconChain, BeaconChainTypes};
|
||||
use beacon_chain::payload_envelope_verification::gossip_verified_envelope::GossipVerifiedEnvelope;
|
||||
use beacon_chain::{
|
||||
BeaconChain, BeaconChainTypes, NotifyExecutionLayer,
|
||||
payload_envelope_verification::EnvelopeError,
|
||||
};
|
||||
use bytes::Bytes;
|
||||
use eth2::{CONTENT_TYPE_HEADER, SSZ_CONTENT_TYPE_HEADER};
|
||||
use lighthouse_network::PubsubMessage;
|
||||
@@ -9,8 +13,11 @@ use ssz::Decode;
|
||||
use std::sync::Arc;
|
||||
use tokio::sync::mpsc::UnboundedSender;
|
||||
use tracing::{info, warn};
|
||||
use types::SignedExecutionPayloadEnvelope;
|
||||
use warp::{Filter, Rejection, Reply, reply::Response};
|
||||
use types::{BlockImportSource, SignedExecutionPayloadEnvelope};
|
||||
use warp::{
|
||||
Filter, Rejection, Reply,
|
||||
hyper::{Body, Response},
|
||||
};
|
||||
|
||||
// POST beacon/execution_payload_envelope (SSZ)
|
||||
pub(crate) fn post_beacon_execution_payload_envelope_ssz<T: BeaconChainTypes>(
|
||||
@@ -77,40 +84,71 @@ pub(crate) fn post_beacon_execution_payload_envelope<T: BeaconChainTypes>(
|
||||
.boxed()
|
||||
}
|
||||
/// Publishes a signed execution payload envelope to the network.
|
||||
/// TODO(gloas): Add gossip verification (BroadcastValidation::Gossip) before import.
|
||||
pub async fn publish_execution_payload_envelope<T: BeaconChainTypes>(
|
||||
envelope: SignedExecutionPayloadEnvelope<T::EthSpec>,
|
||||
chain: Arc<BeaconChain<T>>,
|
||||
network_tx: &UnboundedSender<NetworkMessage<T::EthSpec>>,
|
||||
) -> Result<Response, Rejection> {
|
||||
) -> Result<Response<Body>, Rejection> {
|
||||
let slot = envelope.message.slot;
|
||||
let beacon_block_root = envelope.message.beacon_block_root;
|
||||
let builder_index = envelope.message.builder_index;
|
||||
|
||||
// TODO(gloas): Replace this check once we have gossip validation.
|
||||
if !chain.spec.is_gloas_scheduled() {
|
||||
return Err(warp_utils::reject::custom_bad_request(
|
||||
"Execution payload envelopes are not supported before the Gloas fork".into(),
|
||||
));
|
||||
}
|
||||
|
||||
// TODO(gloas): We should probably add validation here i.e. BroadcastValidation::Gossip
|
||||
info!(
|
||||
%slot,
|
||||
%beacon_block_root,
|
||||
builder_index = envelope.message.builder_index,
|
||||
"Publishing signed execution payload envelope to network"
|
||||
);
|
||||
let signed_envelope = Arc::new(envelope);
|
||||
|
||||
// Publish to the network
|
||||
crate::utils::publish_pubsub_message(
|
||||
network_tx,
|
||||
PubsubMessage::ExecutionPayload(Box::new(envelope)),
|
||||
)
|
||||
.map_err(|_| {
|
||||
warn!(%slot, "Failed to publish execution payload envelope to network");
|
||||
warp_utils::reject::custom_server_error(
|
||||
"Unable to publish execution payload envelope to network".into(),
|
||||
// The publish_fn is called inside process_execution_payload_envelope after consensus
|
||||
// verification but before the EL call.
|
||||
let envelope_for_publish = signed_envelope.clone();
|
||||
let sender = network_tx.clone();
|
||||
let publish_fn = move || {
|
||||
info!(
|
||||
%slot,
|
||||
%beacon_block_root,
|
||||
builder_index,
|
||||
"Publishing signed execution payload envelope to network"
|
||||
);
|
||||
crate::utils::publish_pubsub_message(
|
||||
&sender,
|
||||
PubsubMessage::ExecutionPayload(Box::new((*envelope_for_publish).clone())),
|
||||
)
|
||||
})?;
|
||||
.map_err(|_| {
|
||||
warn!(%slot, "Failed to publish execution payload envelope to network");
|
||||
EnvelopeError::InternalError(
|
||||
"Unable to publish execution payload envelope to network".to_owned(),
|
||||
)
|
||||
})
|
||||
};
|
||||
|
||||
let ctx = chain.gossip_verification_context();
|
||||
let Ok(gossip_verifed_envelope) = GossipVerifiedEnvelope::new(signed_envelope, &ctx) else {
|
||||
warn!(%slot, %beacon_block_root, "Execution payload envelope rejected");
|
||||
return Err(warp_utils::reject::custom_bad_request(
|
||||
"execution payload envelope rejected, gossip verification".to_string(),
|
||||
));
|
||||
};
|
||||
|
||||
// Import the envelope locally (runs state transition and notifies the EL).
|
||||
chain
|
||||
.process_execution_payload_envelope(
|
||||
beacon_block_root,
|
||||
gossip_verifed_envelope,
|
||||
NotifyExecutionLayer::Yes,
|
||||
BlockImportSource::HttpApi,
|
||||
publish_fn,
|
||||
)
|
||||
.await
|
||||
.map_err(|e| {
|
||||
warn!(%slot, %beacon_block_root, reason = ?e, "Execution payload envelope rejected");
|
||||
warp_utils::reject::custom_bad_request(format!(
|
||||
"execution payload envelope rejected: {e:?}"
|
||||
))
|
||||
})?;
|
||||
|
||||
Ok(warp::reply().into_response())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user