Skip to content

Commit

Permalink
dev: add requests to EthBuiltPayload (paradigmxyz#12072)
Browse files Browse the repository at this point in the history
  • Loading branch information
greged93 authored Oct 26, 2024
1 parent fa59bd5 commit e0ad598
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 24 deletions.
3 changes: 2 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 1 addition & 8 deletions crates/e2e-test-utils/src/engine_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,7 @@ impl<E: EngineTypes, ChainSpec: EthereumHardforks> EngineApiTestContext<E, Chain
.chain_spec
.is_prague_active_at_timestamp(payload_builder_attributes.timestamp())
{
let requests = payload
.executed_block()
.unwrap()
.execution_outcome()
.requests
.first()
.unwrap()
.clone();
let requests = payload.requests().unwrap();
let envelope: <E as EngineTypes>::ExecutionPayloadEnvelopeV4 = payload.into();
EngineApiClient::<E>::new_payload_v4(
&self.engine_api_client,
Expand Down
26 changes: 15 additions & 11 deletions crates/ethereum/engine-primitives/src/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ pub struct EthBuiltPayload {
/// The blobs, proofs, and commitments in the block. If the block is pre-cancun, this will be
/// empty.
pub(crate) sidecars: Vec<BlobTransactionSidecar>,
/// The requests of the payload
pub(crate) requests: Option<Requests>,
}

// === impl BuiltPayload ===
Expand All @@ -46,8 +48,9 @@ impl EthBuiltPayload {
block: SealedBlock,
fees: U256,
executed_block: Option<ExecutedBlock>,
requests: Option<Requests>,
) -> Self {
Self { id, block, executed_block, fees, sidecars: Vec::new() }
Self { id, block, executed_block, fees, sidecars: Vec::new(), requests }
}

/// Returns the identifier of the payload.
Expand Down Expand Up @@ -97,6 +100,10 @@ impl BuiltPayload for EthBuiltPayload {
fn executed_block(&self) -> Option<ExecutedBlock> {
self.executed_block.clone()
}

fn requests(&self) -> Option<Requests> {
self.requests.clone()
}
}

impl BuiltPayload for &EthBuiltPayload {
Expand All @@ -111,6 +118,10 @@ impl BuiltPayload for &EthBuiltPayload {
fn executed_block(&self) -> Option<ExecutedBlock> {
self.executed_block.clone()
}

fn requests(&self) -> Option<Requests> {
self.requests.clone()
}
}

// V1 engine_getPayloadV1 response
Expand Down Expand Up @@ -152,15 +163,8 @@ impl From<EthBuiltPayload> for ExecutionPayloadEnvelopeV3 {

impl From<EthBuiltPayload> for ExecutionPayloadEnvelopeV4 {
fn from(value: EthBuiltPayload) -> Self {
let EthBuiltPayload { block, fees, sidecars, executed_block, .. } = value;

// if we have an executed block, we pop off the first set of requests from the execution
// outcome. the assumption here is that there will always only be one block in the execution
// outcome.
let execution_requests = executed_block
.and_then(|block| block.execution_outcome().requests.first().cloned())
.map(Requests::take)
.unwrap_or_default();
let EthBuiltPayload { block, fees, sidecars, requests, .. } = value;

Self {
execution_payload: block_to_payload_v3(block),
block_value: fees,
Expand All @@ -174,7 +178,7 @@ impl From<EthBuiltPayload> for ExecutionPayloadEnvelopeV4 {
// <https://github.com/ethereum/execution-apis/blob/fe8e13c288c592ec154ce25c534e26cb7ce0530d/src/engine/cancun.md#specification-2>
should_override_builder: false,
blobs_bundle: sidecars.into_iter().map(Into::into).collect::<Vec<_>>().into(),
execution_requests,
execution_requests: requests.unwrap_or_default().take(),
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions crates/ethereum/payload/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ where
db.take_bundle(),
vec![receipts].into(),
block_number,
vec![requests.unwrap_or_default()],
vec![requests.clone().unwrap_or_default()],
);
let receipts_root =
execution_outcome.receipts_root_slow(block_number).expect("Number is in range");
Expand Down Expand Up @@ -449,7 +449,8 @@ where
trie: Arc::new(trie_output),
};

let mut payload = EthBuiltPayload::new(attributes.id, sealed_block, total_fees, Some(executed));
let mut payload =
EthBuiltPayload::new(attributes.id, sealed_block, total_fees, Some(executed), requests);

// extend the payload with the blob sidecars from the executed txs
payload.extend_sidecars(blob_sidecars);
Expand Down
10 changes: 9 additions & 1 deletion crates/optimism/payload/src/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//! Optimism builder support
use alloy_eips::eip2718::Decodable2718;
use alloy_eips::{eip2718::Decodable2718, eip7685::Requests};
use alloy_primitives::{Address, B256, U256};
use alloy_rlp::Encodable;
use alloy_rpc_types_engine::{ExecutionPayloadEnvelopeV2, ExecutionPayloadV1, PayloadId};
Expand Down Expand Up @@ -178,6 +178,10 @@ impl BuiltPayload for OptimismBuiltPayload {
fn executed_block(&self) -> Option<ExecutedBlock> {
self.executed_block.clone()
}

fn requests(&self) -> Option<Requests> {
None
}
}

impl BuiltPayload for &OptimismBuiltPayload {
Expand All @@ -192,6 +196,10 @@ impl BuiltPayload for &OptimismBuiltPayload {
fn executed_block(&self) -> Option<ExecutedBlock> {
self.executed_block.clone()
}

fn requests(&self) -> Option<Requests> {
None
}
}

// V1 engine_getPayloadV1 response
Expand Down
2 changes: 1 addition & 1 deletion crates/payload/builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
//! },
//! ..Default::default()
//! };
//! let payload = EthBuiltPayload::new(self.attributes.id, payload.seal_slow(), U256::ZERO, None);
//! let payload = EthBuiltPayload::new(self.attributes.id, payload.seal_slow(), U256::ZERO, None, None);
//! Ok(payload)
//! }
//!
Expand Down
1 change: 1 addition & 0 deletions crates/payload/builder/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ impl PayloadJob for TestPayloadJob {
Block::default().seal_slow(),
U256::ZERO,
Some(ExecutedBlock::default()),
Some(Default::default()),
))
}

Expand Down
1 change: 1 addition & 0 deletions crates/payload/primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ reth-transaction-pool.workspace = true
reth-chain-state.workspace = true

# alloy
alloy-eips.workspace = true
alloy-primitives.workspace = true
alloy-rpc-types = { workspace = true, features = ["engine"] }
op-alloy-rpc-types-engine.workspace = true
Expand Down
4 changes: 4 additions & 0 deletions crates/payload/primitives/src/traits.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::{PayloadEvents, PayloadKind, PayloadTypes};
use alloy_eips::eip7685::Requests;
use alloy_primitives::{Address, B256, U256};
use alloy_rpc_types::{
engine::{PayloadAttributes as EthPayloadAttributes, PayloadId},
Expand Down Expand Up @@ -65,6 +66,9 @@ pub trait BuiltPayload: Send + Sync + std::fmt::Debug {
fn executed_block(&self) -> Option<ExecutedBlock> {
None
}

/// Returns the EIP-7865 requests for the payload if any.
fn requests(&self) -> Option<Requests>;
}

/// This can be implemented by types that describe a currently running payload job.
Expand Down

0 comments on commit e0ad598

Please sign in to comment.