Publish payload

This commit is contained in:
Eitan Seri- Levi
2026-02-03 20:28:28 -08:00
parent 1ed80fa35d
commit 25853847ef
9 changed files with 232 additions and 218 deletions

View File

@@ -23,6 +23,7 @@ mod produce_block;
mod proposer_duties;
mod publish_attestations;
mod publish_blocks;
mod publish_execution_payload_envelope;
mod standard_block_rewards;
mod state_id;
mod sync_committee_rewards;
@@ -71,7 +72,7 @@ pub use publish_blocks::{
};
use serde::{Deserialize, Serialize};
use slot_clock::SlotClock;
use ssz::Encode;
use ssz::{Decode, Encode};
pub use state_id::StateId;
use std::future::Future;
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
@@ -90,7 +91,7 @@ use tokio_stream::{
use tracing::{debug, info, warn};
use types::{
BeaconStateError, Checkpoint, ConfigAndPreset, Epoch, EthSpec, ForkName, Hash256,
SignedBlindedBeaconBlock, Slot,
SignedBlindedBeaconBlock, SignedExecutionPayloadEnvelope, Slot,
};
use version::{
ResponseIncludesVersion, V1, V2, add_consensus_version_header, add_ssz_content_type_header,
@@ -1486,6 +1487,60 @@ pub fn serve<T: BeaconChainTypes>(
let post_beacon_pool_bls_to_execution_changes =
post_beacon_pool_bls_to_execution_changes(&network_tx_filter, &beacon_pool_path);
// POST beacon/execution_payload_envelope
let post_beacon_execution_payload_envelope = eth_v1
.clone()
.and(warp::path("beacon"))
.and(warp::path("execution_payload_envelope"))
.and(warp::path::end())
.and(warp::body::json())
.and(task_spawner_filter.clone())
.and(chain_filter.clone())
.and(network_tx_filter.clone())
.then(
|envelope: SignedExecutionPayloadEnvelope<T::EthSpec>,
task_spawner: TaskSpawner<T::EthSpec>,
chain: Arc<BeaconChain<T>>,
network_tx: UnboundedSender<NetworkMessage<T::EthSpec>>| {
task_spawner.spawn_async_with_rejection(Priority::P0, async move {
publish_execution_payload_envelope::publish_execution_payload_envelope(
envelope, chain, &network_tx,
)
.await
})
},
);
// POST beacon/execution_payload_envelope (SSZ)
let post_beacon_execution_payload_envelope_ssz = eth_v1
.clone()
.and(warp::path("beacon"))
.and(warp::path("execution_payload_envelope"))
.and(warp::path::end())
.and(warp::header::exact(CONTENT_TYPE_HEADER, SSZ_CONTENT_TYPE_HEADER))
.and(warp::body::bytes())
.and(task_spawner_filter.clone())
.and(chain_filter.clone())
.and(network_tx_filter.clone())
.then(
|body_bytes: Bytes,
task_spawner: TaskSpawner<T::EthSpec>,
chain: Arc<BeaconChain<T>>,
network_tx: UnboundedSender<NetworkMessage<T::EthSpec>>| {
task_spawner.spawn_async_with_rejection(Priority::P0, async move {
let envelope =
SignedExecutionPayloadEnvelope::<T::EthSpec>::from_ssz_bytes(&body_bytes)
.map_err(|e| {
warp_utils::reject::custom_bad_request(format!("invalid SSZ: {e:?}"))
})?;
publish_execution_payload_envelope::publish_execution_payload_envelope(
envelope, chain, &network_tx,
)
.await
})
},
);
let beacon_rewards_path = eth_v1
.clone()
.and(warp::path("beacon"))
@@ -3374,7 +3429,8 @@ pub fn serve<T: BeaconChainTypes>(
post_beacon_blocks_ssz
.uor(post_beacon_blocks_v2_ssz)
.uor(post_beacon_blinded_blocks_ssz)
.uor(post_beacon_blinded_blocks_v2_ssz),
.uor(post_beacon_blinded_blocks_v2_ssz)
.uor(post_beacon_execution_payload_envelope_ssz),
)
.uor(post_beacon_blocks)
.uor(post_beacon_blinded_blocks)
@@ -3386,6 +3442,7 @@ pub fn serve<T: BeaconChainTypes>(
.uor(post_beacon_pool_voluntary_exits)
.uor(post_beacon_pool_sync_committees)
.uor(post_beacon_pool_bls_to_execution_changes)
.uor(post_beacon_execution_payload_envelope)
.uor(post_beacon_state_validators)
.uor(post_beacon_state_validator_balances)
.uor(post_beacon_state_validator_identities)

View File

@@ -0,0 +1,57 @@
use beacon_chain::{BeaconChain, BeaconChainTypes};
use lighthouse_network::PubsubMessage;
use network::NetworkMessage;
use std::sync::Arc;
use tokio::sync::mpsc::UnboundedSender;
use tracing::{info, warn};
use types::SignedExecutionPayloadEnvelope;
use warp::{Rejection, Reply, reply::Response};
/// Publishes a signed execution payload envelope to the network.
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> {
let slot = envelope.message.slot;
let beacon_block_root = envelope.message.beacon_block_root;
// Basic validation: check that the slot is reasonable
let current_slot = chain
.slot()
.map_err(|_| warp_utils::reject::custom_server_error("Unable to get current slot".into()))?;
// Don't accept envelopes too far in the future
if slot > current_slot + 1 {
return Err(warp_utils::reject::custom_bad_request(format!(
"Envelope slot {} is too far in the future (current slot: {})",
slot, current_slot
)));
}
// TODO(gloas): Add more validation:
// - Verify the signature
// - Check builder_index is valid
// - Verify the envelope references a known block
info!(
%slot,
%beacon_block_root,
builder_index = envelope.message.builder_index,
"Publishing signed execution payload envelope to network"
);
// 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(),
)
})?;
Ok(warp::reply().into_response())
}

View File

@@ -6,7 +6,7 @@ use crate::utils::{
AnyVersionFilter, ChainFilter, EthV1Filter, NetworkTxFilter, NotWhileSyncingFilter,
ResponseFilter, TaskSpawnerFilter, ValidatorSubscriptionTxFilter, publish_network_message,
};
use crate::version::{V3, V4};
use crate::version::V3;
use crate::{StateId, attester_duties, proposer_duties, sync_committees};
use beacon_chain::attestation_verification::VerifiedAttestation;
use beacon_chain::validator_monitor::timestamp_now;
@@ -336,6 +336,7 @@ pub fn get_validator_blocks<T: BeaconChainTypes>(
}
// GET validator/execution_payload_bid/
#[allow(dead_code)]
pub fn get_validator_execution_payload_bid<T: BeaconChainTypes>(
eth_v1: EthV1Filter,
chain_filter: ChainFilter<T>,
@@ -357,10 +358,10 @@ pub fn get_validator_execution_payload_bid<T: BeaconChainTypes>(
.and(chain_filter)
.then(
|slot: Slot,
accept_header: Option<Accept>,
_accept_header: Option<Accept>,
not_synced_filter: Result<(), Rejection>,
task_spawner: TaskSpawner<T::EthSpec>,
chain: Arc<BeaconChain<T>>| {
_chain: Arc<BeaconChain<T>>| {
task_spawner.spawn_async_with_rejection(Priority::P0, async move {
debug!(
?slot,

View File

@@ -14,7 +14,6 @@ use warp::reply::{self, Reply, Response};
pub const V1: EndpointVersion = EndpointVersion(1);
pub const V2: EndpointVersion = EndpointVersion(2);
pub const V3: EndpointVersion = EndpointVersion(3);
pub const V4: EndpointVersion = EndpointVersion(4);
#[derive(Debug, PartialEq, Clone, Serialize)]
pub enum ResponseIncludesVersion {