got interop working~

This commit is contained in:
Eitan Seri-Levi
2025-06-09 10:07:53 +03:00
parent 30f28784ee
commit 7fe71d4db6
31 changed files with 282 additions and 249 deletions

View File

@@ -42,7 +42,7 @@ pub const ENGINE_GET_PAYLOAD_V1: &str = "engine_getPayloadV1";
pub const ENGINE_GET_PAYLOAD_V2: &str = "engine_getPayloadV2";
pub const ENGINE_GET_PAYLOAD_V3: &str = "engine_getPayloadV3";
pub const ENGINE_GET_PAYLOAD_V4: &str = "engine_getPayloadV4";
pub const ENGINE_GET_PAYLOAD_V5: &str = "engine_getPayloadV5";
pub const ENGINE_GET_PAYLOAD_V5: &str = "engine_getPayloadV4";
pub const ENGINE_GET_PAYLOAD_TIMEOUT: Duration = Duration::from_secs(2);
pub const ENGINE_FORKCHOICE_UPDATED_V1: &str = "engine_forkchoiceUpdatedV1";
@@ -1041,6 +1041,19 @@ impl HttpJsonRpc {
.try_into()
.map_err(Error::BadResponse)
}
ForkName::Eip7805 => {
let response: JsonGetPayloadResponseV5<E> = self
.rpc_request(
ENGINE_GET_PAYLOAD_V4,
params,
ENGINE_GET_PAYLOAD_TIMEOUT * self.execution_timeout_multiplier,
)
.await?;
JsonGetPayloadResponse::V5(response)
.try_into()
.map_err(Error::BadResponse)
}
_ => Err(Error::UnsupportedForkVariant(format!(
"called get_payload_v4 with {}",
fork_name
@@ -1394,10 +1407,10 @@ impl HttpJsonRpc {
}
}
ForkName::Eip7805 => {
if engine_capabilities.get_payload_v5 {
self.get_payload_v5(fork_name, payload_id).await
if engine_capabilities.get_payload_v4 {
self.get_payload_v4(fork_name, payload_id).await
} else {
Err(Error::RequiredMethodUnsupported("engine_getPayloadv5"))
Err(Error::RequiredMethodUnsupported("engine_getPayloadv4"))
}
}
ForkName::Fulu => {

View File

@@ -65,7 +65,7 @@ pub struct JsonPayloadIdResponse {
}
#[superstruct(
variants(V1, V2, V3, V4, V5),
variants(V1, V2, V3, V4, V5, V6),
variant_attributes(
derive(Debug, PartialEq, Default, Serialize, Deserialize,),
serde(bound = "E: EthSpec", rename_all = "camelCase"),
@@ -100,12 +100,12 @@ pub struct JsonExecutionPayload<E: EthSpec> {
pub block_hash: ExecutionBlockHash,
#[serde(with = "ssz_types::serde_utils::list_of_hex_var_list")]
pub transactions: Transactions<E>,
#[superstruct(only(V2, V3, V4, V5))]
#[superstruct(only(V2, V3, V4, V5, V6))]
pub withdrawals: VariableList<JsonWithdrawal, E::MaxWithdrawalsPerPayload>,
#[superstruct(only(V3, V4, V5))]
#[superstruct(only(V3, V4, V5, V6))]
#[serde(with = "serde_utils::u64_hex_be")]
pub blob_gas_used: u64,
#[superstruct(only(V3, V4, V5))]
#[superstruct(only(V3, V4, V5, V6))]
#[serde(with = "serde_utils::u64_hex_be")]
pub excess_blob_gas: u64,
}
@@ -243,6 +243,35 @@ impl<E: EthSpec> From<ExecutionPayloadEip7805<E>> for JsonExecutionPayloadV5<E>
}
}
impl<E: EthSpec> From<ExecutionPayloadFulu<E>> for JsonExecutionPayloadV6<E> {
fn from(payload: ExecutionPayloadFulu<E>) -> Self {
JsonExecutionPayloadV6 {
parent_hash: payload.parent_hash,
fee_recipient: payload.fee_recipient,
state_root: payload.state_root,
receipts_root: payload.receipts_root,
logs_bloom: payload.logs_bloom,
prev_randao: payload.prev_randao,
block_number: payload.block_number,
gas_limit: payload.gas_limit,
gas_used: payload.gas_used,
timestamp: payload.timestamp,
extra_data: payload.extra_data,
base_fee_per_gas: payload.base_fee_per_gas,
block_hash: payload.block_hash,
transactions: payload.transactions,
withdrawals: payload
.withdrawals
.into_iter()
.map(Into::into)
.collect::<Vec<_>>()
.into(),
blob_gas_used: payload.blob_gas_used,
excess_blob_gas: payload.excess_blob_gas,
}
}
}
impl<E: EthSpec> From<ExecutionPayload<E>> for JsonExecutionPayload<E> {
fn from(execution_payload: ExecutionPayload<E>) -> Self {
match execution_payload {
@@ -251,7 +280,7 @@ impl<E: EthSpec> From<ExecutionPayload<E>> for JsonExecutionPayload<E> {
ExecutionPayload::Deneb(payload) => JsonExecutionPayload::V3(payload.into()),
ExecutionPayload::Electra(payload) => JsonExecutionPayload::V4(payload.into()),
ExecutionPayload::Eip7805(payload) => JsonExecutionPayload::V5(payload.into()),
ExecutionPayload::Fulu(_) => unreachable!("DONT USE FULU"),
ExecutionPayload::Fulu(payload) => JsonExecutionPayload::V6(payload.into()),
}
}
}
@@ -390,6 +419,35 @@ impl<E: EthSpec> From<JsonExecutionPayloadV5<E>> for ExecutionPayloadEip7805<E>
}
}
impl<E: EthSpec> From<JsonExecutionPayloadV6<E>> for ExecutionPayloadFulu<E> {
fn from(payload: JsonExecutionPayloadV6<E>) -> Self {
ExecutionPayloadFulu {
parent_hash: payload.parent_hash,
fee_recipient: payload.fee_recipient,
state_root: payload.state_root,
receipts_root: payload.receipts_root,
logs_bloom: payload.logs_bloom,
prev_randao: payload.prev_randao,
block_number: payload.block_number,
gas_limit: payload.gas_limit,
gas_used: payload.gas_used,
timestamp: payload.timestamp,
extra_data: payload.extra_data,
base_fee_per_gas: payload.base_fee_per_gas,
block_hash: payload.block_hash,
transactions: payload.transactions,
withdrawals: payload
.withdrawals
.into_iter()
.map(Into::into)
.collect::<Vec<_>>()
.into(),
blob_gas_used: payload.blob_gas_used,
excess_blob_gas: payload.excess_blob_gas,
}
}
}
impl<E: EthSpec> From<JsonExecutionPayload<E>> for ExecutionPayload<E> {
fn from(json_execution_payload: JsonExecutionPayload<E>) -> Self {
match json_execution_payload {
@@ -398,6 +456,7 @@ impl<E: EthSpec> From<JsonExecutionPayload<E>> for ExecutionPayload<E> {
JsonExecutionPayload::V3(payload) => ExecutionPayload::Deneb(payload.into()),
JsonExecutionPayload::V4(payload) => ExecutionPayload::Electra(payload.into()),
JsonExecutionPayload::V5(payload) => ExecutionPayload::Eip7805(payload.into()),
JsonExecutionPayload::V6(payload) => ExecutionPayload::Fulu(payload.into()),
}
}
}
@@ -483,7 +542,7 @@ impl<E: EthSpec> TryFrom<JsonExecutionRequests> for ExecutionRequests<E> {
}
#[superstruct(
variants(V1, V2, V3, V4, V5),
variants(V1, V2, V3, V4, V5, V6),
variant_attributes(
derive(Debug, PartialEq, Serialize, Deserialize),
serde(bound = "E: EthSpec", rename_all = "camelCase")
@@ -504,13 +563,15 @@ pub struct JsonGetPayloadResponse<E: EthSpec> {
pub execution_payload: JsonExecutionPayloadV4<E>,
#[superstruct(only(V5), partial_getter(rename = "execution_payload_v5"))]
pub execution_payload: JsonExecutionPayloadV5<E>,
#[superstruct(only(V6), partial_getter(rename = "execution_payload_v6"))]
pub execution_payload: JsonExecutionPayloadV6<E>,
#[serde(with = "serde_utils::u256_hex_be")]
pub block_value: Uint256,
#[superstruct(only(V3, V4, V5))]
#[superstruct(only(V3, V4, V5, V6))]
pub blobs_bundle: JsonBlobsBundleV1<E>,
#[superstruct(only(V3, V4, V5))]
#[superstruct(only(V3, V4, V5, V6))]
pub should_override_builder: bool,
#[superstruct(only(V4, V5))]
#[superstruct(only(V4, V5, V6))]
pub execution_requests: JsonExecutionRequests,
}
@@ -560,6 +621,17 @@ impl<E: EthSpec> TryFrom<JsonGetPayloadResponse<E>> for GetPayloadResponse<E> {
})?,
}))
}
JsonGetPayloadResponse::V6(response) => {
Ok(GetPayloadResponse::Fulu(GetPayloadResponseFulu {
execution_payload: response.execution_payload.into(),
block_value: response.block_value,
blobs_bundle: response.blobs_bundle.into(),
should_override_builder: response.should_override_builder,
requests: response.execution_requests.try_into().map_err(|e| {
format!("Failed to convert json to execution requests {:?}", e)
})?,
}))
}
}
}
}

