Add get payload envelope route

This commit is contained in:
Eitan Seri- Levi
2026-02-03 18:51:53 -08:00
parent 50dde1585c
commit 2d321f60eb
6 changed files with 364 additions and 49 deletions

View File

@@ -2469,6 +2469,14 @@ pub fn serve<T: BeaconChainTypes>(
task_spawner_filter.clone(),
);
// GET validator/execution_payload_envelope/{slot}/{builder_index}
let get_validator_execution_payload_envelope = get_validator_execution_payload_envelope(
eth_v1.clone().clone(),
chain_filter.clone(),
not_while_syncing_filter.clone(),
task_spawner_filter.clone(),
);
// GET validator/attestation_data?slot,committee_index
let get_validator_attestation_data = get_validator_attestation_data(
eth_v1.clone().clone(),
@@ -3327,6 +3335,7 @@ pub fn serve<T: BeaconChainTypes>(
.uor(get_validator_duties_proposer)
.uor(get_validator_blocks)
.uor(get_validator_blinded_blocks)
.uor(get_validator_execution_payload_envelope)
.uor(get_validator_attestation_data)
.uor(get_validator_aggregate_attestation)
.uor(get_validator_sync_committee_contribution)

View File

@@ -21,6 +21,7 @@ use eth2::types::{
use lighthouse_network::PubsubMessage;
use network::{NetworkMessage, ValidatorSubscriptionMessage};
use slot_clock::SlotClock;
use ssz::Encode;
use std::sync::Arc;
use tokio::sync::mpsc::{Sender, UnboundedSender};
use tokio::sync::oneshot;
@@ -30,6 +31,7 @@ use types::{
SignedContributionAndProof, SignedValidatorRegistrationData, Slot, SyncContributionData,
ValidatorSubscription,
};
use warp::http::Response;
use warp::{Filter, Rejection, Reply};
use warp_utils::reject::convert_rejection;
@@ -374,6 +376,99 @@ pub fn get_validator_execution_payload_bid<T: BeaconChainTypes>(
.boxed()
}
// GET validator/execution_payload_envelope/{slot}/{builder_index}
pub fn get_validator_execution_payload_envelope<T: BeaconChainTypes>(
eth_v1: EthV1Filter,
chain_filter: ChainFilter<T>,
not_while_syncing_filter: NotWhileSyncingFilter,
task_spawner_filter: TaskSpawnerFilter<T>,
) -> ResponseFilter {
eth_v1
.and(warp::path("validator"))
.and(warp::path("execution_payload_envelope"))
.and(warp::path::param::<Slot>().or_else(|_| async {
Err(warp_utils::reject::custom_bad_request(
"Invalid slot".to_string(),
))
}))
.and(warp::path::param::<u64>().or_else(|_| async {
Err(warp_utils::reject::custom_bad_request(
"Invalid builder_index".to_string(),
))
}))
.and(warp::path::end())
.and(warp::header::optional::<Accept>("accept"))
.and(not_while_syncing_filter)
.and(task_spawner_filter)
.and(chain_filter)
.then(
|slot: Slot,
// TODO(gloas) we're only doing local building
// we'll need to implement builder index logic
// eventually.
_builder_index: u64,
accept_header: Option<Accept>,
not_synced_filter: Result<(), Rejection>,
task_spawner: TaskSpawner<T::EthSpec>,
chain: Arc<BeaconChain<T>>| {
task_spawner.spawn_async_with_rejection(Priority::P0, async move {
debug!(?slot, "Execution payload envelope request from HTTP API");
not_synced_filter?;
// Get the envelope from the pending cache (local building only)
let envelope = chain
.pending_payload_envelopes
.read()
.get(slot)
.cloned()
.ok_or_else(|| {
warp_utils::reject::custom_not_found(format!(
"Execution payload envelope not available for slot {slot}"
))
})?;
let fork_name = chain.spec.fork_name_at_slot::<T::EthSpec>(slot);
match accept_header {
Some(Accept::Ssz) => Response::builder()
.status(200)
.header("Content-Type", "application/octet-stream")
.header("Eth-Consensus-Version", fork_name.to_string())
.body(envelope.as_ssz_bytes().into())
.map_err(|e| {
warp_utils::reject::custom_server_error(format!(
"Failed to build SSZ response: {e}"
))
}),
_ => {
let json_response = GenericResponse { data: envelope };
Response::builder()
.status(200)
.header("Content-Type", "application/json")
.header("Eth-Consensus-Version", fork_name.to_string())
.body(
serde_json::to_string(&json_response)
.map_err(|e| {
warp_utils::reject::custom_server_error(format!(
"Failed to serialize response: {e}"
))
})?
.into(),
)
.map_err(|e| {
warp_utils::reject::custom_server_error(format!(
"Failed to build JSON response: {e}"
))
})
}
}
})
},
)
.boxed()
}
// POST validator/liveness/{epoch}
pub fn post_validator_liveness_epoch<T: BeaconChainTypes>(
eth_v1: EthV1Filter,

View File

@@ -3800,13 +3800,13 @@ impl ApiTester {
assert!(!metadata.consensus_block_value.is_zero());
// Verify that the execution payload envelope is cached for local building.
// The envelope is stored in the pending cache until publishing.
// The envelope is stored in the pending cache (keyed by slot) until publishing.
let block_root = block.tree_hash_root();
let envelope = self
.chain
.pending_payload_envelopes
.read()
.get(&block_root)
.get(slot)
.cloned()
.expect("envelope should exist in pending cache for local building");
assert_eq!(envelope.beacon_block_root, block_root);
@@ -3910,6 +3910,159 @@ impl ApiTester {
self
}
/// Test fetching execution payload envelope via HTTP API (JSON). Only runs if Gloas is scheduled.
pub async fn test_get_execution_payload_envelope(self) -> Self {
if !self.chain.spec.is_gloas_scheduled() {
return self;
}
let fork = self.chain.canonical_head.cached_head().head_fork();
let genesis_validators_root = self.chain.genesis_validators_root;
for _ in 0..E::slots_per_epoch() * 3 {
let slot = self.chain.slot().unwrap();
let epoch = self.chain.epoch().unwrap();
// Skip if not in Gloas fork yet
let fork_name = self.chain.spec.fork_name_at_slot::<E>(slot);
if !fork_name.gloas_enabled() {
self.chain.slot_clock.set_slot(slot.as_u64() + 1);
continue;
}
let proposer_pubkey_bytes = self
.client
.get_validator_duties_proposer(epoch)
.await
.unwrap()
.data
.into_iter()
.find(|duty| duty.slot == slot)
.map(|duty| duty.pubkey)
.unwrap();
let proposer_pubkey = (&proposer_pubkey_bytes).try_into().unwrap();
let sk = self
.validator_keypairs()
.iter()
.find(|kp| kp.pk == proposer_pubkey)
.map(|kp| kp.sk.clone())
.unwrap();
let randao_reveal = {
let domain = self.chain.spec.get_domain(
epoch,
Domain::Randao,
&fork,
genesis_validators_root,
);
let message = epoch.signing_root(domain);
sk.sign(message).into()
};
// Produce a V4 block (which caches the envelope)
let (response, _metadata) = self
.client
.get_validator_blocks_v4::<E>(slot, &randao_reveal, None, None, None)
.await
.unwrap();
let block = response.data;
let block_root = block.tree_hash_root();
// Fetch the envelope via HTTP API (using builder_index=0 for local building)
let envelope_response = self
.client
.get_validator_execution_payload_envelope::<E>(slot, 0)
.await
.unwrap();
let envelope = envelope_response.data;
assert_eq!(envelope.beacon_block_root, block_root);
assert_eq!(envelope.slot, slot);
self.chain.slot_clock.set_slot(slot.as_u64() + 1);
}
self
}
/// Test fetching execution payload envelope via HTTP API (SSZ). Only runs if Gloas is scheduled.
pub async fn test_get_execution_payload_envelope_ssz(self) -> Self {
if !self.chain.spec.is_gloas_scheduled() {
return self;
}
let fork = self.chain.canonical_head.cached_head().head_fork();
let genesis_validators_root = self.chain.genesis_validators_root;
for _ in 0..E::slots_per_epoch() * 3 {
let slot = self.chain.slot().unwrap();
let epoch = self.chain.epoch().unwrap();
// Skip if not in Gloas fork yet
let fork_name = self.chain.spec.fork_name_at_slot::<E>(slot);
if !fork_name.gloas_enabled() {
self.chain.slot_clock.set_slot(slot.as_u64() + 1);
continue;
}
let proposer_pubkey_bytes = self
.client
.get_validator_duties_proposer(epoch)
.await
.unwrap()
.data
.into_iter()
.find(|duty| duty.slot == slot)
.map(|duty| duty.pubkey)
.unwrap();
let proposer_pubkey = (&proposer_pubkey_bytes).try_into().unwrap();
let sk = self
.validator_keypairs()
.iter()
.find(|kp| kp.pk == proposer_pubkey)
.map(|kp| kp.sk.clone())
.unwrap();
let randao_reveal = {
let domain = self.chain.spec.get_domain(
epoch,
Domain::Randao,
&fork,
genesis_validators_root,
);
let message = epoch.signing_root(domain);
sk.sign(message).into()
};
// Produce a V4 block (which caches the envelope)
let (response, _metadata) = self
.client
.get_validator_blocks_v4::<E>(slot, &randao_reveal, None, None, None)
.await
.unwrap();
let block = response.data;
let block_root = block.tree_hash_root();
// Fetch the envelope via HTTP API in SSZ format
let envelope = self
.client
.get_validator_execution_payload_envelope_ssz::<E>(slot, 0)
.await
.unwrap();
assert_eq!(envelope.beacon_block_root, block_root);
assert_eq!(envelope.slot, slot);
self.chain.slot_clock.set_slot(slot.as_u64() + 1);
}
self
}
pub async fn test_block_production_no_verify_randao(self) -> Self {
for _ in 0..E::slots_per_epoch() {
let slot = self.chain.slot().unwrap();
@@ -7659,6 +7812,22 @@ async fn block_production_v4_ssz() {
.await;
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn get_execution_payload_envelope() {
ApiTester::new_with_hard_forks()
.await
.test_get_execution_payload_envelope()
.await;
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn get_execution_payload_envelope_ssz() {
ApiTester::new_with_hard_forks()
.await
.test_get_execution_payload_envelope_ssz()
.await;
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn blinded_block_production_full_payload_premerge() {
ApiTester::new().await.test_blinded_block_production().await;