dev: add requests to EthBuiltPayload (#12072)

This commit is contained in:
greged93
2024-10-26 08:10:15 +02:00
committed by GitHub
parent fa59bd512e
commit e0ad59834d
9 changed files with 36 additions and 23 deletions

3
Cargo.lock generated
View File

@ -8373,6 +8373,7 @@ dependencies = [
name = "reth-payload-primitives" name = "reth-payload-primitives"
version = "1.1.0" version = "1.1.0"
dependencies = [ dependencies = [
"alloy-eips",
"alloy-primitives", "alloy-primitives",
"alloy-rpc-types", "alloy-rpc-types",
"async-trait", "async-trait",
@ -11956,4 +11957,4 @@ checksum = "38ff0f21cfee8f97d94cef41359e0c89aa6113028ab0291aa8ca0038995a95aa"
dependencies = [ dependencies = [
"cc", "cc",
"pkg-config", "pkg-config",
] ]

View File

@ -62,14 +62,7 @@ impl<E: EngineTypes, ChainSpec: EthereumHardforks> EngineApiTestContext<E, Chain
.chain_spec .chain_spec
.is_prague_active_at_timestamp(payload_builder_attributes.timestamp()) .is_prague_active_at_timestamp(payload_builder_attributes.timestamp())
{ {
let requests = payload let requests = payload.requests().unwrap();
.executed_block()
.unwrap()
.execution_outcome()
.requests
.first()
.unwrap()
.clone();
let envelope: <E as EngineTypes>::ExecutionPayloadEnvelopeV4 = payload.into(); let envelope: <E as EngineTypes>::ExecutionPayloadEnvelopeV4 = payload.into();
EngineApiClient::<E>::new_payload_v4( EngineApiClient::<E>::new_payload_v4(
&self.engine_api_client, &self.engine_api_client,

View File

@ -33,6 +33,8 @@ pub struct EthBuiltPayload {
/// The blobs, proofs, and commitments in the block. If the block is pre-cancun, this will be /// The blobs, proofs, and commitments in the block. If the block is pre-cancun, this will be
/// empty. /// empty.
pub(crate) sidecars: Vec<BlobTransactionSidecar>, pub(crate) sidecars: Vec<BlobTransactionSidecar>,
/// The requests of the payload
pub(crate) requests: Option<Requests>,
} }
// === impl BuiltPayload === // === impl BuiltPayload ===
@ -46,8 +48,9 @@ impl EthBuiltPayload {
block: SealedBlock, block: SealedBlock,
fees: U256, fees: U256,
executed_block: Option<ExecutedBlock>, executed_block: Option<ExecutedBlock>,
requests: Option<Requests>,
) -> Self { ) -> 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. /// Returns the identifier of the payload.
@ -97,6 +100,10 @@ impl BuiltPayload for EthBuiltPayload {
fn executed_block(&self) -> Option<ExecutedBlock> { fn executed_block(&self) -> Option<ExecutedBlock> {
self.executed_block.clone() self.executed_block.clone()
} }
fn requests(&self) -> Option<Requests> {
self.requests.clone()
}
} }
impl BuiltPayload for &EthBuiltPayload { impl BuiltPayload for &EthBuiltPayload {
@ -111,6 +118,10 @@ impl BuiltPayload for &EthBuiltPayload {
fn executed_block(&self) -> Option<ExecutedBlock> { fn executed_block(&self) -> Option<ExecutedBlock> {
self.executed_block.clone() self.executed_block.clone()
} }
fn requests(&self) -> Option<Requests> {
self.requests.clone()
}
} }
// V1 engine_getPayloadV1 response // V1 engine_getPayloadV1 response
@ -152,15 +163,8 @@ impl From<EthBuiltPayload> for ExecutionPayloadEnvelopeV3 {
impl From<EthBuiltPayload> for ExecutionPayloadEnvelopeV4 { impl From<EthBuiltPayload> for ExecutionPayloadEnvelopeV4 {
fn from(value: EthBuiltPayload) -> Self { fn from(value: EthBuiltPayload) -> Self {
let EthBuiltPayload { block, fees, sidecars, executed_block, .. } = value; let EthBuiltPayload { block, fees, sidecars, requests, .. } = 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();
Self { Self {
execution_payload: block_to_payload_v3(block), execution_payload: block_to_payload_v3(block),
block_value: fees, block_value: fees,
@ -174,7 +178,7 @@ impl From<EthBuiltPayload> for ExecutionPayloadEnvelopeV4 {
// <https://github.com/ethereum/execution-apis/blob/fe8e13c288c592ec154ce25c534e26cb7ce0530d/src/engine/cancun.md#specification-2> // <https://github.com/ethereum/execution-apis/blob/fe8e13c288c592ec154ce25c534e26cb7ce0530d/src/engine/cancun.md#specification-2>
should_override_builder: false, should_override_builder: false,
blobs_bundle: sidecars.into_iter().map(Into::into).collect::<Vec<_>>().into(), blobs_bundle: sidecars.into_iter().map(Into::into).collect::<Vec<_>>().into(),
execution_requests, execution_requests: requests.unwrap_or_default().take(),
} }
} }
} }

View File

@ -360,7 +360,7 @@ where
db.take_bundle(), db.take_bundle(),
vec![receipts].into(), vec![receipts].into(),
block_number, block_number,
vec![requests.unwrap_or_default()], vec![requests.clone().unwrap_or_default()],
); );
let receipts_root = let receipts_root =
execution_outcome.receipts_root_slow(block_number).expect("Number is in range"); execution_outcome.receipts_root_slow(block_number).expect("Number is in range");
@ -449,7 +449,8 @@ where
trie: Arc::new(trie_output), 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 // extend the payload with the blob sidecars from the executed txs
payload.extend_sidecars(blob_sidecars); payload.extend_sidecars(blob_sidecars);

View File

@ -2,7 +2,7 @@
//! Optimism builder support //! Optimism builder support
use alloy_eips::eip2718::Decodable2718; use alloy_eips::{eip2718::Decodable2718, eip7685::Requests};
use alloy_primitives::{Address, B256, U256}; use alloy_primitives::{Address, B256, U256};
use alloy_rlp::Encodable; use alloy_rlp::Encodable;
use alloy_rpc_types_engine::{ExecutionPayloadEnvelopeV2, ExecutionPayloadV1, PayloadId}; use alloy_rpc_types_engine::{ExecutionPayloadEnvelopeV2, ExecutionPayloadV1, PayloadId};
@ -178,6 +178,10 @@ impl BuiltPayload for OptimismBuiltPayload {
fn executed_block(&self) -> Option<ExecutedBlock> { fn executed_block(&self) -> Option<ExecutedBlock> {
self.executed_block.clone() self.executed_block.clone()
} }
fn requests(&self) -> Option<Requests> {
None
}
} }
impl BuiltPayload for &OptimismBuiltPayload { impl BuiltPayload for &OptimismBuiltPayload {
@ -192,6 +196,10 @@ impl BuiltPayload for &OptimismBuiltPayload {
fn executed_block(&self) -> Option<ExecutedBlock> { fn executed_block(&self) -> Option<ExecutedBlock> {
self.executed_block.clone() self.executed_block.clone()
} }
fn requests(&self) -> Option<Requests> {
None
}
} }
// V1 engine_getPayloadV1 response // V1 engine_getPayloadV1 response

View File

@ -65,7 +65,7 @@
//! }, //! },
//! ..Default::default() //! ..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) //! Ok(payload)
//! } //! }
//! //!

View File

@ -89,6 +89,7 @@ impl PayloadJob for TestPayloadJob {
Block::default().seal_slow(), Block::default().seal_slow(),
U256::ZERO, U256::ZERO,
Some(ExecutedBlock::default()), Some(ExecutedBlock::default()),
Some(Default::default()),
)) ))
} }

View File

@ -20,6 +20,7 @@ reth-transaction-pool.workspace = true
reth-chain-state.workspace = true reth-chain-state.workspace = true
# alloy # alloy
alloy-eips.workspace = true
alloy-primitives.workspace = true alloy-primitives.workspace = true
alloy-rpc-types = { workspace = true, features = ["engine"] } alloy-rpc-types = { workspace = true, features = ["engine"] }
op-alloy-rpc-types-engine.workspace = true op-alloy-rpc-types-engine.workspace = true

View File

@ -1,4 +1,5 @@
use crate::{PayloadEvents, PayloadKind, PayloadTypes}; use crate::{PayloadEvents, PayloadKind, PayloadTypes};
use alloy_eips::eip7685::Requests;
use alloy_primitives::{Address, B256, U256}; use alloy_primitives::{Address, B256, U256};
use alloy_rpc_types::{ use alloy_rpc_types::{
engine::{PayloadAttributes as EthPayloadAttributes, PayloadId}, engine::{PayloadAttributes as EthPayloadAttributes, PayloadId},
@ -65,6 +66,9 @@ pub trait BuiltPayload: Send + Sync + std::fmt::Debug {
fn executed_block(&self) -> Option<ExecutedBlock> { fn executed_block(&self) -> Option<ExecutedBlock> {
None 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. /// This can be implemented by types that describe a currently running payload job.