From 17f6225fa5e603fe5bb89f8ab356bf7d1e77ec59 Mon Sep 17 00:00:00 2001 From: malik Date: Sat, 31 Aug 2024 18:27:12 +0100 Subject: [PATCH] Feat: Extend BuiltPayload type (#10583) Co-authored-by: Oliver --- .../ethereum/engine-primitives/src/payload.rs | 21 ++++++++++++--- crates/ethereum/payload/src/lib.rs | 8 +++--- crates/optimism/payload/src/builder.rs | 13 ++++++++-- crates/optimism/payload/src/payload.rs | 26 ++++++++++++++++--- crates/payload/builder/src/lib.rs | 2 +- crates/payload/builder/src/test_utils.rs | 7 ++++- crates/payload/primitives/src/traits.rs | 5 +++- 7 files changed, 68 insertions(+), 14 deletions(-) diff --git a/crates/ethereum/engine-primitives/src/payload.rs b/crates/ethereum/engine-primitives/src/payload.rs index 45514d4d44..7de1205304 100644 --- a/crates/ethereum/engine-primitives/src/payload.rs +++ b/crates/ethereum/engine-primitives/src/payload.rs @@ -6,7 +6,7 @@ use reth_evm_ethereum::revm_spec_by_timestamp_after_merge; use reth_payload_primitives::{BuiltPayload, PayloadBuilderAttributes}; use reth_primitives::{ constants::EIP1559_INITIAL_BASE_FEE, Address, BlobTransactionSidecar, EthereumHardfork, Header, - SealedBlock, Withdrawals, B256, U256, + Receipt, SealedBlock, Withdrawals, B256, U256, }; use reth_rpc_types::engine::{ ExecutionPayloadEnvelopeV2, ExecutionPayloadEnvelopeV3, ExecutionPayloadEnvelopeV4, @@ -35,14 +35,21 @@ 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, + /// The receipts of the block + pub(crate) receipts: Vec, } // === impl BuiltPayload === impl EthBuiltPayload { /// Initializes the payload with the given initial block. - pub const fn new(id: PayloadId, block: SealedBlock, fees: U256) -> Self { - Self { id, block, fees, sidecars: Vec::new() } + pub const fn new( + id: PayloadId, + block: SealedBlock, + fees: U256, + receipts: Vec, + ) -> Self { + Self { id, block, fees, sidecars: Vec::new(), receipts } } /// Returns the identifier of the payload. @@ -79,6 +86,10 @@ impl BuiltPayload for EthBuiltPayload { fn fees(&self) -> U256 { self.fees } + + fn receipts(&self) -> &[Receipt] { + &self.receipts + } } impl<'a> BuiltPayload for &'a EthBuiltPayload { @@ -89,6 +100,10 @@ impl<'a> BuiltPayload for &'a EthBuiltPayload { fn fees(&self) -> U256 { (**self).fees() } + + fn receipts(&self) -> &[Receipt] { + &self.receipts + } } // V1 engine_getPayloadV1 response diff --git a/crates/ethereum/payload/src/lib.rs b/crates/ethereum/payload/src/lib.rs index 2e9a2fdaed..5707d97dde 100644 --- a/crates/ethereum/payload/src/lib.rs +++ b/crates/ethereum/payload/src/lib.rs @@ -109,6 +109,7 @@ where ); err })?; + let mut db = State::builder() .with_database(StateProviderDatabase::new(state)) .with_bundle_update() @@ -254,7 +255,7 @@ where let block = Block { header, body: vec![], ommers: vec![], withdrawals, requests }; let sealed_block = block.seal_slow(); - Ok(EthBuiltPayload::new(attributes.payload_id(), sealed_block, U256::ZERO)) + Ok(EthBuiltPayload::new(attributes.payload_id(), sealed_block, U256::ZERO, Vec::new())) } } @@ -490,7 +491,7 @@ where let execution_outcome = ExecutionOutcome::new( db.take_bundle(), - vec![receipts].into(), + vec![receipts.clone()].into(), block_number, vec![requests.clone().unwrap_or_default()], ); @@ -564,7 +565,8 @@ where let sealed_block = block.seal_slow(); debug!(target: "payload_builder", ?sealed_block, "sealed built block"); - let mut payload = EthBuiltPayload::new(attributes.id, sealed_block, total_fees); + let receipts_pay: Vec = receipts.into_iter().flatten().collect(); + let mut payload = EthBuiltPayload::new(attributes.id, sealed_block, total_fees, receipts_pay); // extend the payload with the blob sidecars from the executed txs payload.extend_sidecars(blob_sidecars); diff --git a/crates/optimism/payload/src/builder.rs b/crates/optimism/payload/src/builder.rs index db9ffc29eb..c985ae8453 100644 --- a/crates/optimism/payload/src/builder.rs +++ b/crates/optimism/payload/src/builder.rs @@ -209,6 +209,8 @@ where let block = Block { header, body: vec![], ommers: vec![], withdrawals, requests: None }; let sealed_block = block.seal_slow(); + let receipts = Vec::new(); + Ok(OptimismBuiltPayload::new( attributes.payload_attributes.payload_id(), sealed_block, @@ -216,6 +218,7 @@ where chain_spec, attributes, None, + receipts, )) } } @@ -515,8 +518,12 @@ where // and 4788 contract call db.merge_transitions(BundleRetention::PlainState); - let execution_outcome = - ExecutionOutcome::new(db.take_bundle(), vec![receipts].into(), block_number, Vec::new()); + let execution_outcome = ExecutionOutcome::new( + db.take_bundle(), + vec![receipts.clone()].into(), + block_number, + Vec::new(), + ); let receipts_root = execution_outcome .optimism_receipts_root_slow( block_number, @@ -601,6 +608,7 @@ where trie: Arc::new(trie_output), }; + let receipts_pay: Vec = receipts.into_iter().flatten().collect(); let mut payload = OptimismBuiltPayload::new( attributes.payload_attributes.id, sealed_block, @@ -608,6 +616,7 @@ where chain_spec, attributes, Some(executed), + receipts_pay, ); // extend the payload with the blob sidecars from the executed txs diff --git a/crates/optimism/payload/src/payload.rs b/crates/optimism/payload/src/payload.rs index 1746b66493..df38c60ea9 100644 --- a/crates/optimism/payload/src/payload.rs +++ b/crates/optimism/payload/src/payload.rs @@ -11,8 +11,8 @@ use reth_payload_primitives::{BuiltPayload, PayloadBuilderAttributes}; use reth_primitives::{ revm_primitives::{BlobExcessGasAndPrice, BlockEnv, CfgEnv, CfgEnvWithHandlerCfg, SpecId}, transaction::WithEncoded, - Address, BlobTransactionSidecar, Header, SealedBlock, TransactionSigned, Withdrawals, B256, - U256, + Address, BlobTransactionSidecar, Header, Receipt, SealedBlock, TransactionSigned, Withdrawals, + B256, U256, }; /// Re-export for use in downstream arguments. pub use reth_rpc_types::optimism::OptimismPayloadAttributes; @@ -179,6 +179,8 @@ pub struct OptimismBuiltPayload { pub(crate) chain_spec: Arc, /// The payload attributes. pub(crate) attributes: OptimismPayloadBuilderAttributes, + /// The receipts of the block + pub(crate) receipts: Vec, } // === impl BuiltPayload === @@ -192,8 +194,18 @@ impl OptimismBuiltPayload { chain_spec: Arc, attributes: OptimismPayloadBuilderAttributes, executed_block: Option, + receipts: Vec, ) -> Self { - Self { id, block, executed_block, fees, sidecars: Vec::new(), chain_spec, attributes } + Self { + id, + block, + executed_block, + fees, + sidecars: Vec::new(), + chain_spec, + attributes, + receipts, + } } /// Returns the identifier of the payload. @@ -229,6 +241,10 @@ impl BuiltPayload for OptimismBuiltPayload { fn executed_block(&self) -> Option { self.executed_block.clone() } + + fn receipts(&self) -> &[Receipt] { + &self.receipts + } } impl<'a> BuiltPayload for &'a OptimismBuiltPayload { @@ -243,6 +259,10 @@ impl<'a> BuiltPayload for &'a OptimismBuiltPayload { fn executed_block(&self) -> Option { self.executed_block.clone() } + + fn receipts(&self) -> &[Receipt] { + &self.receipts + } } // V1 engine_getPayloadV1 response diff --git a/crates/payload/builder/src/lib.rs b/crates/payload/builder/src/lib.rs index 2a29fe916e..fc74c21a15 100644 --- a/crates/payload/builder/src/lib.rs +++ b/crates/payload/builder/src/lib.rs @@ -65,7 +65,7 @@ //! }, //! ..Default::default() //! }; -//! let payload = EthBuiltPayload::new(self.attributes.id, payload.seal_slow(), U256::ZERO); +//! let payload = EthBuiltPayload::new(self.attributes.id, payload.seal_slow(), U256::ZERO, Vec::new()); //! Ok(payload) //! } //! diff --git a/crates/payload/builder/src/test_utils.rs b/crates/payload/builder/src/test_utils.rs index 62f697ddd6..c854fce738 100644 --- a/crates/payload/builder/src/test_utils.rs +++ b/crates/payload/builder/src/test_utils.rs @@ -82,7 +82,12 @@ impl PayloadJob for TestPayloadJob { type BuiltPayload = EthBuiltPayload; fn best_payload(&self) -> Result { - Ok(EthBuiltPayload::new(self.attr.payload_id(), Block::default().seal_slow(), U256::ZERO)) + Ok(EthBuiltPayload::new( + self.attr.payload_id(), + Block::default().seal_slow(), + U256::ZERO, + Vec::new(), + )) } fn payload_attributes(&self) -> Result { diff --git a/crates/payload/primitives/src/traits.rs b/crates/payload/primitives/src/traits.rs index 80ae38127e..c3d011f7ef 100644 --- a/crates/payload/primitives/src/traits.rs +++ b/crates/payload/primitives/src/traits.rs @@ -2,7 +2,7 @@ use reth_chain_state::ExecutedBlock; use reth_chainspec::ChainSpec; use reth_primitives::{ revm_primitives::{BlockEnv, CfgEnvWithHandlerCfg}, - Address, Header, SealedBlock, Withdrawals, B256, U256, + Address, Header, Receipt, SealedBlock, Withdrawals, B256, U256, }; use reth_rpc_types::{ engine::{PayloadAttributes as EthPayloadAttributes, PayloadId}, @@ -23,6 +23,9 @@ pub trait BuiltPayload: Send + Sync + std::fmt::Debug { /// Returns the fees collected for the built block fn fees(&self) -> U256; + /// Returns the Receipts + fn receipts(&self) -> &[Receipt]; + /// Returns the entire execution data for the built block, if available. fn executed_block(&self) -> Option { None