mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-07 00:42:42 +00:00
hacky fix
This commit is contained in:
@@ -5,7 +5,10 @@ use crate::version::{
|
|||||||
ResponseIncludesVersion, add_consensus_version_header, add_ssz_content_type_header,
|
ResponseIncludesVersion, add_consensus_version_header, add_ssz_content_type_header,
|
||||||
execution_optimistic_finalized_beacon_response,
|
execution_optimistic_finalized_beacon_response,
|
||||||
};
|
};
|
||||||
use beacon_chain::{BeaconChain, BeaconChainTypes};
|
use beacon_chain::{
|
||||||
|
BeaconChain, BeaconChainTypes, NotifyExecutionLayer,
|
||||||
|
payload_envelope_verification::EnvelopeError,
|
||||||
|
};
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
use eth2::types as api_types;
|
use eth2::types as api_types;
|
||||||
use eth2::{CONTENT_TYPE_HEADER, SSZ_CONTENT_TYPE_HEADER};
|
use eth2::{CONTENT_TYPE_HEADER, SSZ_CONTENT_TYPE_HEADER};
|
||||||
@@ -15,7 +18,7 @@ use ssz::{Decode, Encode};
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use tokio::sync::mpsc::UnboundedSender;
|
use tokio::sync::mpsc::UnboundedSender;
|
||||||
use tracing::{info, warn};
|
use tracing::{info, warn};
|
||||||
use types::SignedExecutionPayloadEnvelope;
|
use types::{BlockImportSource, SignedExecutionPayloadEnvelope};
|
||||||
use warp::{Filter, Rejection, Reply, reply::Response};
|
use warp::{Filter, Rejection, Reply, reply::Response};
|
||||||
|
|
||||||
// POST beacon/execution_payload_envelope (SSZ)
|
// POST beacon/execution_payload_envelope (SSZ)
|
||||||
@@ -82,7 +85,9 @@ pub(crate) fn post_beacon_execution_payload_envelope<T: BeaconChainTypes>(
|
|||||||
)
|
)
|
||||||
.boxed()
|
.boxed()
|
||||||
}
|
}
|
||||||
/// Publishes a signed execution payload envelope to the network.
|
/// Locally imports and 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>(
|
pub async fn publish_execution_payload_envelope<T: BeaconChainTypes>(
|
||||||
envelope: SignedExecutionPayloadEnvelope<T::EthSpec>,
|
envelope: SignedExecutionPayloadEnvelope<T::EthSpec>,
|
||||||
chain: Arc<BeaconChain<T>>,
|
chain: Arc<BeaconChain<T>>,
|
||||||
@@ -90,33 +95,55 @@ pub async fn publish_execution_payload_envelope<T: BeaconChainTypes>(
|
|||||||
) -> Result<Response, Rejection> {
|
) -> Result<Response, Rejection> {
|
||||||
let slot = envelope.message.slot;
|
let slot = envelope.message.slot;
|
||||||
let beacon_block_root = envelope.message.beacon_block_root;
|
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() {
|
if !chain.spec.is_gloas_scheduled() {
|
||||||
return Err(warp_utils::reject::custom_bad_request(
|
return Err(warp_utils::reject::custom_bad_request(
|
||||||
"Execution payload envelopes are not supported before the Gloas fork".into(),
|
"Execution payload envelopes are not supported before the Gloas fork".into(),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(gloas): We should probably add validation here i.e. BroadcastValidation::Gossip
|
let signed_envelope = Arc::new(envelope);
|
||||||
info!(
|
|
||||||
%slot,
|
|
||||||
%beacon_block_root,
|
|
||||||
builder_index = envelope.message.builder_index,
|
|
||||||
"Publishing signed execution payload envelope to network"
|
|
||||||
);
|
|
||||||
|
|
||||||
// Publish to the network
|
// The publish_fn is called inside process_execution_payload_envelope after consensus
|
||||||
crate::utils::publish_pubsub_message(
|
// verification but before the EL call.
|
||||||
network_tx,
|
let envelope_for_publish = signed_envelope.clone();
|
||||||
PubsubMessage::ExecutionPayload(Box::new(envelope)),
|
let sender = network_tx.clone();
|
||||||
)
|
let publish_fn = move || {
|
||||||
.map_err(|_| {
|
info!(
|
||||||
warn!(%slot, "Failed to publish execution payload envelope to network");
|
%slot,
|
||||||
warp_utils::reject::custom_server_error(
|
%beacon_block_root,
|
||||||
"Unable to publish execution payload envelope to network".into(),
|
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(),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
};
|
||||||
|
|
||||||
|
// Import the envelope locally (runs state transition and notifies the EL).
|
||||||
|
chain
|
||||||
|
.process_execution_payload_envelope(
|
||||||
|
beacon_block_root,
|
||||||
|
signed_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())
|
Ok(warp::reply().into_response())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ use std::fmt::Debug;
|
|||||||
use std::future::Future;
|
use std::future::Future;
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
use std::thread::sleep;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use task_executor::TaskExecutor;
|
use task_executor::TaskExecutor;
|
||||||
use tokio::sync::mpsc;
|
use tokio::sync::mpsc;
|
||||||
@@ -621,6 +622,8 @@ impl<S: ValidatorStore + 'static, T: SlotClock + 'static> BlockService<S, T> {
|
|||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
sleep(Duration::from_secs(4));
|
||||||
|
|
||||||
// TODO(gloas) we only need to fetch, sign and publish the envelope in the local building case.
|
// TODO(gloas) we only need to fetch, sign and publish the envelope in the local building case.
|
||||||
// Right now we always default to local building. Once we implement trustless/trusted builder logic
|
// Right now we always default to local building. Once we implement trustless/trusted builder logic
|
||||||
// we should check the bid for index == BUILDER_INDEX_SELF_BUILD
|
// we should check the bid for index == BUILDER_INDEX_SELF_BUILD
|
||||||
|
|||||||
Reference in New Issue
Block a user