Use E for EthSpec globally (#5264)

* Use `E` for `EthSpec` globally

* Fix tests

* Merge branch 'unstable' into e-ethspec

* Merge branch 'unstable' into e-ethspec

# Conflicts:
#	beacon_node/execution_layer/src/engine_api.rs
#	beacon_node/execution_layer/src/engine_api/http.rs
#	beacon_node/execution_layer/src/engine_api/json_structures.rs
#	beacon_node/execution_layer/src/test_utils/handle_rpc.rs
#	beacon_node/store/src/partial_beacon_state.rs
#	consensus/types/src/beacon_block.rs
#	consensus/types/src/beacon_block_body.rs
#	consensus/types/src/beacon_state.rs
#	consensus/types/src/config_and_preset.rs
#	consensus/types/src/execution_payload.rs
#	consensus/types/src/execution_payload_header.rs
#	consensus/types/src/light_client_optimistic_update.rs
#	consensus/types/src/payload.rs
#	lcli/src/parse_ssz.rs
This commit is contained in:
Mac L
2024-04-03 02:12:25 +11:00
committed by GitHub
parent f8fdb71f50
commit 969d12dc6f
230 changed files with 2743 additions and 2792 deletions

View File

@@ -14,8 +14,8 @@ use types::{
///
/// Return `(block_hash, transactions_root)`, where `transactions_root` is the root of the RLP
/// transactions.
pub fn calculate_execution_block_hash<T: EthSpec>(
payload: ExecutionPayloadRef<T>,
pub fn calculate_execution_block_hash<E: EthSpec>(
payload: ExecutionPayloadRef<E>,
parent_beacon_block_root: Option<Hash256>,
) -> (ExecutionBlockHash, Hash256) {
// Calculate the transactions root.

View File

@@ -158,21 +158,21 @@ pub struct ExecutionBlock {
variants(Merge, Capella, Deneb, Electra),
variant_attributes(
derive(Clone, Debug, PartialEq, Serialize, Deserialize,),
serde(bound = "T: EthSpec", rename_all = "camelCase"),
serde(bound = "E: EthSpec", rename_all = "camelCase"),
),
cast_error(ty = "Error", expr = "Error::IncorrectStateVariant"),
partial_getter_error(ty = "Error", expr = "Error::IncorrectStateVariant")
)]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(bound = "T: EthSpec", rename_all = "camelCase", untagged)]
pub struct ExecutionBlockWithTransactions<T: EthSpec> {
#[serde(bound = "E: EthSpec", rename_all = "camelCase", untagged)]
pub struct ExecutionBlockWithTransactions<E: EthSpec> {
pub parent_hash: ExecutionBlockHash,
#[serde(alias = "miner")]
pub fee_recipient: Address,
pub state_root: Hash256,
pub receipts_root: Hash256,
#[serde(with = "ssz_types::serde_utils::hex_fixed_vec")]
pub logs_bloom: FixedVector<u8, T::BytesPerLogsBloom>,
pub logs_bloom: FixedVector<u8, E::BytesPerLogsBloom>,
#[serde(alias = "mixHash")]
pub prev_randao: Hash256,
#[serde(rename = "number", with = "serde_utils::u64_hex_be")]
@@ -184,7 +184,7 @@ pub struct ExecutionBlockWithTransactions<T: EthSpec> {
#[serde(with = "serde_utils::u64_hex_be")]
pub timestamp: u64,
#[serde(with = "ssz_types::serde_utils::hex_var_list")]
pub extra_data: VariableList<u8, T::MaxExtraDataBytes>,
pub extra_data: VariableList<u8, E::MaxExtraDataBytes>,
pub base_fee_per_gas: Uint256,
#[serde(rename = "hash")]
pub block_hash: ExecutionBlockHash,
@@ -199,10 +199,10 @@ pub struct ExecutionBlockWithTransactions<T: EthSpec> {
pub excess_blob_gas: u64,
}
impl<T: EthSpec> TryFrom<ExecutionPayload<T>> for ExecutionBlockWithTransactions<T> {
impl<E: EthSpec> TryFrom<ExecutionPayload<E>> for ExecutionBlockWithTransactions<E> {
type Error = Error;
fn try_from(payload: ExecutionPayload<T>) -> Result<Self, Error> {
fn try_from(payload: ExecutionPayload<E>) -> Result<Self, Error> {
let json_payload = match payload {
ExecutionPayload::Merge(block) => Self::Merge(ExecutionBlockWithTransactionsMerge {
parent_hash: block.parent_hash,
@@ -431,18 +431,18 @@ pub struct ProposeBlindedBlockResponse {
partial_getter_error(ty = "Error", expr = "Error::IncorrectStateVariant")
)]
#[derive(Clone, Debug, PartialEq)]
pub struct GetPayloadResponse<T: EthSpec> {
pub struct GetPayloadResponse<E: EthSpec> {
#[superstruct(only(Merge), partial_getter(rename = "execution_payload_merge"))]
pub execution_payload: ExecutionPayloadMerge<T>,
pub execution_payload: ExecutionPayloadMerge<E>,
#[superstruct(only(Capella), partial_getter(rename = "execution_payload_capella"))]
pub execution_payload: ExecutionPayloadCapella<T>,
pub execution_payload: ExecutionPayloadCapella<E>,
#[superstruct(only(Deneb), partial_getter(rename = "execution_payload_deneb"))]
pub execution_payload: ExecutionPayloadDeneb<T>,
pub execution_payload: ExecutionPayloadDeneb<E>,
#[superstruct(only(Electra), partial_getter(rename = "execution_payload_electra"))]
pub execution_payload: ExecutionPayloadElectra<T>,
pub execution_payload: ExecutionPayloadElectra<E>,
pub block_value: Uint256,
#[superstruct(only(Deneb, Electra))]
pub blobs_bundle: BlobsBundle<T>,
pub blobs_bundle: BlobsBundle<E>,
#[superstruct(only(Deneb, Electra), partial_getter(copy))]
pub should_override_builder: bool,
}
@@ -461,26 +461,26 @@ impl<E: EthSpec> GetPayloadResponse<E> {
}
}
impl<'a, T: EthSpec> From<GetPayloadResponseRef<'a, T>> for ExecutionPayloadRef<'a, T> {
fn from(response: GetPayloadResponseRef<'a, T>) -> Self {
impl<'a, E: EthSpec> From<GetPayloadResponseRef<'a, E>> for ExecutionPayloadRef<'a, E> {
fn from(response: GetPayloadResponseRef<'a, E>) -> Self {
map_get_payload_response_ref_into_execution_payload_ref!(&'a _, response, |inner, cons| {
cons(&inner.execution_payload)
})
}
}
impl<T: EthSpec> From<GetPayloadResponse<T>> for ExecutionPayload<T> {
fn from(response: GetPayloadResponse<T>) -> Self {
impl<E: EthSpec> From<GetPayloadResponse<E>> for ExecutionPayload<E> {
fn from(response: GetPayloadResponse<E>) -> Self {
map_get_payload_response_into_execution_payload!(response, |inner, cons| {
cons(inner.execution_payload)
})
}
}
impl<T: EthSpec> From<GetPayloadResponse<T>>
for (ExecutionPayload<T>, Uint256, Option<BlobsBundle<T>>)
impl<E: EthSpec> From<GetPayloadResponse<E>>
for (ExecutionPayload<E>, Uint256, Option<BlobsBundle<E>>)
{
fn from(response: GetPayloadResponse<T>) -> Self {
fn from(response: GetPayloadResponse<E>) -> Self {
match response {
GetPayloadResponse::Merge(inner) => (
ExecutionPayload::Merge(inner.execution_payload),
@@ -511,8 +511,8 @@ pub enum GetPayloadResponseType<E: EthSpec> {
Blinded(GetPayloadResponse<E>),
}
impl<T: EthSpec> GetPayloadResponse<T> {
pub fn execution_payload_ref(&self) -> ExecutionPayloadRef<T> {
impl<E: EthSpec> GetPayloadResponse<E> {
pub fn execution_payload_ref(&self) -> ExecutionPayloadRef<E> {
self.to_ref().into()
}
}

View File

@@ -709,11 +709,11 @@ impl HttpJsonRpc {
.await
}
pub async fn get_block_by_hash_with_txns<T: EthSpec>(
pub async fn get_block_by_hash_with_txns<E: EthSpec>(
&self,
block_hash: ExecutionBlockHash,
fork: ForkName,
) -> Result<Option<ExecutionBlockWithTransactions<T>>, Error> {
) -> Result<Option<ExecutionBlockWithTransactions<E>>, Error> {
let params = json!([block_hash, true]);
Ok(Some(match fork {
ForkName::Merge => ExecutionBlockWithTransactions::Merge(
@@ -757,9 +757,9 @@ impl HttpJsonRpc {
}))
}
pub async fn new_payload_v1<T: EthSpec>(
pub async fn new_payload_v1<E: EthSpec>(
&self,
execution_payload: ExecutionPayload<T>,
execution_payload: ExecutionPayload<E>,
) -> Result<PayloadStatusV1, Error> {
let params = json!([JsonExecutionPayload::from(execution_payload)]);
@@ -774,9 +774,9 @@ impl HttpJsonRpc {
Ok(response.into())
}
pub async fn new_payload_v2<T: EthSpec>(
pub async fn new_payload_v2<E: EthSpec>(
&self,
execution_payload: ExecutionPayload<T>,
execution_payload: ExecutionPayload<E>,
) -> Result<PayloadStatusV1, Error> {
let params = json!([JsonExecutionPayload::from(execution_payload)]);
@@ -791,9 +791,9 @@ impl HttpJsonRpc {
Ok(response.into())
}
pub async fn new_payload_v3_deneb<T: EthSpec>(
pub async fn new_payload_v3_deneb<E: EthSpec>(
&self,
new_payload_request_deneb: NewPayloadRequestDeneb<'_, T>,
new_payload_request_deneb: NewPayloadRequestDeneb<'_, E>,
) -> Result<PayloadStatusV1, Error> {
let params = json!([
JsonExecutionPayload::V3(new_payload_request_deneb.execution_payload.clone().into()),
@@ -812,9 +812,9 @@ impl HttpJsonRpc {
Ok(response.into())
}
pub async fn new_payload_v3_electra<T: EthSpec>(
pub async fn new_payload_v3_electra<E: EthSpec>(
&self,
new_payload_request_electra: NewPayloadRequestElectra<'_, T>,
new_payload_request_electra: NewPayloadRequestElectra<'_, E>,
) -> Result<PayloadStatusV1, Error> {
let params = json!([
JsonExecutionPayload::V4(new_payload_request_electra.execution_payload.clone().into()),
@@ -833,13 +833,13 @@ impl HttpJsonRpc {
Ok(response.into())
}
pub async fn get_payload_v1<T: EthSpec>(
pub async fn get_payload_v1<E: EthSpec>(
&self,
payload_id: PayloadId,
) -> Result<GetPayloadResponse<T>, Error> {
) -> Result<GetPayloadResponse<E>, Error> {
let params = json!([JsonPayloadIdRequest::from(payload_id)]);
let payload_v1: JsonExecutionPayloadV1<T> = self
let payload_v1: JsonExecutionPayloadV1<E> = self
.rpc_request(
ENGINE_GET_PAYLOAD_V1,
params,
@@ -856,16 +856,16 @@ impl HttpJsonRpc {
}))
}
pub async fn get_payload_v2<T: EthSpec>(
pub async fn get_payload_v2<E: EthSpec>(
&self,
fork_name: ForkName,
payload_id: PayloadId,
) -> Result<GetPayloadResponse<T>, Error> {
) -> Result<GetPayloadResponse<E>, Error> {
let params = json!([JsonPayloadIdRequest::from(payload_id)]);
match fork_name {
ForkName::Merge => {
let response: JsonGetPayloadResponseV1<T> = self
let response: JsonGetPayloadResponseV1<E> = self
.rpc_request(
ENGINE_GET_PAYLOAD_V2,
params,
@@ -875,7 +875,7 @@ impl HttpJsonRpc {
Ok(JsonGetPayloadResponse::V1(response).into())
}
ForkName::Capella => {
let response: JsonGetPayloadResponseV2<T> = self
let response: JsonGetPayloadResponseV2<E> = self
.rpc_request(
ENGINE_GET_PAYLOAD_V2,
params,
@@ -890,16 +890,16 @@ impl HttpJsonRpc {
}
}
pub async fn get_payload_v3<T: EthSpec>(
pub async fn get_payload_v3<E: EthSpec>(
&self,
fork_name: ForkName,
payload_id: PayloadId,
) -> Result<GetPayloadResponse<T>, Error> {
) -> Result<GetPayloadResponse<E>, Error> {
let params = json!([JsonPayloadIdRequest::from(payload_id)]);
match fork_name {
ForkName::Deneb => {
let response: JsonGetPayloadResponseV3<T> = self
let response: JsonGetPayloadResponseV3<E> = self
.rpc_request(
ENGINE_GET_PAYLOAD_V3,
params,
@@ -909,7 +909,7 @@ impl HttpJsonRpc {
Ok(JsonGetPayloadResponse::V3(response).into())
}
ForkName::Electra => {
let response: JsonGetPayloadResponseV4<T> = self
let response: JsonGetPayloadResponseV4<E> = self
.rpc_request(
ENGINE_GET_PAYLOAD_V3,
params,
@@ -1089,9 +1089,9 @@ impl HttpJsonRpc {
// automatically selects the latest version of
// new_payload that the execution engine supports
pub async fn new_payload<T: EthSpec>(
pub async fn new_payload<E: EthSpec>(
&self,
new_payload_request: NewPayloadRequest<'_, T>,
new_payload_request: NewPayloadRequest<'_, E>,
) -> Result<PayloadStatusV1, Error> {
let engine_capabilities = self.get_engine_capabilities(None).await?;
match new_payload_request {
@@ -1126,11 +1126,11 @@ impl HttpJsonRpc {
// automatically selects the latest version of
// get_payload that the execution engine supports
pub async fn get_payload<T: EthSpec>(
pub async fn get_payload<E: EthSpec>(
&self,
fork_name: ForkName,
payload_id: PayloadId,
) -> Result<GetPayloadResponse<T>, Error> {
) -> Result<GetPayloadResponse<E>, Error> {
let engine_capabilities = self.get_engine_capabilities(None).await?;
match fork_name {
ForkName::Merge | ForkName::Capella => {

View File

@@ -63,20 +63,20 @@ pub struct JsonPayloadIdResponse {
variants(V1, V2, V3, V4),
variant_attributes(
derive(Debug, PartialEq, Default, Serialize, Deserialize,),
serde(bound = "T: EthSpec", rename_all = "camelCase"),
serde(bound = "E: EthSpec", rename_all = "camelCase"),
),
cast_error(ty = "Error", expr = "Error::IncorrectStateVariant"),
partial_getter_error(ty = "Error", expr = "Error::IncorrectStateVariant")
)]
#[derive(Debug, PartialEq, Serialize, Deserialize)]
#[serde(bound = "T: EthSpec", rename_all = "camelCase", untagged)]
pub struct JsonExecutionPayload<T: EthSpec> {
#[serde(bound = "E: EthSpec", rename_all = "camelCase", untagged)]
pub struct JsonExecutionPayload<E: EthSpec> {
pub parent_hash: ExecutionBlockHash,
pub fee_recipient: Address,
pub state_root: Hash256,
pub receipts_root: Hash256,
#[serde(with = "serde_logs_bloom")]
pub logs_bloom: FixedVector<u8, T::BytesPerLogsBloom>,
pub logs_bloom: FixedVector<u8, E::BytesPerLogsBloom>,
pub prev_randao: Hash256,
#[serde(with = "serde_utils::u64_hex_be")]
pub block_number: u64,
@@ -87,14 +87,14 @@ pub struct JsonExecutionPayload<T: EthSpec> {
#[serde(with = "serde_utils::u64_hex_be")]
pub timestamp: u64,
#[serde(with = "ssz_types::serde_utils::hex_var_list")]
pub extra_data: VariableList<u8, T::MaxExtraDataBytes>,
pub extra_data: VariableList<u8, E::MaxExtraDataBytes>,
#[serde(with = "serde_utils::u256_hex_be")]
pub base_fee_per_gas: Uint256,
pub block_hash: ExecutionBlockHash,
#[serde(with = "ssz_types::serde_utils::list_of_hex_var_list")]
pub transactions: Transactions<T>,
pub transactions: Transactions<E>,
#[superstruct(only(V2, V3, V4))]
pub withdrawals: VariableList<JsonWithdrawal, T::MaxWithdrawalsPerPayload>,
pub withdrawals: VariableList<JsonWithdrawal, E::MaxWithdrawalsPerPayload>,
#[superstruct(only(V3, V4))]
#[serde(with = "serde_utils::u64_hex_be")]
pub blob_gas_used: u64,
@@ -103,8 +103,8 @@ pub struct JsonExecutionPayload<T: EthSpec> {
pub excess_blob_gas: u64,
}
impl<T: EthSpec> From<ExecutionPayloadMerge<T>> for JsonExecutionPayloadV1<T> {
fn from(payload: ExecutionPayloadMerge<T>) -> Self {
impl<E: EthSpec> From<ExecutionPayloadMerge<E>> for JsonExecutionPayloadV1<E> {
fn from(payload: ExecutionPayloadMerge<E>) -> Self {
JsonExecutionPayloadV1 {
parent_hash: payload.parent_hash,
fee_recipient: payload.fee_recipient,
@@ -123,8 +123,8 @@ impl<T: EthSpec> From<ExecutionPayloadMerge<T>> for JsonExecutionPayloadV1<T> {
}
}
}
impl<T: EthSpec> From<ExecutionPayloadCapella<T>> for JsonExecutionPayloadV2<T> {
fn from(payload: ExecutionPayloadCapella<T>) -> Self {
impl<E: EthSpec> From<ExecutionPayloadCapella<E>> for JsonExecutionPayloadV2<E> {
fn from(payload: ExecutionPayloadCapella<E>) -> Self {
JsonExecutionPayloadV2 {
parent_hash: payload.parent_hash,
fee_recipient: payload.fee_recipient,
@@ -149,8 +149,8 @@ impl<T: EthSpec> From<ExecutionPayloadCapella<T>> for JsonExecutionPayloadV2<T>
}
}
}
impl<T: EthSpec> From<ExecutionPayloadDeneb<T>> for JsonExecutionPayloadV3<T> {
fn from(payload: ExecutionPayloadDeneb<T>) -> Self {
impl<E: EthSpec> From<ExecutionPayloadDeneb<E>> for JsonExecutionPayloadV3<E> {
fn from(payload: ExecutionPayloadDeneb<E>) -> Self {
JsonExecutionPayloadV3 {
parent_hash: payload.parent_hash,
fee_recipient: payload.fee_recipient,
@@ -178,8 +178,8 @@ impl<T: EthSpec> From<ExecutionPayloadDeneb<T>> for JsonExecutionPayloadV3<T> {
}
}
impl<T: EthSpec> From<ExecutionPayloadElectra<T>> for JsonExecutionPayloadV4<T> {
fn from(payload: ExecutionPayloadElectra<T>) -> Self {
impl<E: EthSpec> From<ExecutionPayloadElectra<E>> for JsonExecutionPayloadV4<E> {
fn from(payload: ExecutionPayloadElectra<E>) -> Self {
JsonExecutionPayloadV4 {
parent_hash: payload.parent_hash,
fee_recipient: payload.fee_recipient,
@@ -207,8 +207,8 @@ impl<T: EthSpec> From<ExecutionPayloadElectra<T>> for JsonExecutionPayloadV4<T>
}
}
impl<T: EthSpec> From<ExecutionPayload<T>> for JsonExecutionPayload<T> {
fn from(execution_payload: ExecutionPayload<T>) -> Self {
impl<E: EthSpec> From<ExecutionPayload<E>> for JsonExecutionPayload<E> {
fn from(execution_payload: ExecutionPayload<E>) -> Self {
match execution_payload {
ExecutionPayload::Merge(payload) => JsonExecutionPayload::V1(payload.into()),
ExecutionPayload::Capella(payload) => JsonExecutionPayload::V2(payload.into()),
@@ -218,8 +218,8 @@ impl<T: EthSpec> From<ExecutionPayload<T>> for JsonExecutionPayload<T> {
}
}
impl<T: EthSpec> From<JsonExecutionPayloadV1<T>> for ExecutionPayloadMerge<T> {
fn from(payload: JsonExecutionPayloadV1<T>) -> Self {
impl<E: EthSpec> From<JsonExecutionPayloadV1<E>> for ExecutionPayloadMerge<E> {
fn from(payload: JsonExecutionPayloadV1<E>) -> Self {
ExecutionPayloadMerge {
parent_hash: payload.parent_hash,
fee_recipient: payload.fee_recipient,
@@ -238,8 +238,8 @@ impl<T: EthSpec> From<JsonExecutionPayloadV1<T>> for ExecutionPayloadMerge<T> {
}
}
}
impl<T: EthSpec> From<JsonExecutionPayloadV2<T>> for ExecutionPayloadCapella<T> {
fn from(payload: JsonExecutionPayloadV2<T>) -> Self {
impl<E: EthSpec> From<JsonExecutionPayloadV2<E>> for ExecutionPayloadCapella<E> {
fn from(payload: JsonExecutionPayloadV2<E>) -> Self {
ExecutionPayloadCapella {
parent_hash: payload.parent_hash,
fee_recipient: payload.fee_recipient,
@@ -265,8 +265,8 @@ impl<T: EthSpec> From<JsonExecutionPayloadV2<T>> for ExecutionPayloadCapella<T>
}
}
impl<T: EthSpec> From<JsonExecutionPayloadV3<T>> for ExecutionPayloadDeneb<T> {
fn from(payload: JsonExecutionPayloadV3<T>) -> Self {
impl<E: EthSpec> From<JsonExecutionPayloadV3<E>> for ExecutionPayloadDeneb<E> {
fn from(payload: JsonExecutionPayloadV3<E>) -> Self {
ExecutionPayloadDeneb {
parent_hash: payload.parent_hash,
fee_recipient: payload.fee_recipient,
@@ -294,8 +294,8 @@ impl<T: EthSpec> From<JsonExecutionPayloadV3<T>> for ExecutionPayloadDeneb<T> {
}
}
impl<T: EthSpec> From<JsonExecutionPayloadV4<T>> for ExecutionPayloadElectra<T> {
fn from(payload: JsonExecutionPayloadV4<T>) -> Self {
impl<E: EthSpec> From<JsonExecutionPayloadV4<E>> for ExecutionPayloadElectra<E> {
fn from(payload: JsonExecutionPayloadV4<E>) -> Self {
ExecutionPayloadElectra {
parent_hash: payload.parent_hash,
fee_recipient: payload.fee_recipient,
@@ -323,8 +323,8 @@ impl<T: EthSpec> From<JsonExecutionPayloadV4<T>> for ExecutionPayloadElectra<T>
}
}
impl<T: EthSpec> From<JsonExecutionPayload<T>> for ExecutionPayload<T> {
fn from(json_execution_payload: JsonExecutionPayload<T>) -> Self {
impl<E: EthSpec> From<JsonExecutionPayload<E>> for ExecutionPayload<E> {
fn from(json_execution_payload: JsonExecutionPayload<E>) -> Self {
match json_execution_payload {
JsonExecutionPayload::V1(payload) => ExecutionPayload::Merge(payload.into()),
JsonExecutionPayload::V2(payload) => ExecutionPayload::Capella(payload.into()),
@@ -338,32 +338,32 @@ impl<T: EthSpec> From<JsonExecutionPayload<T>> for ExecutionPayload<T> {
variants(V1, V2, V3, V4),
variant_attributes(
derive(Debug, PartialEq, Serialize, Deserialize),
serde(bound = "T: EthSpec", rename_all = "camelCase")
serde(bound = "E: EthSpec", rename_all = "camelCase")
),
cast_error(ty = "Error", expr = "Error::IncorrectStateVariant"),
partial_getter_error(ty = "Error", expr = "Error::IncorrectStateVariant")
)]
#[derive(Debug, PartialEq, Serialize, Deserialize)]
#[serde(untagged)]
pub struct JsonGetPayloadResponse<T: EthSpec> {
pub struct JsonGetPayloadResponse<E: EthSpec> {
#[superstruct(only(V1), partial_getter(rename = "execution_payload_v1"))]
pub execution_payload: JsonExecutionPayloadV1<T>,
pub execution_payload: JsonExecutionPayloadV1<E>,
#[superstruct(only(V2), partial_getter(rename = "execution_payload_v2"))]
pub execution_payload: JsonExecutionPayloadV2<T>,
pub execution_payload: JsonExecutionPayloadV2<E>,
#[superstruct(only(V3), partial_getter(rename = "execution_payload_v3"))]
pub execution_payload: JsonExecutionPayloadV3<T>,
pub execution_payload: JsonExecutionPayloadV3<E>,
#[superstruct(only(V4), partial_getter(rename = "execution_payload_v4"))]
pub execution_payload: JsonExecutionPayloadV4<T>,
pub execution_payload: JsonExecutionPayloadV4<E>,
#[serde(with = "serde_utils::u256_hex_be")]
pub block_value: Uint256,
#[superstruct(only(V3, V4))]
pub blobs_bundle: JsonBlobsBundleV1<T>,
pub blobs_bundle: JsonBlobsBundleV1<E>,
#[superstruct(only(V3, V4))]
pub should_override_builder: bool,
}
impl<T: EthSpec> From<JsonGetPayloadResponse<T>> for GetPayloadResponse<T> {
fn from(json_get_payload_response: JsonGetPayloadResponse<T>) -> Self {
impl<E: EthSpec> From<JsonGetPayloadResponse<E>> for GetPayloadResponse<E> {
fn from(json_get_payload_response: JsonGetPayloadResponse<E>) -> Self {
match json_get_payload_response {
JsonGetPayloadResponse::V1(response) => {
GetPayloadResponse::Merge(GetPayloadResponseMerge {

View File

@@ -170,7 +170,7 @@ pub enum BlockProposalContentsType<E: EthSpec> {
Blinded(BlockProposalContents<E, BlindedPayload<E>>),
}
pub enum BlockProposalContents<T: EthSpec, Payload: AbstractExecPayload<T>> {
pub enum BlockProposalContents<E: EthSpec, Payload: AbstractExecPayload<E>> {
Payload {
payload: Payload,
block_value: Uint256,
@@ -178,16 +178,16 @@ pub enum BlockProposalContents<T: EthSpec, Payload: AbstractExecPayload<T>> {
PayloadAndBlobs {
payload: Payload,
block_value: Uint256,
kzg_commitments: KzgCommitments<T>,
kzg_commitments: KzgCommitments<E>,
/// `None` for blinded `PayloadAndBlobs`.
blobs_and_proofs: Option<(BlobsList<T>, KzgProofs<T>)>,
blobs_and_proofs: Option<(BlobsList<E>, KzgProofs<E>)>,
},
}
impl<T: EthSpec> From<BlockProposalContents<T, FullPayload<T>>>
for BlockProposalContents<T, BlindedPayload<T>>
impl<E: EthSpec> From<BlockProposalContents<E, FullPayload<E>>>
for BlockProposalContents<E, BlindedPayload<E>>
{
fn from(item: BlockProposalContents<T, FullPayload<T>>) -> Self {
fn from(item: BlockProposalContents<E, FullPayload<E>>) -> Self {
match item {
BlockProposalContents::Payload {
payload,
@@ -245,13 +245,13 @@ impl<E: EthSpec> TryFrom<GetPayloadResponseType<E>> for BlockProposalContentsTyp
}
#[allow(clippy::type_complexity)]
impl<T: EthSpec, Payload: AbstractExecPayload<T>> BlockProposalContents<T, Payload> {
impl<E: EthSpec, Payload: AbstractExecPayload<E>> BlockProposalContents<E, Payload> {
pub fn deconstruct(
self,
) -> (
Payload,
Option<KzgCommitments<T>>,
Option<(BlobsList<T>, KzgProofs<T>)>,
Option<KzgCommitments<E>>,
Option<(BlobsList<E>, KzgProofs<E>)>,
Uint256,
) {
match self {
@@ -333,7 +333,7 @@ pub enum FailedCondition {
EpochsSinceFinalization,
}
type PayloadContentsRefTuple<'a, T> = (ExecutionPayloadRef<'a, T>, Option<&'a BlobsBundle<T>>);
type PayloadContentsRefTuple<'a, E> = (ExecutionPayloadRef<'a, E>, Option<&'a BlobsBundle<E>>);
struct Inner<E: EthSpec> {
engine: Arc<Engine>,
@@ -378,11 +378,11 @@ pub struct Config {
/// Provides access to one execution engine and provides a neat interface for consumption by the
/// `BeaconChain`.
#[derive(Clone)]
pub struct ExecutionLayer<T: EthSpec> {
inner: Arc<Inner<T>>,
pub struct ExecutionLayer<E: EthSpec> {
inner: Arc<Inner<E>>,
}
impl<T: EthSpec> ExecutionLayer<T> {
impl<E: EthSpec> ExecutionLayer<E> {
/// Instantiate `Self` with an Execution engine specified in `Config`, using JSON-RPC via HTTP.
pub fn from_config(config: Config, executor: TaskExecutor, log: Logger) -> Result<Self, Error> {
let Config {
@@ -502,8 +502,8 @@ impl<T: EthSpec> ExecutionLayer<T> {
/// Cache a full payload, keyed on the `tree_hash_root` of the payload
fn cache_payload(
&self,
payload_and_blobs: PayloadContentsRefTuple<T>,
) -> Option<FullPayloadContents<T>> {
payload_and_blobs: PayloadContentsRefTuple<E>,
) -> Option<FullPayloadContents<E>> {
let (payload_ref, maybe_json_blobs_bundle) = payload_and_blobs;
let payload = payload_ref.clone_from_ref();
@@ -521,7 +521,7 @@ impl<T: EthSpec> ExecutionLayer<T> {
}
/// Attempt to retrieve a full payload from the payload cache by the payload root
pub fn get_payload_by_root(&self, root: &Hash256) -> Option<FullPayloadContents<T>> {
pub fn get_payload_by_root(&self, root: &Hash256) -> Option<FullPayloadContents<E>> {
self.inner.payload_cache.get(root)
}
@@ -583,7 +583,7 @@ impl<T: EthSpec> ExecutionLayer<T> {
/// Spawns a routine which attempts to keep the execution engine online.
pub fn spawn_watchdog_routine<S: SlotClock + 'static>(&self, slot_clock: S) {
let watchdog = |el: ExecutionLayer<T>| async move {
let watchdog = |el: ExecutionLayer<E>| async move {
// Run one task immediately.
el.watchdog_task().await;
@@ -607,18 +607,18 @@ impl<T: EthSpec> ExecutionLayer<T> {
/// Spawns a routine which cleans the cached proposer data periodically.
pub fn spawn_clean_proposer_caches_routine<S: SlotClock + 'static>(&self, slot_clock: S) {
let preparation_cleaner = |el: ExecutionLayer<T>| async move {
let preparation_cleaner = |el: ExecutionLayer<E>| async move {
// Start the loop to periodically clean proposer preparation cache.
loop {
if let Some(duration_to_next_epoch) =
slot_clock.duration_to_next_epoch(T::slots_per_epoch())
slot_clock.duration_to_next_epoch(E::slots_per_epoch())
{
// Wait for next epoch
sleep(duration_to_next_epoch).await;
match slot_clock
.now()
.map(|slot| slot.epoch(T::slots_per_epoch()))
.map(|slot| slot.epoch(E::slots_per_epoch()))
{
Some(current_epoch) => el
.clean_proposer_caches(current_epoch)
@@ -721,7 +721,7 @@ impl<T: EthSpec> ExecutionLayer<T> {
});
drop(proposer_preparation_data);
let retain_slot = retain_epoch.start_slot(T::slots_per_epoch());
let retain_slot = retain_epoch.start_slot(E::slots_per_epoch());
self.proposers()
.write()
.await
@@ -800,7 +800,7 @@ impl<T: EthSpec> ExecutionLayer<T> {
spec: &ChainSpec,
builder_boost_factor: Option<u64>,
block_production_version: BlockProductionVersion,
) -> Result<BlockProposalContentsType<T>, Error> {
) -> Result<BlockProposalContentsType<E>, Error> {
let payload_result_type = match block_production_version {
BlockProductionVersion::V3 => match self
.determine_and_fetch_payload(
@@ -899,8 +899,8 @@ impl<T: EthSpec> ExecutionLayer<T> {
forkchoice_update_params: ForkchoiceUpdateParameters,
current_fork: ForkName,
) -> (
Result<Option<ForkVersionedResponse<SignedBuilderBid<T>>>, builder_client::Error>,
Result<GetPayloadResponse<T>, Error>,
Result<Option<ForkVersionedResponse<SignedBuilderBid<E>>>, builder_client::Error>,
Result<GetPayloadResponse<E>, Error>,
) {
let slot = builder_params.slot;
let pubkey = &builder_params.pubkey;
@@ -917,7 +917,7 @@ impl<T: EthSpec> ExecutionLayer<T> {
let ((relay_result, relay_duration), (local_result, local_duration)) = tokio::join!(
timed_future(metrics::GET_BLINDED_PAYLOAD_BUILDER, async {
builder
.get_builder_header::<T>(slot, parent_hash, pubkey)
.get_builder_header::<E>(slot, parent_hash, pubkey)
.await
}),
timed_future(metrics::GET_BLINDED_PAYLOAD_LOCAL, async {
@@ -965,7 +965,7 @@ impl<T: EthSpec> ExecutionLayer<T> {
current_fork: ForkName,
builder_boost_factor: Option<u64>,
spec: &ChainSpec,
) -> Result<ProvenancedPayload<BlockProposalContentsType<T>>, Error> {
) -> Result<ProvenancedPayload<BlockProposalContentsType<E>>, Error> {
let Some(builder) = self.builder() else {
// no builder.. return local payload
return self
@@ -1210,7 +1210,7 @@ impl<T: EthSpec> ExecutionLayer<T> {
payload_attributes: &PayloadAttributes,
forkchoice_update_params: ForkchoiceUpdateParameters,
current_fork: ForkName,
) -> Result<GetPayloadResponseType<T>, Error> {
) -> Result<GetPayloadResponseType<E>, Error> {
self.get_full_payload_with(
parent_hash,
payload_attributes,
@@ -1228,10 +1228,10 @@ impl<T: EthSpec> ExecutionLayer<T> {
forkchoice_update_params: ForkchoiceUpdateParameters,
current_fork: ForkName,
cache_fn: fn(
&ExecutionLayer<T>,
PayloadContentsRefTuple<T>,
) -> Option<FullPayloadContents<T>>,
) -> Result<GetPayloadResponseType<T>, Error> {
&ExecutionLayer<E>,
PayloadContentsRefTuple<E>,
) -> Option<FullPayloadContents<E>>,
) -> Result<GetPayloadResponseType<E>, Error> {
self.engine()
.request(move |engine| async move {
let payload_id = if let Some(id) = engine
@@ -1297,7 +1297,7 @@ impl<T: EthSpec> ExecutionLayer<T> {
&metrics::EXECUTION_LAYER_REQUEST_TIMES,
&[metrics::GET_PAYLOAD],
);
engine.api.get_payload::<T>(current_fork, payload_id).await
engine.api.get_payload::<E>(current_fork, payload_id).await
}.await?;
if payload_response.execution_payload_ref().fee_recipient() != payload_attributes.suggested_fee_recipient() {
@@ -1331,7 +1331,7 @@ impl<T: EthSpec> ExecutionLayer<T> {
/// Maps to the `engine_newPayload` JSON-RPC call.
pub async fn notify_new_payload(
&self,
new_payload_request: NewPayloadRequest<'_, T>,
new_payload_request: NewPayloadRequest<'_, E>,
) -> Result<PayloadStatus, Error> {
let _timer = metrics::start_timer_vec(
&metrics::EXECUTION_LAYER_REQUEST_TIMES,
@@ -1733,7 +1733,7 @@ impl<T: EthSpec> ExecutionLayer<T> {
pub async fn get_payload_bodies_by_hash(
&self,
hashes: Vec<ExecutionBlockHash>,
) -> Result<Vec<Option<ExecutionPayloadBodyV1<T>>>, Error> {
) -> Result<Vec<Option<ExecutionPayloadBodyV1<E>>>, Error> {
self.engine()
.request(|engine: &Engine| async move {
engine.api.get_payload_bodies_by_hash_v1(hashes).await
@@ -1747,7 +1747,7 @@ impl<T: EthSpec> ExecutionLayer<T> {
&self,
start: u64,
count: u64,
) -> Result<Vec<Option<ExecutionPayloadBodyV1<T>>>, Error> {
) -> Result<Vec<Option<ExecutionPayloadBodyV1<E>>>, Error> {
let _timer = metrics::start_timer(&metrics::EXECUTION_LAYER_GET_PAYLOAD_BODIES_BY_RANGE);
self.engine()
.request(|engine: &Engine| async move {
@@ -1766,9 +1766,9 @@ impl<T: EthSpec> ExecutionLayer<T> {
/// This will fail if the payload is not from the finalized portion of the chain.
pub async fn get_payload_for_header(
&self,
header: &ExecutionPayloadHeader<T>,
header: &ExecutionPayloadHeader<E>,
fork: ForkName,
) -> Result<Option<ExecutionPayload<T>>, Error> {
) -> Result<Option<ExecutionPayload<E>>, Error> {
let hash = header.block_hash();
let block_number = header.block_number();
@@ -1823,7 +1823,7 @@ impl<T: EthSpec> ExecutionLayer<T> {
&self,
hash: ExecutionBlockHash,
fork: ForkName,
) -> Result<Option<ExecutionPayload<T>>, Error> {
) -> Result<Option<ExecutionPayload<E>>, Error> {
self.engine()
.request(|engine| async move {
self.get_payload_by_hash_from_engine(engine, hash, fork)
@@ -1839,7 +1839,7 @@ impl<T: EthSpec> ExecutionLayer<T> {
engine: &Engine,
hash: ExecutionBlockHash,
fork: ForkName,
) -> Result<Option<ExecutionPayload<T>>, ApiError> {
) -> Result<Option<ExecutionPayload<E>>, ApiError> {
let _timer = metrics::start_timer(&metrics::EXECUTION_LAYER_GET_PAYLOAD_BY_BLOCK_HASH);
if hash == ExecutionBlockHash::zero() {
@@ -1856,7 +1856,7 @@ impl<T: EthSpec> ExecutionLayer<T> {
let Some(block) = engine
.api
.get_block_by_hash_with_txns::<T>(hash, fork)
.get_block_by_hash_with_txns::<E>(hash, fork)
.await?
else {
return Ok(None);
@@ -1984,8 +1984,8 @@ impl<T: EthSpec> ExecutionLayer<T> {
pub async fn propose_blinded_beacon_block(
&self,
block_root: Hash256,
block: &SignedBlindedBeaconBlock<T>,
) -> Result<FullPayloadContents<T>, Error> {
block: &SignedBlindedBeaconBlock<E>,
) -> Result<FullPayloadContents<E>, Error> {
debug!(
self.log(),
"Sending block to builder";
@@ -2122,8 +2122,8 @@ impl fmt::Display for InvalidBuilderPayload {
}
/// Perform some cursory, non-exhaustive validation of the bid returned from the builder.
fn verify_builder_bid<T: EthSpec>(
bid: &ForkVersionedResponse<SignedBuilderBid<T>>,
fn verify_builder_bid<E: EthSpec>(
bid: &ForkVersionedResponse<SignedBuilderBid<E>>,
parent_hash: ExecutionBlockHash,
payload_attributes: &PayloadAttributes,
block_number: Option<u64>,
@@ -2147,7 +2147,7 @@ fn verify_builder_bid<T: EthSpec>(
.withdrawals()
.ok()
.cloned()
.map(|withdrawals| Withdrawals::<T>::from(withdrawals).tree_hash_root());
.map(|withdrawals| Withdrawals::<E>::from(withdrawals).tree_hash_root());
let payload_withdrawals_root = header.withdrawals_root().ok().copied();
if header.parent_hash() != parent_hash {
@@ -2208,10 +2208,10 @@ fn timestamp_now() -> u64 {
.as_secs()
}
fn noop<T: EthSpec>(
_: &ExecutionLayer<T>,
_: PayloadContentsRefTuple<T>,
) -> Option<FullPayloadContents<T>> {
fn noop<E: EthSpec>(
_: &ExecutionLayer<E>,
_: PayloadContentsRefTuple<E>,
) -> Option<FullPayloadContents<E>> {
None
}

View File

@@ -9,14 +9,14 @@ use types::{EthSpec, Hash256};
pub const DEFAULT_PAYLOAD_CACHE_SIZE: NonZeroUsize = new_non_zero_usize(10);
/// A cache mapping execution payloads by tree hash roots.
pub struct PayloadCache<T: EthSpec> {
payloads: Mutex<LruCache<PayloadCacheId, FullPayloadContents<T>>>,
pub struct PayloadCache<E: EthSpec> {
payloads: Mutex<LruCache<PayloadCacheId, FullPayloadContents<E>>>,
}
#[derive(Hash, PartialEq, Eq)]
struct PayloadCacheId(Hash256);
impl<T: EthSpec> Default for PayloadCache<T> {
impl<E: EthSpec> Default for PayloadCache<E> {
fn default() -> Self {
PayloadCache {
payloads: Mutex::new(LruCache::new(DEFAULT_PAYLOAD_CACHE_SIZE)),
@@ -24,17 +24,17 @@ impl<T: EthSpec> Default for PayloadCache<T> {
}
}
impl<T: EthSpec> PayloadCache<T> {
pub fn put(&self, payload: FullPayloadContents<T>) -> Option<FullPayloadContents<T>> {
impl<E: EthSpec> PayloadCache<E> {
pub fn put(&self, payload: FullPayloadContents<E>) -> Option<FullPayloadContents<E>> {
let root = payload.payload_ref().tree_hash_root();
self.payloads.lock().put(PayloadCacheId(root), payload)
}
pub fn pop(&self, root: &Hash256) -> Option<FullPayloadContents<T>> {
pub fn pop(&self, root: &Hash256) -> Option<FullPayloadContents<E>> {
self.payloads.lock().pop(&PayloadCacheId(*root))
}
pub fn get(&self, hash: &Hash256) -> Option<FullPayloadContents<T>> {
pub fn get(&self, hash: &Hash256) -> Option<FullPayloadContents<E>> {
self.payloads.lock().get(&PayloadCacheId(*hash)).cloned()
}
}

View File

@@ -35,12 +35,12 @@ const GAS_USED: u64 = GAS_LIMIT - 1;
#[derive(Clone, Debug, PartialEq)]
#[allow(clippy::large_enum_variant)] // This struct is only for testing.
pub enum Block<T: EthSpec> {
pub enum Block<E: EthSpec> {
PoW(PoWBlock),
PoS(ExecutionPayload<T>),
PoS(ExecutionPayload<E>),
}
impl<T: EthSpec> Block<T> {
impl<E: EthSpec> Block<E> {
pub fn block_number(&self) -> u64 {
match self {
Block::PoW(block) => block.block_number,
@@ -88,7 +88,7 @@ impl<T: EthSpec> Block<T> {
}
}
pub fn as_execution_block_with_tx(&self) -> Option<ExecutionBlockWithTransactions<T>> {
pub fn as_execution_block_with_tx(&self) -> Option<ExecutionBlockWithTransactions<E>> {
match self {
Block::PoS(payload) => Some(payload.clone().try_into().unwrap()),
Block::PoW(_) => None,
@@ -107,13 +107,13 @@ pub struct PoWBlock {
}
#[derive(Debug, Clone)]
pub struct ExecutionBlockGenerator<T: EthSpec> {
pub struct ExecutionBlockGenerator<E: EthSpec> {
/*
* Common database
*/
head_block: Option<Block<T>>,
head_block: Option<Block<E>>,
finalized_block_hash: Option<ExecutionBlockHash>,
blocks: HashMap<ExecutionBlockHash, Block<T>>,
blocks: HashMap<ExecutionBlockHash, Block<E>>,
block_hashes: HashMap<u64, Vec<ExecutionBlockHash>>,
/*
* PoW block parameters
@@ -124,9 +124,9 @@ pub struct ExecutionBlockGenerator<T: EthSpec> {
/*
* PoS block parameters
*/
pub pending_payloads: HashMap<ExecutionBlockHash, ExecutionPayload<T>>,
pub pending_payloads: HashMap<ExecutionBlockHash, ExecutionPayload<E>>,
pub next_payload_id: u64,
pub payload_ids: HashMap<PayloadId, ExecutionPayload<T>>,
pub payload_ids: HashMap<PayloadId, ExecutionPayload<E>>,
/*
* Post-merge fork triggers
*/
@@ -136,7 +136,7 @@ pub struct ExecutionBlockGenerator<T: EthSpec> {
/*
* deneb stuff
*/
pub blobs_bundles: HashMap<PayloadId, BlobsBundle<T>>,
pub blobs_bundles: HashMap<PayloadId, BlobsBundle<E>>,
pub kzg: Option<Arc<Kzg>>,
rng: Arc<Mutex<StdRng>>,
}
@@ -147,7 +147,7 @@ fn make_rng() -> Arc<Mutex<StdRng>> {
Arc::new(Mutex::new(StdRng::seed_from_u64(0xDEADBEEF0BAD5EEDu64)))
}
impl<T: EthSpec> ExecutionBlockGenerator<T> {
impl<E: EthSpec> ExecutionBlockGenerator<E> {
pub fn new(
terminal_total_difficulty: Uint256,
terminal_block_number: u64,
@@ -181,7 +181,7 @@ impl<T: EthSpec> ExecutionBlockGenerator<T> {
gen
}
pub fn latest_block(&self) -> Option<Block<T>> {
pub fn latest_block(&self) -> Option<Block<E>> {
self.head_block.clone()
}
@@ -190,7 +190,7 @@ impl<T: EthSpec> ExecutionBlockGenerator<T> {
.map(|block| block.as_execution_block(self.terminal_total_difficulty))
}
pub fn block_by_number(&self, number: u64) -> Option<Block<T>> {
pub fn block_by_number(&self, number: u64) -> Option<Block<E>> {
// Get the latest canonical head block
let mut latest_block = self.latest_block()?;
loop {
@@ -223,7 +223,7 @@ impl<T: EthSpec> ExecutionBlockGenerator<T> {
.map(|block| block.as_execution_block(self.terminal_total_difficulty))
}
pub fn block_by_hash(&self, hash: ExecutionBlockHash) -> Option<Block<T>> {
pub fn block_by_hash(&self, hash: ExecutionBlockHash) -> Option<Block<E>> {
self.blocks.get(&hash).cloned()
}
@@ -235,7 +235,7 @@ impl<T: EthSpec> ExecutionBlockGenerator<T> {
pub fn execution_block_with_txs_by_hash(
&self,
hash: ExecutionBlockHash,
) -> Option<ExecutionBlockWithTransactions<T>> {
) -> Option<ExecutionBlockWithTransactions<E>> {
self.block_by_hash(hash)
.and_then(|block| block.as_execution_block_with_tx())
}
@@ -243,7 +243,7 @@ impl<T: EthSpec> ExecutionBlockGenerator<T> {
pub fn execution_block_with_txs_by_number(
&self,
number: u64,
) -> Option<ExecutionBlockWithTransactions<T>> {
) -> Option<ExecutionBlockWithTransactions<E>> {
self.block_by_number(number)
.and_then(|block| block.as_execution_block_with_tx())
}
@@ -368,7 +368,7 @@ impl<T: EthSpec> ExecutionBlockGenerator<T> {
// This does not reject duplicate blocks inserted. This lets us re-use the same execution
// block generator for multiple beacon chains which is useful in testing.
pub fn insert_block(&mut self, block: Block<T>) -> Result<ExecutionBlockHash, String> {
pub fn insert_block(&mut self, block: Block<E>) -> Result<ExecutionBlockHash, String> {
if block.parent_hash() != ExecutionBlockHash::zero()
&& !self.blocks.contains_key(&block.parent_hash())
{
@@ -378,7 +378,7 @@ impl<T: EthSpec> ExecutionBlockGenerator<T> {
Ok(self.insert_block_without_checks(block))
}
pub fn insert_block_without_checks(&mut self, block: Block<T>) -> ExecutionBlockHash {
pub fn insert_block_without_checks(&mut self, block: Block<E>) -> ExecutionBlockHash {
let block_hash = block.block_hash();
self.block_hashes
.entry(block.block_number())
@@ -389,7 +389,7 @@ impl<T: EthSpec> ExecutionBlockGenerator<T> {
block_hash
}
pub fn modify_last_block(&mut self, block_modifier: impl FnOnce(&mut Block<T>)) {
pub fn modify_last_block(&mut self, block_modifier: impl FnOnce(&mut Block<E>)) {
if let Some(last_block_hash) = self
.block_hashes
.iter_mut()
@@ -423,15 +423,15 @@ impl<T: EthSpec> ExecutionBlockGenerator<T> {
}
}
pub fn get_payload(&mut self, id: &PayloadId) -> Option<ExecutionPayload<T>> {
pub fn get_payload(&mut self, id: &PayloadId) -> Option<ExecutionPayload<E>> {
self.payload_ids.get(id).cloned()
}
pub fn get_blobs_bundle(&mut self, id: &PayloadId) -> Option<BlobsBundle<T>> {
pub fn get_blobs_bundle(&mut self, id: &PayloadId) -> Option<BlobsBundle<E>> {
self.blobs_bundles.get(id).cloned()
}
pub fn new_payload(&mut self, payload: ExecutionPayload<T>) -> PayloadStatusV1 {
pub fn new_payload(&mut self, payload: ExecutionPayload<E>) -> PayloadStatusV1 {
let Some(parent) = self.blocks.get(&payload.parent_hash()) else {
return PayloadStatusV1 {
status: PayloadStatusV1Status::Syncing,
@@ -551,10 +551,10 @@ impl<T: EthSpec> ExecutionBlockGenerator<T> {
pub fn build_new_execution_payload(
&mut self,
head_block_hash: ExecutionBlockHash,
parent: &Block<T>,
parent: &Block<E>,
id: PayloadId,
attributes: &PayloadAttributes,
) -> Result<ExecutionPayload<T>, String> {
) -> Result<ExecutionPayload<E>, String> {
let mut execution_payload = match attributes {
PayloadAttributes::V1(pa) => ExecutionPayload::Merge(ExecutionPayloadMerge {
parent_hash: head_block_hash,
@@ -656,7 +656,7 @@ impl<T: EthSpec> ExecutionBlockGenerator<T> {
ForkName::Deneb | ForkName::Electra => {
// get random number between 0 and Max Blobs
let mut rng = self.rng.lock();
let num_blobs = rng.gen::<usize>() % (T::max_blobs_per_block() + 1);
let num_blobs = rng.gen::<usize>() % (E::max_blobs_per_block() + 1);
let (bundle, transactions) = generate_blobs(num_blobs)?;
for tx in Vec::from(transactions) {
execution_payload
@@ -728,7 +728,7 @@ pub fn generate_blobs<E: EthSpec>(
Ok((bundle, transactions.into()))
}
pub fn static_valid_tx<T: EthSpec>() -> Result<Transaction<T::MaxBytesPerTransaction>, String> {
pub fn static_valid_tx<E: EthSpec>() -> Result<Transaction<E::MaxBytesPerTransaction>, String> {
// This is a real transaction hex encoded, but we don't care about the contents of the transaction.
let transaction: EthersTransaction = serde_json::from_str(
r#"{
@@ -757,11 +757,11 @@ fn payload_id_from_u64(n: u64) -> PayloadId {
n.to_le_bytes()
}
pub fn generate_genesis_header<T: EthSpec>(
pub fn generate_genesis_header<E: EthSpec>(
spec: &ChainSpec,
post_transition_merge: bool,
) -> Option<ExecutionPayloadHeader<T>> {
let genesis_fork = spec.fork_name_at_slot::<T>(spec.genesis_slot);
) -> Option<ExecutionPayloadHeader<E>> {
let genesis_fork = spec.fork_name_at_slot::<E>(spec.genesis_slot);
let genesis_block_hash =
generate_genesis_block(spec.terminal_total_difficulty, DEFAULT_TERMINAL_BLOCK)
.ok()
@@ -774,7 +774,7 @@ pub fn generate_genesis_header<T: EthSpec>(
*header.block_hash_mut() = genesis_block_hash.unwrap_or_default();
Some(header)
} else {
Some(ExecutionPayloadHeader::<T>::Merge(<_>::default()))
Some(ExecutionPayloadHeader::<E>::Merge(<_>::default()))
}
}
ForkName::Capella => {

View File

@@ -11,9 +11,9 @@ pub const BAD_PARAMS_ERROR_CODE: i64 = -32602;
pub const UNKNOWN_PAYLOAD_ERROR_CODE: i64 = -38001;
pub const FORK_REQUEST_MISMATCH_ERROR_CODE: i64 = -32000;
pub async fn handle_rpc<T: EthSpec>(
pub async fn handle_rpc<E: EthSpec>(
body: JsonValue,
ctx: Arc<Context<T>>,
ctx: Arc<Context<E>>,
) -> Result<JsonValue, (String, i64)> {
*ctx.previous_request.lock() = Some(body.clone());
@@ -95,26 +95,26 @@ pub async fn handle_rpc<T: EthSpec>(
ENGINE_NEW_PAYLOAD_V1 | ENGINE_NEW_PAYLOAD_V2 | ENGINE_NEW_PAYLOAD_V3 => {
let request = match method {
ENGINE_NEW_PAYLOAD_V1 => JsonExecutionPayload::V1(
get_param::<JsonExecutionPayloadV1<T>>(params, 0)
get_param::<JsonExecutionPayloadV1<E>>(params, 0)
.map_err(|s| (s, BAD_PARAMS_ERROR_CODE))?,
),
ENGINE_NEW_PAYLOAD_V2 => get_param::<JsonExecutionPayloadV2<T>>(params, 0)
ENGINE_NEW_PAYLOAD_V2 => get_param::<JsonExecutionPayloadV2<E>>(params, 0)
.map(|jep| JsonExecutionPayload::V2(jep))
.or_else(|_| {
get_param::<JsonExecutionPayloadV1<T>>(params, 0)
get_param::<JsonExecutionPayloadV1<E>>(params, 0)
.map(|jep| JsonExecutionPayload::V1(jep))
})
.map_err(|s| (s, BAD_PARAMS_ERROR_CODE))?,
ENGINE_NEW_PAYLOAD_V3 => get_param::<JsonExecutionPayloadV4<T>>(params, 0)
ENGINE_NEW_PAYLOAD_V3 => get_param::<JsonExecutionPayloadV4<E>>(params, 0)
.map(|jep| JsonExecutionPayload::V4(jep))
.or_else(|_| {
get_param::<JsonExecutionPayloadV3<T>>(params, 0)
get_param::<JsonExecutionPayloadV3<E>>(params, 0)
.map(|jep| JsonExecutionPayload::V3(jep))
.or_else(|_| {
get_param::<JsonExecutionPayloadV2<T>>(params, 0)
get_param::<JsonExecutionPayloadV2<E>>(params, 0)
.map(|jep| JsonExecutionPayload::V2(jep))
.or_else(|_| {
get_param::<JsonExecutionPayloadV1<T>>(params, 0)
get_param::<JsonExecutionPayloadV1<E>>(params, 0)
.map(|jep| JsonExecutionPayload::V1(jep))
})
})
@@ -543,7 +543,7 @@ pub async fn handle_rpc<T: EthSpec>(
match maybe_block {
Some(block) => {
let transactions = Transactions::<T>::new(
let transactions = Transactions::<E>::new(
block
.transactions()
.iter()
@@ -563,7 +563,7 @@ pub async fn handle_rpc<T: EthSpec>(
)
})?;
response.push(Some(JsonExecutionPayloadBodyV1::<T> {
response.push(Some(JsonExecutionPayloadBodyV1::<E> {
transactions,
withdrawals: block
.withdrawals()

View File

@@ -9,14 +9,14 @@ use kzg::Kzg;
use tempfile::NamedTempFile;
use types::MainnetEthSpec;
pub struct MockExecutionLayer<T: EthSpec> {
pub server: MockServer<T>,
pub el: ExecutionLayer<T>,
pub struct MockExecutionLayer<E: EthSpec> {
pub server: MockServer<E>,
pub el: ExecutionLayer<E>,
pub executor: TaskExecutor,
pub spec: ChainSpec,
}
impl<T: EthSpec> MockExecutionLayer<T> {
impl<E: EthSpec> MockExecutionLayer<E> {
pub fn default_params(executor: TaskExecutor) -> Self {
let mut spec = MainnetEthSpec::default_spec();
spec.terminal_total_difficulty = DEFAULT_TERMINAL_DIFFICULTY.into();
@@ -146,7 +146,7 @@ impl<T: EthSpec> MockExecutionLayer<T> {
.await
.unwrap();
let payload: ExecutionPayload<T> = match block_proposal_content_type {
let payload: ExecutionPayload<E> = match block_proposal_content_type {
BlockProposalContentsType::Full(block) => block.to_payload().into(),
BlockProposalContentsType::Blinded(_) => panic!("Should always be a full payload"),
};
@@ -219,9 +219,9 @@ impl<T: EthSpec> MockExecutionLayer<T> {
}
#[allow(clippy::too_many_arguments)]
pub async fn assert_valid_execution_payload_on_head<Payload: AbstractExecPayload<T>>(
pub async fn assert_valid_execution_payload_on_head<Payload: AbstractExecPayload<E>>(
&self,
payload: ExecutionPayload<T>,
payload: ExecutionPayload<E>,
payload_header: Payload,
block_hash: ExecutionBlockHash,
parent_hash: ExecutionBlockHash,
@@ -307,7 +307,7 @@ impl<T: EthSpec> MockExecutionLayer<T> {
pub async fn with_terminal_block<'a, U, V>(self, func: U) -> Self
where
U: Fn(ChainSpec, ExecutionLayer<T>, Option<ExecutionBlock>) -> V,
U: Fn(ChainSpec, ExecutionLayer<E>, Option<ExecutionBlock>) -> V,
V: Future<Output = ()>,
{
let terminal_block_number = self

View File

@@ -84,14 +84,14 @@ impl Default for MockExecutionConfig {
}
}
pub struct MockServer<T: EthSpec> {
pub struct MockServer<E: EthSpec> {
_shutdown_tx: oneshot::Sender<()>,
listen_socket_addr: SocketAddr,
last_echo_request: Arc<RwLock<Option<Bytes>>>,
pub ctx: Arc<Context<T>>,
pub ctx: Arc<Context<E>>,
}
impl<T: EthSpec> MockServer<T> {
impl<E: EthSpec> MockServer<E> {
pub fn unit_testing() -> Self {
Self::new(
&runtime::Handle::current(),
@@ -133,7 +133,7 @@ impl<T: EthSpec> MockServer<T> {
kzg,
);
let ctx: Arc<Context<T>> = Arc::new(Context {
let ctx: Arc<Context<E>> = Arc::new(Context {
config: server_config,
jwt_key,
log: null_logger().unwrap(),
@@ -211,7 +211,7 @@ impl<T: EthSpec> MockServer<T> {
)
}
pub fn execution_block_generator(&self) -> RwLockWriteGuard<'_, ExecutionBlockGenerator<T>> {
pub fn execution_block_generator(&self) -> RwLockWriteGuard<'_, ExecutionBlockGenerator<E>> {
self.ctx.execution_block_generator.write()
}
@@ -423,7 +423,7 @@ impl<T: EthSpec> MockServer<T> {
.insert_block_without_checks(block);
}
pub fn get_block(&self, block_hash: ExecutionBlockHash) -> Option<Block<T>> {
pub fn get_block(&self, block_hash: ExecutionBlockHash) -> Option<Block<E>> {
self.ctx
.execution_block_generator
.read()
@@ -501,12 +501,12 @@ impl warp::reject::Reject for AuthError {}
/// A wrapper around all the items required to spawn the HTTP server.
///
/// The server will gracefully handle the case where any fields are `None`.
pub struct Context<T: EthSpec> {
pub struct Context<E: EthSpec> {
pub config: Config,
pub jwt_key: JwtKey,
pub log: Logger,
pub last_echo_request: Arc<RwLock<Option<Bytes>>>,
pub execution_block_generator: RwLock<ExecutionBlockGenerator<T>>,
pub execution_block_generator: RwLock<ExecutionBlockGenerator<E>>,
pub preloaded_responses: Arc<Mutex<Vec<serde_json::Value>>>,
pub previous_request: Arc<Mutex<Option<serde_json::Value>>>,
pub static_new_payload_response: Arc<Mutex<Option<StaticNewPayloadResponse>>>,
@@ -525,10 +525,10 @@ pub struct Context<T: EthSpec> {
pub syncing_response: Arc<Mutex<Result<bool, String>>>,
pub engine_capabilities: Arc<RwLock<EngineCapabilities>>,
pub _phantom: PhantomData<T>,
pub _phantom: PhantomData<E>,
}
impl<T: EthSpec> Context<T> {
impl<E: EthSpec> Context<E> {
pub fn get_new_payload_status(
&self,
block_hash: &ExecutionBlockHash,
@@ -637,8 +637,8 @@ async fn handle_rejection(err: Rejection) -> Result<impl warp::Reply, Infallible
///
/// Returns an error if the server is unable to bind or there is another error during
/// configuration.
pub fn serve<T: EthSpec>(
ctx: Arc<Context<T>>,
pub fn serve<E: EthSpec>(
ctx: Arc<Context<E>>,
shutdown: impl Future<Output = ()> + Send + Sync + 'static,
) -> Result<(SocketAddr, impl Future<Output = ()>), Error> {
let config = &ctx.config;
@@ -653,7 +653,7 @@ pub fn serve<T: EthSpec>(
let root = warp::path::end()
.and(warp::body::json())
.and(ctx_filter.clone())
.and_then(|body: serde_json::Value, ctx: Arc<Context<T>>| async move {
.and_then(|body: serde_json::Value, ctx: Arc<Context<E>>| async move {
let id = body
.get("id")
.and_then(serde_json::Value::as_u64)
@@ -700,7 +700,7 @@ pub fn serve<T: EthSpec>(
let echo = warp::path("echo")
.and(warp::body::bytes())
.and(ctx_filter)
.and_then(|bytes: Bytes, ctx: Arc<Context<T>>| async move {
.and_then(|bytes: Bytes, ctx: Arc<Context<E>>| async move {
*ctx.last_echo_request.write() = Some(bytes.clone());
Ok::<_, warp::reject::Rejection>(
warp::http::Response::builder().status(200).body(bytes),