Resolve merge conflicts

This commit is contained in:
Eitan Seri- Levi
2025-11-04 10:36:08 -08:00
129 changed files with 2701 additions and 1640 deletions

View File

@@ -13,6 +13,7 @@ use rand::{Rng, SeedableRng, rngs::StdRng};
use serde::{Deserialize, Serialize};
use ssz::Decode;
use ssz_types::VariableList;
use std::cmp::max;
use std::collections::HashMap;
use std::sync::Arc;
use tree_hash::TreeHash;
@@ -29,7 +30,7 @@ use super::DEFAULT_TERMINAL_BLOCK;
const TEST_BLOB_BUNDLE: &[u8] = include_bytes!("fixtures/mainnet/test_blobs_bundle.ssz");
const TEST_BLOB_BUNDLE_V2: &[u8] = include_bytes!("fixtures/mainnet/test_blobs_bundle_v2.ssz");
pub const DEFAULT_GAS_LIMIT: u64 = 45_000_000;
pub const DEFAULT_GAS_LIMIT: u64 = 60_000_000;
const GAS_USED: u64 = DEFAULT_GAS_LIMIT - 1;
#[derive(Clone, Debug, PartialEq)]
@@ -40,7 +41,7 @@ pub enum Block<E: EthSpec> {
}
pub fn mock_el_extra_data<E: EthSpec>() -> types::VariableList<u8, E::MaxExtraDataBytes> {
"block gen was here".as_bytes().to_vec().into()
"block gen was here".as_bytes().to_vec().try_into().unwrap()
}
impl<E: EthSpec> Block<E> {
@@ -157,7 +158,6 @@ pub struct ExecutionBlockGenerator<E: EthSpec> {
pub blobs_bundles: HashMap<PayloadId, BlobsBundle<E>>,
pub kzg: Option<Arc<Kzg>>,
rng: Arc<Mutex<StdRng>>,
spec: Arc<ChainSpec>,
}
fn make_rng() -> Arc<Mutex<StdRng>> {
@@ -177,7 +177,6 @@ impl<E: EthSpec> ExecutionBlockGenerator<E> {
prague_time: Option<u64>,
osaka_time: Option<u64>,
amsterdam_time: Option<u64>,
spec: Arc<ChainSpec>,
kzg: Option<Arc<Kzg>>,
) -> Self {
let mut generator = Self {
@@ -200,7 +199,6 @@ impl<E: EthSpec> ExecutionBlockGenerator<E> {
blobs_bundles: <_>::default(),
kzg,
rng: make_rng(),
spec,
};
generator.insert_pow_block(0).unwrap();
@@ -602,7 +600,7 @@ impl<E: EthSpec> ExecutionBlockGenerator<E> {
fee_recipient: pa.suggested_fee_recipient,
receipts_root: Hash256::repeat_byte(42),
state_root: Hash256::repeat_byte(43),
logs_bloom: vec![0; 256].into(),
logs_bloom: vec![0; 256].try_into().unwrap(),
prev_randao: pa.prev_randao,
block_number: parent.block_number() + 1,
gas_limit: DEFAULT_GAS_LIMIT,
@@ -611,7 +609,7 @@ impl<E: EthSpec> ExecutionBlockGenerator<E> {
extra_data: mock_el_extra_data::<E>(),
base_fee_per_gas: Uint256::from(1u64),
block_hash: ExecutionBlockHash::zero(),
transactions: vec![].into(),
transactions: vec![].try_into().unwrap(),
}),
PayloadAttributes::V2(pa) => match self.get_fork_at_timestamp(pa.timestamp) {
ForkName::Bellatrix => ExecutionPayload::Bellatrix(ExecutionPayloadBellatrix {
@@ -619,7 +617,7 @@ impl<E: EthSpec> ExecutionBlockGenerator<E> {
fee_recipient: pa.suggested_fee_recipient,
receipts_root: Hash256::repeat_byte(42),
state_root: Hash256::repeat_byte(43),
logs_bloom: vec![0; 256].into(),
logs_bloom: vec![0; 256].try_into().unwrap(),
prev_randao: pa.prev_randao,
block_number: parent.block_number() + 1,
gas_limit: DEFAULT_GAS_LIMIT,
@@ -628,14 +626,14 @@ impl<E: EthSpec> ExecutionBlockGenerator<E> {
extra_data: mock_el_extra_data::<E>(),
base_fee_per_gas: Uint256::from(1u64),
block_hash: ExecutionBlockHash::zero(),
transactions: vec![].into(),
transactions: vec![].try_into().unwrap(),
}),
ForkName::Capella => ExecutionPayload::Capella(ExecutionPayloadCapella {
parent_hash: head_block_hash,
fee_recipient: pa.suggested_fee_recipient,
receipts_root: Hash256::repeat_byte(42),
state_root: Hash256::repeat_byte(43),
logs_bloom: vec![0; 256].into(),
logs_bloom: vec![0; 256].try_into().unwrap(),
prev_randao: pa.prev_randao,
block_number: parent.block_number() + 1,
gas_limit: DEFAULT_GAS_LIMIT,
@@ -644,8 +642,8 @@ impl<E: EthSpec> ExecutionBlockGenerator<E> {
extra_data: mock_el_extra_data::<E>(),
base_fee_per_gas: Uint256::from(1u64),
block_hash: ExecutionBlockHash::zero(),
transactions: vec![].into(),
withdrawals: pa.withdrawals.clone().into(),
transactions: vec![].try_into().unwrap(),
withdrawals: pa.withdrawals.clone().try_into().unwrap(),
}),
_ => unreachable!(),
},
@@ -655,7 +653,7 @@ impl<E: EthSpec> ExecutionBlockGenerator<E> {
fee_recipient: pa.suggested_fee_recipient,
receipts_root: Hash256::repeat_byte(42),
state_root: Hash256::repeat_byte(43),
logs_bloom: vec![0; 256].into(),
logs_bloom: vec![0; 256].try_into().unwrap(),
prev_randao: pa.prev_randao,
block_number: parent.block_number() + 1,
gas_limit: DEFAULT_GAS_LIMIT,
@@ -664,8 +662,8 @@ impl<E: EthSpec> ExecutionBlockGenerator<E> {
extra_data: mock_el_extra_data::<E>(),
base_fee_per_gas: Uint256::from(1u64),
block_hash: ExecutionBlockHash::zero(),
transactions: vec![].into(),
withdrawals: pa.withdrawals.clone().into(),
transactions: vec![].try_into().unwrap(),
withdrawals: pa.withdrawals.clone().try_into().unwrap(),
blob_gas_used: 0,
excess_blob_gas: 0,
}),
@@ -674,7 +672,7 @@ impl<E: EthSpec> ExecutionBlockGenerator<E> {
fee_recipient: pa.suggested_fee_recipient,
receipts_root: Hash256::repeat_byte(42),
state_root: Hash256::repeat_byte(43),
logs_bloom: vec![0; 256].into(),
logs_bloom: vec![0; 256].try_into().unwrap(),
prev_randao: pa.prev_randao,
block_number: parent.block_number() + 1,
gas_limit: DEFAULT_GAS_LIMIT,
@@ -683,8 +681,8 @@ impl<E: EthSpec> ExecutionBlockGenerator<E> {
extra_data: mock_el_extra_data::<E>(),
base_fee_per_gas: Uint256::from(1u64),
block_hash: ExecutionBlockHash::zero(),
transactions: vec![].into(),
withdrawals: pa.withdrawals.clone().into(),
transactions: vec![].try_into().unwrap(),
withdrawals: pa.withdrawals.clone().try_into().unwrap(),
blob_gas_used: 0,
excess_blob_gas: 0,
}),
@@ -693,17 +691,17 @@ impl<E: EthSpec> ExecutionBlockGenerator<E> {
fee_recipient: pa.suggested_fee_recipient,
receipts_root: Hash256::repeat_byte(42),
state_root: Hash256::repeat_byte(43),
logs_bloom: vec![0; 256].into(),
logs_bloom: vec![0; 256].try_into().unwrap(),
prev_randao: pa.prev_randao,
block_number: parent.block_number() + 1,
gas_limit: DEFAULT_GAS_LIMIT,
gas_used: GAS_USED,
timestamp: pa.timestamp,
extra_data: "block gen was here".as_bytes().to_vec().into(),
extra_data: "block gen was here".as_bytes().to_vec().try_into().unwrap(),
base_fee_per_gas: Uint256::from(1u64),
block_hash: ExecutionBlockHash::zero(),
transactions: vec![].into(),
withdrawals: pa.withdrawals.clone().into(),
transactions: vec![].try_into().unwrap(),
withdrawals: pa.withdrawals.clone().try_into().unwrap(),
blob_gas_used: 0,
excess_blob_gas: 0,
}),
@@ -712,17 +710,17 @@ impl<E: EthSpec> ExecutionBlockGenerator<E> {
fee_recipient: pa.suggested_fee_recipient,
receipts_root: Hash256::repeat_byte(42),
state_root: Hash256::repeat_byte(43),
logs_bloom: vec![0; 256].into(),
logs_bloom: vec![0; 256].try_into().unwrap(),
prev_randao: pa.prev_randao,
block_number: parent.block_number() + 1,
gas_limit: DEFAULT_GAS_LIMIT,
gas_used: GAS_USED,
timestamp: pa.timestamp,
extra_data: "block gen was here".as_bytes().to_vec().into(),
extra_data: "block gen was here".as_bytes().to_vec().try_into().unwrap(),
base_fee_per_gas: Uint256::from(1u64),
block_hash: ExecutionBlockHash::zero(),
transactions: vec![].into(),
withdrawals: pa.withdrawals.clone().into(),
transactions: vec![].try_into().unwrap(),
withdrawals: pa.withdrawals.clone().try_into().unwrap(),
blob_gas_used: 0,
excess_blob_gas: 0,
}),
@@ -732,11 +730,10 @@ impl<E: EthSpec> ExecutionBlockGenerator<E> {
let fork_name = execution_payload.fork_name();
if fork_name.deneb_enabled() {
// get random number between 0 and Max Blobs
// get random number between 0 and 1 blobs by default
// For tests that need higher blob count, consider adding a `set_max_blob_count` method
let mut rng = self.rng.lock();
// TODO(EIP-7892): see FIXME below
// FIXME: this will break with BPO forks. This function needs to calculate the epoch based on block timestamp..
let max_blobs = self.spec.max_blobs_per_block_within_fork(fork_name) as usize;
let max_blobs = max(1, self.min_blobs_count);
let num_blobs = rng.random_range(self.min_blobs_count..=max_blobs);
let (bundle, transactions) = generate_blobs(num_blobs, fork_name)?;
for tx in Vec::from(transactions) {
@@ -813,24 +810,25 @@ pub fn generate_blobs<E: EthSpec>(
let bundle = if fork_name.fulu_enabled() {
let (kzg_commitment, kzg_proofs, blob) = load_test_blobs_bundle_v2::<E>()?;
BlobsBundle {
commitments: vec![kzg_commitment; n_blobs].into(),
commitments: vec![kzg_commitment; n_blobs].try_into().unwrap(),
proofs: vec![kzg_proofs.to_vec(); n_blobs]
.into_iter()
.flatten()
.collect::<Vec<_>>()
.into(),
blobs: vec![blob; n_blobs].into(),
.try_into()
.unwrap(),
blobs: vec![blob; n_blobs].try_into().unwrap(),
}
} else {
let (kzg_commitment, kzg_proof, blob) = load_test_blobs_bundle_v1::<E>()?;
BlobsBundle {
commitments: vec![kzg_commitment; n_blobs].into(),
proofs: vec![kzg_proof; n_blobs].into(),
blobs: vec![blob; n_blobs].into(),
commitments: vec![kzg_commitment; n_blobs].try_into().unwrap(),
proofs: vec![kzg_proof; n_blobs].try_into().unwrap(),
blobs: vec![blob; n_blobs].try_into().unwrap(),
}
};
Ok((bundle, transactions.into()))
Ok((bundle, transactions.try_into().unwrap()))
}
pub fn static_valid_tx<E: EthSpec>() -> Result<Transaction<E::MaxBytesPerTransaction>, String> {
@@ -973,7 +971,6 @@ mod test {
const TERMINAL_DIFFICULTY: u64 = 10;
const TERMINAL_BLOCK: u64 = 10;
const DIFFICULTY_INCREMENT: u64 = 1;
let spec = Arc::new(MainnetEthSpec::default_spec());
let mut generator: ExecutionBlockGenerator<MainnetEthSpec> = ExecutionBlockGenerator::new(
Uint256::from(TERMINAL_DIFFICULTY),
@@ -984,7 +981,6 @@ mod test {
None,
None,
None,
spec,
None,
);

View File

@@ -252,7 +252,7 @@ pub async fn handle_rpc<E: EthSpec>(
Some(
ctx.execution_block_generator
.write()
.new_payload(request.into()),
.new_payload(request.try_into().unwrap()),
)
} else {
None
@@ -361,98 +361,107 @@ pub async fn handle_rpc<E: EthSpec>(
}
match method {
ENGINE_GET_PAYLOAD_V1 => {
Ok(serde_json::to_value(JsonExecutionPayload::from(response)).unwrap())
ENGINE_GET_PAYLOAD_V1 => Ok(serde_json::to_value(
JsonExecutionPayload::try_from(response).unwrap(),
)
.unwrap()),
ENGINE_GET_PAYLOAD_V2 => {
Ok(match JsonExecutionPayload::try_from(response).unwrap() {
JsonExecutionPayload::Bellatrix(execution_payload) => {
serde_json::to_value(JsonGetPayloadResponseBellatrix {
execution_payload,
block_value: Uint256::from(DEFAULT_MOCK_EL_PAYLOAD_VALUE_WEI),
})
.unwrap()
}
JsonExecutionPayload::Capella(execution_payload) => {
serde_json::to_value(JsonGetPayloadResponseCapella {
execution_payload,
block_value: Uint256::from(DEFAULT_MOCK_EL_PAYLOAD_VALUE_WEI),
})
.unwrap()
}
_ => unreachable!(),
})
}
ENGINE_GET_PAYLOAD_V2 => Ok(match JsonExecutionPayload::from(response) {
JsonExecutionPayload::Bellatrix(execution_payload) => {
serde_json::to_value(JsonGetPayloadResponseBellatrix {
execution_payload,
block_value: Uint256::from(DEFAULT_MOCK_EL_PAYLOAD_VALUE_WEI),
})
.unwrap()
}
JsonExecutionPayload::Capella(execution_payload) => {
serde_json::to_value(JsonGetPayloadResponseCapella {
execution_payload,
block_value: Uint256::from(DEFAULT_MOCK_EL_PAYLOAD_VALUE_WEI),
})
.unwrap()
}
_ => unreachable!(),
}),
// From v3 onwards, we use the getPayload version only for the corresponding
// ExecutionPayload version. So we return an error if the ExecutionPayload version
// we get does not correspond to the getPayload version.
ENGINE_GET_PAYLOAD_V3 => Ok(match JsonExecutionPayload::from(response) {
JsonExecutionPayload::Deneb(execution_payload) => {
serde_json::to_value(JsonGetPayloadResponseDeneb {
execution_payload,
block_value: Uint256::from(DEFAULT_MOCK_EL_PAYLOAD_VALUE_WEI),
blobs_bundle: maybe_blobs
.ok_or((
"No blobs returned despite V3 Payload".to_string(),
GENERIC_ERROR_CODE,
))?
.into(),
should_override_builder: false,
})
.unwrap()
}
_ => unreachable!(),
}),
ENGINE_GET_PAYLOAD_V4 => Ok(match JsonExecutionPayload::from(response) {
JsonExecutionPayload::Electra(execution_payload) => {
serde_json::to_value(JsonGetPayloadResponseElectra {
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(),
GENERIC_ERROR_CODE,
))?
.into(),
should_override_builder: false,
// TODO(electra): add EL requests in mock el
execution_requests: Default::default(),
})
.unwrap()
}
_ => unreachable!(),
}),
ENGINE_GET_PAYLOAD_V5 => Ok(match JsonExecutionPayload::from(response) {
JsonExecutionPayload::Fulu(execution_payload) => {
serde_json::to_value(JsonGetPayloadResponseFulu {
execution_payload,
block_value: Uint256::from(DEFAULT_MOCK_EL_PAYLOAD_VALUE_WEI),
blobs_bundle: maybe_blobs
.ok_or((
"No blobs returned despite V5 Payload".to_string(),
GENERIC_ERROR_CODE,
))?
.into(),
should_override_builder: false,
execution_requests: Default::default(),
})
.unwrap()
}
JsonExecutionPayload::Gloas(execution_payload) => {
serde_json::to_value(JsonGetPayloadResponseGloas {
execution_payload,
block_value: Uint256::from(DEFAULT_MOCK_EL_PAYLOAD_VALUE_WEI),
blobs_bundle: maybe_blobs
.ok_or((
"No blobs returned despite V5 Payload".to_string(),
GENERIC_ERROR_CODE,
))?
.into(),
should_override_builder: false,
execution_requests: Default::default(),
})
.unwrap()
}
_ => unreachable!(),
}),
ENGINE_GET_PAYLOAD_V3 => {
Ok(match JsonExecutionPayload::try_from(response).unwrap() {
JsonExecutionPayload::Deneb(execution_payload) => {
serde_json::to_value(JsonGetPayloadResponseDeneb {
execution_payload,
block_value: Uint256::from(DEFAULT_MOCK_EL_PAYLOAD_VALUE_WEI),
blobs_bundle: maybe_blobs
.ok_or((
"No blobs returned despite V3 Payload".to_string(),
GENERIC_ERROR_CODE,
))?
.into(),
should_override_builder: false,
})
.unwrap()
}
_ => unreachable!(),
})
}
ENGINE_GET_PAYLOAD_V4 => {
Ok(match JsonExecutionPayload::try_from(response).unwrap() {
JsonExecutionPayload::Electra(execution_payload) => {
serde_json::to_value(JsonGetPayloadResponseElectra {
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(),
GENERIC_ERROR_CODE,
))?
.into(),
should_override_builder: false,
// TODO(electra): add EL requests in mock el
execution_requests: Default::default(),
})
.unwrap()
}
_ => unreachable!(),
})
}
ENGINE_GET_PAYLOAD_V5 => {
Ok(match JsonExecutionPayload::try_from(response).unwrap() {
JsonExecutionPayload::Fulu(execution_payload) => {
serde_json::to_value(JsonGetPayloadResponseFulu {
execution_payload,
block_value: Uint256::from(DEFAULT_MOCK_EL_PAYLOAD_VALUE_WEI),
blobs_bundle: maybe_blobs
.ok_or((
"No blobs returned despite V5 Payload".to_string(),
GENERIC_ERROR_CODE,
))?
.into(),
should_override_builder: false,
execution_requests: Default::default(),
})
.unwrap()
}
JsonExecutionPayload::Gloas(execution_payload) => {
serde_json::to_value(JsonGetPayloadResponseGloas {
execution_payload,
block_value: Uint256::from(DEFAULT_MOCK_EL_PAYLOAD_VALUE_WEI),
blobs_bundle: maybe_blobs
.ok_or((
"No blobs returned despite V5 Payload".to_string(),
GENERIC_ERROR_CODE,
))?
.into(),
should_override_builder: false,
execution_requests: Default::default(),
})
.unwrap()
}
_ => unreachable!(),
})
}
_ => unreachable!(),
}
}
@@ -644,7 +653,8 @@ pub async fn handle_rpc<E: EthSpec>(
transactions: payload.transactions().clone(),
withdrawals: payload.withdrawals().ok().cloned(),
};
let json_payload_body = JsonExecutionPayloadBodyV1::from(payload_body);
let json_payload_body: JsonExecutionPayloadBodyV1<E> =
payload_body.try_into().unwrap();
response.push(Some(json_payload_body));
}
None => response.push(None),

View File

@@ -40,7 +40,7 @@ use warp::reply::{self, Reply};
use warp::{Filter, Rejection};
pub const DEFAULT_FEE_RECIPIENT: Address = Address::repeat_byte(42);
pub const DEFAULT_GAS_LIMIT: u64 = 45_000_000;
pub const DEFAULT_GAS_LIMIT: u64 = 60_000_000;
pub const DEFAULT_BUILDER_PRIVATE_KEY: &str =
"607a11b45a7219cc61a3d9c5fd08c7eebd602a6a19a977f8d3771d5711a550f2";
@@ -72,7 +72,7 @@ impl Operation {
}
pub fn mock_builder_extra_data<E: EthSpec>() -> types::VariableList<u8, E::MaxExtraDataBytes> {
"mock_builder".as_bytes().to_vec().into()
"mock_builder".as_bytes().to_vec().try_into().unwrap()
}
#[derive(Debug)]

View File

@@ -63,7 +63,6 @@ impl<E: EthSpec> MockExecutionLayer<E> {
prague_time,
osaka_time,
amsterdam_time,
spec.clone(),
kzg,
);

View File

@@ -22,7 +22,7 @@ use std::net::{Ipv4Addr, SocketAddr, SocketAddrV4};
use std::sync::{Arc, LazyLock};
use tokio::{runtime, sync::oneshot};
use tracing::info;
use types::{ChainSpec, EthSpec, ExecutionBlockHash, Uint256};
use types::{EthSpec, ExecutionBlockHash, Uint256};
use warp::{Filter, Rejection, http::StatusCode};
use crate::EngineCapabilities;
@@ -114,7 +114,7 @@ pub struct MockServer<E: EthSpec> {
}
impl<E: EthSpec> MockServer<E> {
pub fn unit_testing(chain_spec: Arc<ChainSpec>) -> Self {
pub fn unit_testing() -> Self {
Self::new(
&runtime::Handle::current(),
JwtKey::from_slice(&DEFAULT_JWT_SECRET).unwrap(),
@@ -126,7 +126,6 @@ impl<E: EthSpec> MockServer<E> {
None, // FIXME(electra): should this be the default?
None, // FIXME(fulu): should this be the default?
None, // FIXME(gloas): should this be the default?
chain_spec,
None,
)
}
@@ -134,7 +133,6 @@ impl<E: EthSpec> MockServer<E> {
pub fn new_with_config(
handle: &runtime::Handle,
config: MockExecutionConfig,
spec: Arc<ChainSpec>,
kzg: Option<Arc<Kzg>>,
) -> Self {
create_test_tracing_subscriber();
@@ -161,7 +159,6 @@ impl<E: EthSpec> MockServer<E> {
prague_time,
osaka_time,
amsterdam_time,
spec,
kzg,
);
@@ -226,7 +223,6 @@ impl<E: EthSpec> MockServer<E> {
prague_time: Option<u64>,
osaka_time: Option<u64>,
amsterdam_time: Option<u64>,
spec: Arc<ChainSpec>,
kzg: Option<Arc<Kzg>>,
) -> Self {
Self::new_with_config(
@@ -243,7 +239,6 @@ impl<E: EthSpec> MockServer<E> {
osaka_time,
amsterdam_time,
},
spec,
kzg,
)
}