mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-14 02:12:33 +00:00
merge block production
This commit is contained in:
129
beacon_node/http_api/src/beacon/execution_payload_envelope.rs
Normal file
129
beacon_node/http_api/src/beacon/execution_payload_envelope.rs
Normal file
@@ -0,0 +1,129 @@
|
||||
use crate::task_spawner::{Priority, TaskSpawner};
|
||||
use crate::utils::{ChainFilter, EthV1Filter, NetworkTxFilter, ResponseFilter, TaskSpawnerFilter};
|
||||
use beacon_chain::{BeaconChain, BeaconChainTypes};
|
||||
use bytes::Bytes;
|
||||
use eth2::{CONTENT_TYPE_HEADER, SSZ_CONTENT_TYPE_HEADER};
|
||||
use lighthouse_network::PubsubMessage;
|
||||
use network::NetworkMessage;
|
||||
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};
|
||||
|
||||
// POST beacon/execution_payload_envelope (SSZ)
|
||||
pub(crate) fn post_beacon_execution_payload_envelope_ssz<T: BeaconChainTypes>(
|
||||
eth_v1: EthV1Filter,
|
||||
task_spawner_filter: TaskSpawnerFilter<T>,
|
||||
chain_filter: ChainFilter<T>,
|
||||
network_tx_filter: NetworkTxFilter<T>,
|
||||
) -> ResponseFilter {
|
||||
eth_v1
|
||||
.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)
|
||||
.and(chain_filter)
|
||||
.and(network_tx_filter)
|
||||
.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(envelope, chain, &network_tx).await
|
||||
})
|
||||
},
|
||||
)
|
||||
.boxed()
|
||||
}
|
||||
|
||||
// POST beacon/execution_payload_envelope
|
||||
pub(crate) fn post_beacon_execution_payload_envelope<T: BeaconChainTypes>(
|
||||
eth_v1: EthV1Filter,
|
||||
task_spawner_filter: TaskSpawnerFilter<T>,
|
||||
chain_filter: ChainFilter<T>,
|
||||
network_tx_filter: NetworkTxFilter<T>,
|
||||
) -> ResponseFilter {
|
||||
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(envelope, chain, &network_tx).await
|
||||
})
|
||||
},
|
||||
)
|
||||
.boxed()
|
||||
}
|
||||
/// 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): Do we want to add more validation like:
|
||||
// - Verify the signature
|
||||
// - Check builder_index is valid
|
||||
// - Verify the envelope references a known block
|
||||
//
|
||||
// If we do, then we must post the signed execution payload envelope to the BN that originally produced it.
|
||||
|
||||
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())
|
||||
}
|
||||
@@ -1,2 +1,3 @@
|
||||
pub mod execution_payload_envelope;
|
||||
pub mod pool;
|
||||
pub mod states;
|
||||
|
||||
@@ -28,7 +28,6 @@ pub fn get_beacon_state_pending_consolidations<T: BeaconChainTypes>(
|
||||
beacon_states_path: BeaconStatesPath<T>,
|
||||
) -> ResponseFilter {
|
||||
beacon_states_path
|
||||
.clone()
|
||||
.and(warp::path("pending_consolidations"))
|
||||
.and(warp::path::end())
|
||||
.then(
|
||||
|
||||
@@ -36,6 +36,9 @@ mod validator_inclusion;
|
||||
mod validators;
|
||||
mod version;
|
||||
|
||||
use crate::beacon::execution_payload_envelope::{
|
||||
post_beacon_execution_payload_envelope, post_beacon_execution_payload_envelope_ssz,
|
||||
};
|
||||
use crate::beacon::pool::*;
|
||||
use crate::light_client::{get_light_client_bootstrap, get_light_client_updates};
|
||||
use crate::utils::{AnyVersionFilter, EthV1Filter};
|
||||
@@ -92,6 +95,7 @@ use types::{
|
||||
BeaconStateError, Checkpoint, ConfigAndPreset, Epoch, EthSpec, ForkName, Hash256,
|
||||
SignedBlindedBeaconBlock, Slot,
|
||||
};
|
||||
use validator::execution_payload_envelope::get_validator_execution_payload_envelope;
|
||||
use version::{
|
||||
ResponseIncludesVersion, V1, V2, add_consensus_version_header, add_ssz_content_type_header,
|
||||
execution_optimistic_finalized_beacon_response, inconsistent_fork_rejection,
|
||||
@@ -1486,6 +1490,22 @@ 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 = post_beacon_execution_payload_envelope(
|
||||
eth_v1.clone(),
|
||||
task_spawner_filter.clone(),
|
||||
chain_filter.clone(),
|
||||
network_tx_filter.clone(),
|
||||
);
|
||||
|
||||
// POST beacon/execution_payload_envelope (SSZ)
|
||||
let post_beacon_execution_payload_envelope_ssz = post_beacon_execution_payload_envelope_ssz(
|
||||
eth_v1.clone(),
|
||||
task_spawner_filter.clone(),
|
||||
chain_filter.clone(),
|
||||
network_tx_filter.clone(),
|
||||
);
|
||||
|
||||
let beacon_rewards_path = eth_v1
|
||||
.clone()
|
||||
.and(warp::path("beacon"))
|
||||
@@ -2466,6 +2486,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(),
|
||||
@@ -3336,6 +3364,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)
|
||||
@@ -3374,7 +3403,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 +3416,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)
|
||||
|
||||
@@ -43,6 +43,49 @@ pub fn get_randao_verification(
|
||||
Ok(randao_verification)
|
||||
}
|
||||
|
||||
#[instrument(
|
||||
name = "lh_produce_block_v4",
|
||||
skip_all,
|
||||
fields(%slot)
|
||||
)]
|
||||
pub async fn produce_block_v4<T: BeaconChainTypes>(
|
||||
accept_header: Option<api_types::Accept>,
|
||||
chain: Arc<BeaconChain<T>>,
|
||||
slot: Slot,
|
||||
query: api_types::ValidatorBlocksQuery,
|
||||
) -> Result<Response<Body>, warp::Rejection> {
|
||||
let randao_reveal = query.randao_reveal.decompress().map_err(|e| {
|
||||
warp_utils::reject::custom_bad_request(format!(
|
||||
"randao reveal is not a valid BLS signature: {:?}",
|
||||
e
|
||||
))
|
||||
})?;
|
||||
|
||||
let randao_verification = get_randao_verification(&query, randao_reveal.is_infinity())?;
|
||||
let builder_boost_factor = if query.builder_boost_factor == Some(DEFAULT_BOOST_FACTOR) {
|
||||
None
|
||||
} else {
|
||||
query.builder_boost_factor
|
||||
};
|
||||
|
||||
let graffiti_settings = GraffitiSettings::new(query.graffiti, query.graffiti_policy);
|
||||
|
||||
let (block, consensus_block_value) = chain
|
||||
.produce_block_with_verification_gloas(
|
||||
randao_reveal,
|
||||
slot,
|
||||
graffiti_settings,
|
||||
randao_verification,
|
||||
builder_boost_factor,
|
||||
)
|
||||
.await
|
||||
.map_err(|e| {
|
||||
warp_utils::reject::custom_bad_request(format!("failed to fetch a block: {:?}", e))
|
||||
})?;
|
||||
|
||||
build_response_v4::<T>(block, consensus_block_value, accept_header, &chain.spec)
|
||||
}
|
||||
|
||||
#[instrument(
|
||||
name = "lh_produce_block_v3",
|
||||
skip_all,
|
||||
@@ -87,6 +130,39 @@ pub async fn produce_block_v3<T: BeaconChainTypes>(
|
||||
build_response_v3(chain, block_response_type, accept_header)
|
||||
}
|
||||
|
||||
pub fn build_response_v4<T: BeaconChainTypes>(
|
||||
block: BeaconBlock<T::EthSpec, FullPayload<T::EthSpec>>,
|
||||
consensus_block_value: u64,
|
||||
accept_header: Option<api_types::Accept>,
|
||||
spec: &ChainSpec,
|
||||
) -> Result<Response<Body>, warp::Rejection> {
|
||||
let fork_name = block
|
||||
.to_ref()
|
||||
.fork_name(spec)
|
||||
.map_err(inconsistent_fork_rejection)?;
|
||||
let consensus_block_value_wei =
|
||||
Uint256::from(consensus_block_value) * Uint256::from(1_000_000_000u64);
|
||||
|
||||
match accept_header {
|
||||
Some(api_types::Accept::Ssz) => Response::builder()
|
||||
.status(200)
|
||||
.body(block.as_ssz_bytes().into())
|
||||
.map(|res: Response<Body>| add_ssz_content_type_header(res))
|
||||
.map(|res: Response<Body>| add_consensus_version_header(res, fork_name))
|
||||
.map(|res| add_consensus_block_value_header(res, consensus_block_value_wei))
|
||||
.map_err(|e| -> warp::Rejection {
|
||||
warp_utils::reject::custom_server_error(format!("failed to create response: {}", e))
|
||||
}),
|
||||
_ => Ok(warp::reply::json(&beacon_response(
|
||||
ResponseIncludesVersion::Yes(fork_name),
|
||||
block,
|
||||
))
|
||||
.into_response())
|
||||
.map(|res| add_consensus_version_header(res, fork_name))
|
||||
.map(|res| add_consensus_block_value_header(res, consensus_block_value_wei)),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn build_response_v3<T: BeaconChainTypes>(
|
||||
chain: Arc<BeaconChain<T>>,
|
||||
block_response: BeaconBlockResponseWrapper<T::EthSpec>,
|
||||
|
||||
105
beacon_node/http_api/src/validator/execution_payload_envelope.rs
Normal file
105
beacon_node/http_api/src/validator/execution_payload_envelope.rs
Normal file
@@ -0,0 +1,105 @@
|
||||
use crate::task_spawner::{Priority, TaskSpawner};
|
||||
use crate::utils::{
|
||||
ChainFilter, EthV1Filter, NotWhileSyncingFilter, ResponseFilter, TaskSpawnerFilter,
|
||||
};
|
||||
use beacon_chain::{BeaconChain, BeaconChainTypes};
|
||||
use eth2::types::{Accept, GenericResponse};
|
||||
use ssz::Encode;
|
||||
use std::sync::Arc;
|
||||
use tracing::debug;
|
||||
use types::Slot;
|
||||
use warp::http::Response;
|
||||
use warp::{Filter, Rejection};
|
||||
|
||||
// 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()
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
use crate::produce_block::{produce_blinded_block_v2, produce_block_v2, produce_block_v3};
|
||||
use crate::produce_block::{
|
||||
produce_blinded_block_v2, produce_block_v2, produce_block_v3, produce_block_v4,
|
||||
};
|
||||
use crate::task_spawner::{Priority, TaskSpawner};
|
||||
use crate::utils::{
|
||||
AnyVersionFilter, ChainFilter, EthV1Filter, NetworkTxFilter, NotWhileSyncingFilter,
|
||||
@@ -31,6 +33,8 @@ use types::{
|
||||
use warp::{Filter, Rejection, Reply};
|
||||
use warp_utils::reject::convert_rejection;
|
||||
|
||||
pub mod execution_payload_envelope;
|
||||
|
||||
/// Uses the `chain.validator_pubkey_cache` to resolve a pubkey to a validator
|
||||
/// index and then ensures that the validator exists in the given `state`.
|
||||
pub fn pubkey_to_validator_index<T: BeaconChainTypes>(
|
||||
@@ -316,7 +320,11 @@ pub fn get_validator_blocks<T: BeaconChainTypes>(
|
||||
|
||||
not_synced_filter?;
|
||||
|
||||
if endpoint_version == V3 {
|
||||
// Use V4 block production for Gloas fork
|
||||
let fork_name = chain.spec.fork_name_at_slot::<T::EthSpec>(slot);
|
||||
if fork_name.gloas_enabled() {
|
||||
produce_block_v4(accept_header, chain, slot, query).await
|
||||
} else if endpoint_version == V3 {
|
||||
produce_block_v3(accept_header, chain, slot, query).await
|
||||
} else {
|
||||
produce_block_v2(accept_header, chain, slot, query).await
|
||||
|
||||
@@ -47,7 +47,8 @@ use tree_hash::TreeHash;
|
||||
use types::ApplicationDomain;
|
||||
use types::{
|
||||
Domain, EthSpec, ExecutionBlockHash, Hash256, MainnetEthSpec, RelativeEpoch, SelectionProof,
|
||||
SignedRoot, SingleAttestation, Slot, attestation::AttestationBase,
|
||||
SignedExecutionPayloadEnvelope, SignedRoot, SingleAttestation, Slot,
|
||||
attestation::AttestationBase, consts::gloas::BUILDER_INDEX_SELF_BUILD,
|
||||
};
|
||||
|
||||
type E = MainnetEthSpec;
|
||||
@@ -3726,6 +3727,241 @@ impl ApiTester {
|
||||
self
|
||||
}
|
||||
|
||||
/// Test V4 block production (JSON). Only runs if Gloas is scheduled.
|
||||
pub async fn test_block_production_v4(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()
|
||||
};
|
||||
|
||||
let (response, metadata) = self
|
||||
.client
|
||||
.get_validator_blocks_v4::<E>(slot, &randao_reveal, None, None, None)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let block = response.data;
|
||||
assert_eq!(
|
||||
metadata.consensus_version,
|
||||
block.to_ref().fork_name(&self.chain.spec).unwrap()
|
||||
);
|
||||
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 (keyed by slot) until publishing.
|
||||
let block_root = block.tree_hash_root();
|
||||
{
|
||||
let envelope = self
|
||||
.chain
|
||||
.pending_payload_envelopes
|
||||
.read()
|
||||
.get(slot)
|
||||
.cloned()
|
||||
.expect("envelope should exist in pending cache for local building");
|
||||
assert_eq!(envelope.beacon_block_root, block_root);
|
||||
assert_eq!(envelope.slot, slot);
|
||||
}
|
||||
|
||||
// Fetch the envelope via the HTTP API
|
||||
let envelope_response = self
|
||||
.client
|
||||
.get_validator_execution_payload_envelope::<E>(slot, BUILDER_INDEX_SELF_BUILD)
|
||||
.await
|
||||
.unwrap();
|
||||
let envelope = envelope_response.data;
|
||||
|
||||
// Verify envelope fields
|
||||
assert_eq!(envelope.beacon_block_root, block_root);
|
||||
assert_eq!(envelope.slot, slot);
|
||||
assert_eq!(envelope.builder_index, BUILDER_INDEX_SELF_BUILD);
|
||||
assert_ne!(envelope.state_root, Hash256::ZERO);
|
||||
|
||||
// Sign and publish the block
|
||||
let signed_block = block.sign(&sk, &fork, genesis_validators_root, &self.chain.spec);
|
||||
let signed_block_request =
|
||||
PublishBlockRequest::try_from(Arc::new(signed_block.clone())).unwrap();
|
||||
|
||||
self.client
|
||||
.post_beacon_blocks_v2(&signed_block_request, None)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(self.chain.head_beacon_block(), Arc::new(signed_block));
|
||||
|
||||
// Sign and publish the execution payload envelope
|
||||
let domain = self.chain.spec.get_builder_domain();
|
||||
let signing_root = envelope.signing_root(domain);
|
||||
let signature = sk.sign(signing_root);
|
||||
|
||||
let signed_envelope = SignedExecutionPayloadEnvelope {
|
||||
message: envelope,
|
||||
signature,
|
||||
};
|
||||
|
||||
self.client
|
||||
.post_beacon_execution_payload_envelope(&signed_envelope)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
self.chain.slot_clock.set_slot(slot.as_u64() + 1);
|
||||
}
|
||||
|
||||
self
|
||||
}
|
||||
|
||||
/// Test V4 block production (SSZ). Only runs if Gloas is scheduled.
|
||||
pub async fn test_block_production_v4_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()
|
||||
};
|
||||
|
||||
let (block, metadata) = self
|
||||
.client
|
||||
.get_validator_blocks_v4_ssz::<E>(slot, &randao_reveal, None, None, None)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let block_root = block.tree_hash_root();
|
||||
|
||||
assert_eq!(
|
||||
metadata.consensus_version,
|
||||
block.to_ref().fork_name(&self.chain.spec).unwrap()
|
||||
);
|
||||
assert!(!metadata.consensus_block_value.is_zero());
|
||||
|
||||
// Fetch the envelope via the HTTP API (SSZ)
|
||||
let envelope = self
|
||||
.client
|
||||
.get_validator_execution_payload_envelope_ssz::<E>(slot, BUILDER_INDEX_SELF_BUILD)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
// Verify envelope fields
|
||||
assert_eq!(envelope.beacon_block_root, block_root);
|
||||
assert_eq!(envelope.slot, slot);
|
||||
assert_eq!(envelope.builder_index, BUILDER_INDEX_SELF_BUILD);
|
||||
assert_ne!(envelope.state_root, Hash256::ZERO);
|
||||
|
||||
// Sign and publish the block
|
||||
let signed_block = block.sign(&sk, &fork, genesis_validators_root, &self.chain.spec);
|
||||
let signed_block_request =
|
||||
PublishBlockRequest::try_from(Arc::new(signed_block.clone())).unwrap();
|
||||
|
||||
self.client
|
||||
.post_beacon_blocks_v2_ssz(&signed_block_request, None)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(self.chain.head_beacon_block(), Arc::new(signed_block));
|
||||
|
||||
// Sign and publish the execution payload envelope
|
||||
let domain = self.chain.spec.get_builder_domain();
|
||||
let signing_root = envelope.signing_root(domain);
|
||||
let signature = sk.sign(signing_root);
|
||||
|
||||
let signed_envelope = SignedExecutionPayloadEnvelope {
|
||||
message: envelope,
|
||||
signature,
|
||||
};
|
||||
|
||||
self.client
|
||||
.post_beacon_execution_payload_envelope(&signed_envelope)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
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();
|
||||
@@ -7459,6 +7695,22 @@ async fn block_production_v3_ssz_with_skip_slots() {
|
||||
.await;
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn block_production_v4() {
|
||||
ApiTester::new_with_hard_forks()
|
||||
.await
|
||||
.test_block_production_v4()
|
||||
.await;
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn block_production_v4_ssz() {
|
||||
ApiTester::new_with_hard_forks()
|
||||
.await
|
||||
.test_block_production_v4_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;
|
||||
|
||||
Reference in New Issue
Block a user