Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Extend BuiltPayload type #10583

Merged
merged 9 commits into from
Aug 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions crates/ethereum/engine-primitives/src/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<BlobTransactionSidecar>,
/// The receipts of the block
pub(crate) receipts: Vec<Receipt>,
}

// === 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<Receipt>,
) -> Self {
Self { id, block, fees, sidecars: Vec::new(), receipts }
}

/// Returns the identifier of the payload.
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand Down
8 changes: 5 additions & 3 deletions crates/ethereum/payload/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ where
);
err
})?;

let mut db = State::builder()
.with_database(StateProviderDatabase::new(state))
.with_bundle_update()
Expand Down Expand Up @@ -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()))
}
}

Expand Down Expand Up @@ -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()],
);
Expand Down Expand Up @@ -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<Receipt> = 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);
Expand Down
13 changes: 11 additions & 2 deletions crates/optimism/payload/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,16 @@ 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,
U256::ZERO,
chain_spec,
attributes,
None,
receipts,
))
}
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -601,13 +608,15 @@ where
trie: Arc::new(trie_output),
};

let receipts_pay: Vec<Receipt> = receipts.into_iter().flatten().collect();
let mut payload = OptimismBuiltPayload::new(
attributes.payload_attributes.id,
sealed_block,
total_fees,
chain_spec,
attributes,
Some(executed),
receipts_pay,
);

// extend the payload with the blob sidecars from the executed txs
Expand Down
26 changes: 23 additions & 3 deletions crates/optimism/payload/src/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -179,6 +179,8 @@ pub struct OptimismBuiltPayload {
pub(crate) chain_spec: Arc<ChainSpec>,
/// The payload attributes.
pub(crate) attributes: OptimismPayloadBuilderAttributes,
/// The receipts of the block
pub(crate) receipts: Vec<Receipt>,
}

// === impl BuiltPayload ===
Expand All @@ -192,8 +194,18 @@ impl OptimismBuiltPayload {
chain_spec: Arc<ChainSpec>,
attributes: OptimismPayloadBuilderAttributes,
executed_block: Option<ExecutedBlock>,
receipts: Vec<Receipt>,
) -> 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.
Expand Down Expand Up @@ -229,6 +241,10 @@ impl BuiltPayload for OptimismBuiltPayload {
fn executed_block(&self) -> Option<ExecutedBlock> {
self.executed_block.clone()
}

fn receipts(&self) -> &[Receipt] {
&self.receipts
}
}

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

fn receipts(&self) -> &[Receipt] {
&self.receipts
}
}

// 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);
//! let payload = EthBuiltPayload::new(self.attributes.id, payload.seal_slow(), U256::ZERO, Vec::new());
//! Ok(payload)
//! }
//!
Expand Down
7 changes: 6 additions & 1 deletion crates/payload/builder/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,12 @@ impl PayloadJob for TestPayloadJob {
type BuiltPayload = EthBuiltPayload;

fn best_payload(&self) -> Result<EthBuiltPayload, PayloadBuilderError> {
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<EthPayloadBuilderAttributes, PayloadBuilderError> {
Expand Down
5 changes: 4 additions & 1 deletion crates/payload/primitives/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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<ExecutedBlock> {
None
Expand Down
Loading