View File

@@ -1,11 +1,11 @@
use crate::{block_hash::calculate_execution_block_hash, metrics, Error};
use crate::{block_hash::calculate_execution_block_hash, metrics, Error, Transactions};
use crate::versioned_hashes::verify_versioned_hashes;
use state_processing::per_block_processing::deneb::kzg_commitment_to_versioned_hash;
use superstruct::superstruct;
use types::{
BeaconBlockRef, BeaconStateError, EthSpec, ExecutionBlockHash, ExecutionPayload,
ExecutionPayloadRef, Hash256, InclusionListTransactions, VersionedHash,
ExecutionPayloadRef, Hash256, VersionedHash,
};
use types::{
ExecutionPayloadBellatrix, ExecutionPayloadCapella, ExecutionPayloadDeneb,
@@ -50,7 +50,7 @@ pub struct NewPayloadRequest<'block, E: EthSpec> {
#[superstruct(only(Electra, Eip7805, Fulu))]
pub execution_requests: &'block ExecutionRequests<E>,
#[superstruct(only(Eip7805, Fulu))]
pub il_transactions: InclusionListTransactions<E>,
pub il_transactions: Transactions<E>,
}
impl<'block, E: EthSpec> NewPayloadRequest<'block, E> {
@@ -177,7 +177,7 @@ impl<'block, E: EthSpec> NewPayloadRequest<'block, E> {
impl<'a, E: EthSpec> NewPayloadRequest<'a, E> {
pub fn try_from_block_and_il_transactions(
block: BeaconBlockRef<'a, E>,
il_transactions: InclusionListTransactions<E>,
il_transactions: Transactions<E>,
) -> Result<Self, BeaconStateError> {
match block {
BeaconBlockRef::Base(_) | BeaconBlockRef::Altair(_) => {

View File

@@ -56,8 +56,7 @@ use types::{
use types::{
BeaconStateError, BlindedPayload, ChainSpec, Epoch, ExecPayload, ExecutionPayloadBellatrix,
ExecutionPayloadCapella, ExecutionPayloadEip7805, ExecutionPayloadElectra,
ExecutionPayloadFulu, FullPayload, InclusionListTransactions, ProposerPreparationData,
PublicKeyBytes, Signature, Slot,
ExecutionPayloadFulu, FullPayload, ProposerPreparationData, PublicKeyBytes, Signature, Slot,
};
mod block_hash;
@@ -1983,17 +1982,14 @@ impl<E: EthSpec> ExecutionLayer<E> {
}
}
pub async fn get_inclusion_list(
&self,
parent_hash: Hash256,
) -> Result<InclusionListTransactions<E>, Error> {
pub async fn get_inclusion_list(&self, parent_hash: Hash256) -> Result<Transactions<E>, Error> {
debug!(%parent_hash, "Requesting inclusion list from EL");
let raw_transactions = self
.engine()
.api
.get_inclusion_list::<E>(parent_hash)
.await?;
// TODO(focil) clean this up?
let mut transactions = vec![];
let Some(raw_transactions) = raw_transactions else {

View File

@@ -3,11 +3,10 @@ use crate::engine_api::{http::*, *};
use crate::json_structures::*;
use crate::test_utils::{DEFAULT_CLIENT_VERSION, DEFAULT_MOCK_EL_PAYLOAD_VALUE_WEI};
use crate::EthersTransaction;
use crate::Transactions;
use serde::{de::DeserializeOwned, Deserialize};
use serde_json::Value as JsonValue;
use ssz_types::VariableList;
use std::sync::Arc;
use types::InclusionListTransactions;
pub const GENERIC_ERROR_CODE: i64 = -1234;
pub const BAD_PARAMS_ERROR_CODE: i64 = -32602;
@@ -128,6 +127,9 @@ pub async fn handle_rpc<E: EthSpec>(
ENGINE_NEW_PAYLOAD_V5 => get_param::<JsonExecutionPayloadV5<E>>(params, 0)
.map(|jep| JsonExecutionPayload::V5(jep))
.map_err(|s| (s, BAD_PARAMS_ERROR_CODE))?,
ENGINE_NEW_PAYLOAD_V5 => get_param::<JsonExecutionPayloadV5<E>>(params, 0)
.map(|jep| JsonExecutionPayload::V5(jep))
.map_err(|s| (s, BAD_PARAMS_ERROR_CODE))?,
_ => unreachable!(),
};
@@ -251,7 +253,7 @@ pub async fn handle_rpc<E: EthSpec>(
if matches!(request, JsonExecutionPayload::V2(_)) {
return Err((
format!(
"{} called with `ExecutionPayloadV2` after Electra fork!",
"{} called with `ExecutionPayloadV2` after Eip7805 fork!",
method
),
GENERIC_ERROR_CODE,
@@ -260,7 +262,7 @@ pub async fn handle_rpc<E: EthSpec>(
if matches!(request, JsonExecutionPayload::V3(_)) {
return Err((
format!(
"{} called with `ExecutionPayloadV3` after Electra fork!",
"{} called with `ExecutionPayloadV3` after Eip7805 fork!",
method
),
GENERIC_ERROR_CODE,
@@ -355,8 +357,7 @@ pub async fn handle_rpc<E: EthSpec>(
ENGINE_GET_PAYLOAD_V1
| ENGINE_GET_PAYLOAD_V2
| ENGINE_GET_PAYLOAD_V3
| ENGINE_GET_PAYLOAD_V4
| ENGINE_GET_PAYLOAD_V5 => {
| ENGINE_GET_PAYLOAD_V4 => {
let request: JsonPayloadIdRequest =
get_param(params, 0).map_err(|s| (s, BAD_PARAMS_ERROR_CODE))?;
let id = request.into();
@@ -416,6 +417,22 @@ pub async fn handle_rpc<E: EthSpec>(
));
}
// validate method called correctly according to prague fork time
if ctx
.execution_block_generator
.read()
.get_fork_at_timestamp(response.timestamp())
== ForkName::Eip7805
&& (method == ENGINE_GET_PAYLOAD_V1
|| method == ENGINE_GET_PAYLOAD_V2
|| method == ENGINE_GET_PAYLOAD_V3)
{
return Err((
format!("{} called after EIP7805 fork!", method),
FORK_REQUEST_MISMATCH_ERROR_CODE,
));
}
// validate method called correctly according to fulu fork time
if ctx
.execution_block_generator
@@ -424,8 +441,7 @@ pub async fn handle_rpc<E: EthSpec>(
== ForkName::Fulu
&& (method == ENGINE_GET_PAYLOAD_V1
|| method == ENGINE_GET_PAYLOAD_V2
|| method == ENGINE_GET_PAYLOAD_V3
|| method == ENGINE_GET_PAYLOAD_V4)
|| method == ENGINE_GET_PAYLOAD_V3)
{
return Err((
format!("{} called after Fulu fork!", method),
@@ -491,9 +507,6 @@ pub async fn handle_rpc<E: EthSpec>(
})
.unwrap()
}
_ => unreachable!(),
}),
ENGINE_GET_PAYLOAD_V5 => Ok(match JsonExecutionPayload::from(response) {
JsonExecutionPayload::V5(execution_payload) => {
serde_json::to_value(JsonGetPayloadResponseV5 {
execution_payload,
@@ -505,17 +518,18 @@ pub async fn handle_rpc<E: EthSpec>(
))?
.into(),
should_override_builder: false,
// TODO(electra): add EL requests in mock el
execution_requests: Default::default(),
})
.unwrap()
}
JsonExecutionPayload::V4(execution_payload) => {
serde_json::to_value(JsonGetPayloadResponseV4 {
JsonExecutionPayload::V6(execution_payload) => {
serde_json::to_value(JsonGetPayloadResponseV6 {
execution_payload,
block_value: Uint256::from(DEFAULT_MOCK_EL_PAYLOAD_VALUE_WEI),
blobs_bundle: maybe_blobs
.ok_or((
"No blobs returned despite V4 Payload".to_string(),
"No blobs returned despite V5 Payload".to_string(),
GENERIC_ERROR_CODE,
))?
.into(),
@@ -525,7 +539,7 @@ pub async fn handle_rpc<E: EthSpec>(
})
.unwrap()
}
other => unreachable!("check {:?}", other),
_ => unreachable!(),
}),
_ => unreachable!(),
}
@@ -747,11 +761,7 @@ pub async fn handle_rpc<E: EthSpec>(
}"#,
)
.unwrap();
let tx_list: InclusionListTransactions<E> =
vec![VariableList::new(transaction.rlp().to_vec())
.map_err(|e| format!("Failed to convert transaction to SSZ: {:?}", e))
.unwrap()]
.into();
let tx_list: Transactions<E> = vec![transaction.rlp().to_vec().into()].into();
Ok(serde_json::to_value(tx_list).unwrap())
}