mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-10 04:01:51 +00:00
Block v3 endpoint (#4629)
## Issue Addressed #4582 ## Proposed Changes Add a new v3 block fetching flow that can decide to return a Full OR Blinded payload ## Additional Info Co-authored-by: Michael Sproul <micsproul@gmail.com>
This commit is contained in:
@@ -508,11 +508,7 @@ pub fn serve<E: EthSpec>(
|
||||
finalized_hash: Some(finalized_execution_hash),
|
||||
};
|
||||
|
||||
let (payload, _block_value, maybe_blobs_bundle): (
|
||||
ExecutionPayload<E>,
|
||||
Uint256,
|
||||
Option<BlobsBundle<E>>,
|
||||
) = builder
|
||||
let payload_response_type = builder
|
||||
.el
|
||||
.get_full_payload_caching(
|
||||
head_execution_hash,
|
||||
@@ -521,38 +517,88 @@ pub fn serve<E: EthSpec>(
|
||||
fork,
|
||||
)
|
||||
.await
|
||||
.map_err(|_| reject("couldn't get payload"))?
|
||||
.into();
|
||||
.map_err(|_| reject("couldn't get payload"))?;
|
||||
|
||||
let mut message = match fork {
|
||||
ForkName::Deneb => BuilderBid::Deneb(BuilderBidDeneb {
|
||||
header: payload
|
||||
.as_deneb()
|
||||
.map_err(|_| reject("incorrect payload variant"))?
|
||||
.into(),
|
||||
blinded_blobs_bundle: maybe_blobs_bundle
|
||||
.map(Into::into)
|
||||
.unwrap_or_default(),
|
||||
value: Uint256::from(DEFAULT_BUILDER_PAYLOAD_VALUE_WEI),
|
||||
pubkey: builder.builder_sk.public_key().compress(),
|
||||
}),
|
||||
ForkName::Capella => BuilderBid::Capella(BuilderBidCapella {
|
||||
header: payload
|
||||
.as_capella()
|
||||
.map_err(|_| reject("incorrect payload variant"))?
|
||||
.into(),
|
||||
value: Uint256::from(DEFAULT_BUILDER_PAYLOAD_VALUE_WEI),
|
||||
pubkey: builder.builder_sk.public_key().compress(),
|
||||
}),
|
||||
ForkName::Merge => BuilderBid::Merge(BuilderBidMerge {
|
||||
header: payload
|
||||
.as_merge()
|
||||
.map_err(|_| reject("incorrect payload variant"))?
|
||||
.into(),
|
||||
value: Uint256::from(DEFAULT_BUILDER_PAYLOAD_VALUE_WEI),
|
||||
pubkey: builder.builder_sk.public_key().compress(),
|
||||
}),
|
||||
ForkName::Base | ForkName::Altair => return Err(reject("invalid fork")),
|
||||
let mut message = match payload_response_type {
|
||||
crate::GetPayloadResponseType::Full(payload_response) => {
|
||||
let (payload, _block_value, maybe_blobs_bundle): (
|
||||
ExecutionPayload<E>,
|
||||
Uint256,
|
||||
Option<BlobsBundle<E>>,
|
||||
) = payload_response.into();
|
||||
|
||||
match fork {
|
||||
ForkName::Deneb => BuilderBid::Deneb(BuilderBidDeneb {
|
||||
header: payload
|
||||
.as_deneb()
|
||||
.map_err(|_| reject("incorrect payload variant"))?
|
||||
.into(),
|
||||
blinded_blobs_bundle: maybe_blobs_bundle
|
||||
.map(Into::into)
|
||||
.unwrap_or_default(),
|
||||
value: Uint256::from(DEFAULT_BUILDER_PAYLOAD_VALUE_WEI),
|
||||
pubkey: builder.builder_sk.public_key().compress(),
|
||||
}),
|
||||
ForkName::Capella => BuilderBid::Capella(BuilderBidCapella {
|
||||
header: payload
|
||||
.as_capella()
|
||||
.map_err(|_| reject("incorrect payload variant"))?
|
||||
.into(),
|
||||
value: Uint256::from(DEFAULT_BUILDER_PAYLOAD_VALUE_WEI),
|
||||
pubkey: builder.builder_sk.public_key().compress(),
|
||||
}),
|
||||
ForkName::Merge => BuilderBid::Merge(BuilderBidMerge {
|
||||
header: payload
|
||||
.as_merge()
|
||||
.map_err(|_| reject("incorrect payload variant"))?
|
||||
.into(),
|
||||
value: Uint256::from(DEFAULT_BUILDER_PAYLOAD_VALUE_WEI),
|
||||
pubkey: builder.builder_sk.public_key().compress(),
|
||||
}),
|
||||
ForkName::Base | ForkName::Altair => {
|
||||
return Err(reject("invalid fork"))
|
||||
}
|
||||
}
|
||||
}
|
||||
crate::GetPayloadResponseType::Blinded(payload_response) => {
|
||||
let (payload, _block_value, maybe_blobs_bundle): (
|
||||
ExecutionPayload<E>,
|
||||
Uint256,
|
||||
Option<BlobsBundle<E>>,
|
||||
) = payload_response.into();
|
||||
match fork {
|
||||
ForkName::Deneb => BuilderBid::Deneb(BuilderBidDeneb {
|
||||
header: payload
|
||||
.as_deneb()
|
||||
.map_err(|_| reject("incorrect payload variant"))?
|
||||
.into(),
|
||||
blinded_blobs_bundle: maybe_blobs_bundle
|
||||
.map(Into::into)
|
||||
.unwrap_or_default(),
|
||||
value: Uint256::from(DEFAULT_BUILDER_PAYLOAD_VALUE_WEI),
|
||||
pubkey: builder.builder_sk.public_key().compress(),
|
||||
}),
|
||||
ForkName::Capella => BuilderBid::Capella(BuilderBidCapella {
|
||||
header: payload
|
||||
.as_capella()
|
||||
.map_err(|_| reject("incorrect payload variant"))?
|
||||
.into(),
|
||||
value: Uint256::from(DEFAULT_BUILDER_PAYLOAD_VALUE_WEI),
|
||||
pubkey: builder.builder_sk.public_key().compress(),
|
||||
}),
|
||||
ForkName::Merge => BuilderBid::Merge(BuilderBidMerge {
|
||||
header: payload
|
||||
.as_merge()
|
||||
.map_err(|_| reject("incorrect payload variant"))?
|
||||
.into(),
|
||||
value: Uint256::from(DEFAULT_BUILDER_PAYLOAD_VALUE_WEI),
|
||||
pubkey: builder.builder_sk.public_key().compress(),
|
||||
}),
|
||||
ForkName::Base | ForkName::Altair => {
|
||||
return Err(reject("invalid fork"))
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
message.set_gas_limit(cached_data.gas_limit);
|
||||
|
||||
@@ -5,12 +5,12 @@ use crate::{
|
||||
},
|
||||
Config, *,
|
||||
};
|
||||
use keccak_hash::H256;
|
||||
use kzg::Kzg;
|
||||
use sensitive_url::SensitiveUrl;
|
||||
use task_executor::TaskExecutor;
|
||||
use tempfile::NamedTempFile;
|
||||
use tree_hash::TreeHash;
|
||||
use types::{Address, ChainSpec, Epoch, EthSpec, FullPayload, Hash256, MainnetEthSpec};
|
||||
use types::{Address, ChainSpec, Epoch, EthSpec, Hash256, MainnetEthSpec};
|
||||
|
||||
pub struct MockExecutionLayer<T: EthSpec> {
|
||||
pub server: MockServer<T>,
|
||||
@@ -133,20 +133,25 @@ impl<T: EthSpec> MockExecutionLayer<T> {
|
||||
let suggested_fee_recipient = self.el.get_suggested_fee_recipient(validator_index).await;
|
||||
let payload_attributes =
|
||||
PayloadAttributes::new(timestamp, prev_randao, suggested_fee_recipient, None, None);
|
||||
let payload: ExecutionPayload<T> = self
|
||||
|
||||
let block_proposal_content_type = self
|
||||
.el
|
||||
.get_payload::<FullPayload<T>>(
|
||||
.get_payload(
|
||||
parent_hash,
|
||||
&payload_attributes,
|
||||
forkchoice_update_params,
|
||||
builder_params,
|
||||
ForkName::Merge,
|
||||
&self.spec,
|
||||
BlockProductionVersion::FullV2,
|
||||
)
|
||||
.await
|
||||
.unwrap()
|
||||
.to_payload()
|
||||
.into();
|
||||
.unwrap();
|
||||
|
||||
let payload: ExecutionPayload<T> = match block_proposal_content_type {
|
||||
BlockProposalContentsType::Full(block) => block.to_payload().into(),
|
||||
BlockProposalContentsType::Blinded(_) => panic!("Should always be a full payload"),
|
||||
};
|
||||
|
||||
let block_hash = payload.block_hash();
|
||||
assert_eq!(payload.parent_hash(), parent_hash);
|
||||
@@ -167,20 +172,64 @@ impl<T: EthSpec> MockExecutionLayer<T> {
|
||||
let suggested_fee_recipient = self.el.get_suggested_fee_recipient(validator_index).await;
|
||||
let payload_attributes =
|
||||
PayloadAttributes::new(timestamp, prev_randao, suggested_fee_recipient, None, None);
|
||||
let payload_header = self
|
||||
|
||||
let block_proposal_content_type = self
|
||||
.el
|
||||
.get_payload::<BlindedPayload<T>>(
|
||||
.get_payload(
|
||||
parent_hash,
|
||||
&payload_attributes,
|
||||
forkchoice_update_params,
|
||||
builder_params,
|
||||
ForkName::Merge,
|
||||
&self.spec,
|
||||
BlockProductionVersion::BlindedV2,
|
||||
)
|
||||
.await
|
||||
.unwrap()
|
||||
.to_payload();
|
||||
.unwrap();
|
||||
|
||||
match block_proposal_content_type {
|
||||
BlockProposalContentsType::Full(block) => {
|
||||
let payload_header = block.to_payload();
|
||||
self.assert_valid_execution_payload_on_head(
|
||||
payload,
|
||||
payload_header,
|
||||
block_hash,
|
||||
parent_hash,
|
||||
block_number,
|
||||
timestamp,
|
||||
prev_randao,
|
||||
)
|
||||
.await;
|
||||
}
|
||||
BlockProposalContentsType::Blinded(block) => {
|
||||
let payload_header = block.to_payload();
|
||||
self.assert_valid_execution_payload_on_head(
|
||||
payload,
|
||||
payload_header,
|
||||
block_hash,
|
||||
parent_hash,
|
||||
block_number,
|
||||
timestamp,
|
||||
prev_randao,
|
||||
)
|
||||
.await;
|
||||
}
|
||||
};
|
||||
|
||||
self
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub async fn assert_valid_execution_payload_on_head<Payload: AbstractExecPayload<T>>(
|
||||
&self,
|
||||
payload: ExecutionPayload<T>,
|
||||
payload_header: Payload,
|
||||
block_hash: ExecutionBlockHash,
|
||||
parent_hash: ExecutionBlockHash,
|
||||
block_number: u64,
|
||||
timestamp: u64,
|
||||
prev_randao: H256,
|
||||
) {
|
||||
assert_eq!(payload_header.block_hash(), block_hash);
|
||||
assert_eq!(payload_header.parent_hash(), parent_hash);
|
||||
assert_eq!(payload_header.block_number(), block_number);
|
||||
@@ -224,8 +273,6 @@ impl<T: EthSpec> MockExecutionLayer<T> {
|
||||
assert_eq!(head_execution_block.block_number(), block_number);
|
||||
assert_eq!(head_execution_block.block_hash(), block_hash);
|
||||
assert_eq!(head_execution_block.parent_hash(), parent_hash);
|
||||
|
||||
self
|
||||
}
|
||||
|
||||
pub fn move_to_block_prior_to_terminal_block(self) -> Self {
|
||||
|
||||
Reference in New Issue
Block a user