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: abstract OP payload builder over transaction #14153

Merged
merged 5 commits into from
Feb 3, 2025
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
1 change: 1 addition & 0 deletions Cargo.lock

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

16 changes: 0 additions & 16 deletions crates/ethereum/engine-primitives/src/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,22 +98,6 @@ impl BuiltPayload for EthBuiltPayload {
}
}

impl BuiltPayload for &EthBuiltPayload {
type Primitives = EthPrimitives;

fn block(&self) -> &SealedBlock {
(**self).block()
}

fn fees(&self) -> U256 {
(**self).fees()
}

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

// V1 engine_getPayloadV1 response
impl From<EthBuiltPayload> for ExecutionPayloadV1 {
fn from(value: EthBuiltPayload) -> Self {
Expand Down
14 changes: 7 additions & 7 deletions crates/optimism/consensus/src/proof.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
//! Helper function for Receipt root calculation for Optimism hardforks.

use alloc::vec::Vec;
use alloy_consensus::TxReceipt;
use alloy_eips::eip2718::Encodable2718;
use alloy_primitives::B256;
use alloy_trie::root::ordered_trie_root_with_encoder;
use reth_chainspec::ChainSpec;
use reth_optimism_forks::{OpHardfork, OpHardforks};
use reth_optimism_primitives::{DepositReceipt, OpReceipt};
use reth_optimism_primitives::DepositReceipt;
use reth_primitives::ReceiptWithBloom;

/// Calculates the receipt root for a header.
Expand Down Expand Up @@ -41,11 +40,11 @@ pub(crate) fn calculate_receipt_root_optimism<R: DepositReceipt>(
ordered_trie_root_with_encoder(receipts, |r, buf| r.encode_2718(buf))
}

/// Calculates the receipt root for a header for the reference type of [`OpReceipt`].
/// Calculates the receipt root for a header for the reference type of an OP receipt.
///
/// NOTE: Prefer calculate receipt root optimism if you have log blooms memoized.
pub fn calculate_receipt_root_no_memo_optimism(
receipts: &[OpReceipt],
pub fn calculate_receipt_root_no_memo_optimism<R: DepositReceipt>(
receipts: &[R],
chain_spec: impl OpHardforks,
timestamp: u64,
) -> B256 {
Expand All @@ -61,8 +60,8 @@ pub fn calculate_receipt_root_no_memo_optimism(
.iter()
.map(|r| {
let mut r = (*r).clone();
if let OpReceipt::Deposit(r) = &mut r {
r.deposit_nonce = None;
if let Some(receipt) = r.as_deposit_receipt_mut() {
receipt.deposit_nonce = None;
}
r
})
Expand All @@ -85,6 +84,7 @@ mod tests {
use alloy_primitives::{b256, bloom, hex, Address, Bloom, Bytes, Log, LogData};
use op_alloy_consensus::OpDepositReceipt;
use reth_optimism_chainspec::BASE_SEPOLIA;
use reth_optimism_primitives::OpReceipt;
use reth_primitives::ReceiptWithBloom;

/// Tests that the receipt root is computed correctly for the regolith block.
Expand Down
1 change: 0 additions & 1 deletion crates/optimism/evm/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,6 @@ where

receipts.push(
match self.receipt_builder.build_receipt(ReceiptBuilderCtx {
header: block.header(),
tx: transaction,
result,
cumulative_gas_used,
Expand Down
4 changes: 1 addition & 3 deletions crates/optimism/evm/src/receipts.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use alloy_consensus::{Eip658Value, Header, Receipt};
use alloy_consensus::{Eip658Value, Receipt};
use core::fmt;
use op_alloy_consensus::{OpDepositReceipt, OpTxType};
use reth_optimism_primitives::{OpReceipt, OpTransactionSigned};
Expand All @@ -7,8 +7,6 @@ use revm_primitives::ExecutionResult;
/// Context for building a receipt.
#[derive(Debug)]
pub struct ReceiptBuilderCtx<'a, T> {
/// Block header.
pub header: &'a Header,
/// Transaction
pub tx: &'a T,
/// Result of transaction execution.
Expand Down
10 changes: 5 additions & 5 deletions crates/optimism/node/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use reth_node_api::{
use reth_optimism_chainspec::OpChainSpec;
use reth_optimism_forks::{OpHardfork, OpHardforks};
use reth_optimism_payload_builder::{OpBuiltPayload, OpPayloadBuilderAttributes};
use reth_optimism_primitives::OpBlock;
use reth_optimism_primitives::{OpBlock, OpPrimitives};
use reth_payload_validator::ExecutionPayloadValidator;
use reth_primitives::SealedBlock;
use std::sync::Arc;
Expand Down Expand Up @@ -61,12 +61,12 @@ where
/// A default payload type for [`OpEngineTypes`]
#[derive(Debug, Default, Clone, serde::Deserialize, serde::Serialize)]
#[non_exhaustive]
pub struct OpPayloadTypes;
pub struct OpPayloadTypes<N: NodePrimitives = OpPrimitives>(core::marker::PhantomData<N>);

impl PayloadTypes for OpPayloadTypes {
type BuiltPayload = OpBuiltPayload;
impl<N: NodePrimitives> PayloadTypes for OpPayloadTypes<N> {
type BuiltPayload = OpBuiltPayload<N>;
type PayloadAttributes = OpPayloadAttributes;
type PayloadBuilderAttributes = OpPayloadBuilderAttributes;
type PayloadBuilderAttributes = OpPayloadBuilderAttributes<N::SignedTx>;
}

/// Validator for Optimism engine API.
Expand Down
13 changes: 10 additions & 3 deletions crates/optimism/node/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use reth_node_builder::{
};
use reth_optimism_chainspec::OpChainSpec;
use reth_optimism_consensus::OpBeaconConsensus;
use reth_optimism_evm::{OpEvmConfig, OpExecutionStrategyFactory};
use reth_optimism_evm::{BasicOpReceiptBuilder, OpEvmConfig, OpExecutionStrategyFactory};
use reth_optimism_payload_builder::{
builder::OpPayloadTransactions,
config::{OpBuilderConfig, OpDAConfig},
Expand Down Expand Up @@ -205,11 +205,16 @@ where
ctx: reth_node_api::AddOnsContext<'_, N>,
) -> eyre::Result<Self::Handle> {
let Self { rpc_add_ons, da_config } = self;

let builder = reth_optimism_payload_builder::OpPayloadBuilder::new(
ctx.node.evm_config().clone(),
BasicOpReceiptBuilder::default(),
);
// install additional OP specific rpc methods
let debug_ext = OpDebugWitnessApi::new(
ctx.node.provider().clone(),
ctx.node.evm_config().clone(),
Box::new(ctx.node.task_executor().clone()),
builder,
);
let miner_ext = OpMinerExtApi::new(da_config);

Expand Down Expand Up @@ -493,9 +498,11 @@ where
+ Unpin
+ 'static,
Evm: ConfigureEvmFor<PrimitivesTy<Node::Types>>,
Txs: OpPayloadTransactions<TxTy<Node::Types>>,
{
let payload_builder = reth_optimism_payload_builder::OpPayloadBuilder::with_builder_config(
evm_config,
BasicOpReceiptBuilder::default(),
OpBuilderConfig { da_config: self.da_config },
)
.with_transactions(self.best_transactions)
Expand Down Expand Up @@ -535,7 +542,7 @@ where
Pool: TransactionPool<Transaction: PoolTransaction<Consensus = TxTy<Node::Types>>>
+ Unpin
+ 'static,
Txs: OpPayloadTransactions,
Txs: OpPayloadTransactions<TxTy<Node::Types>>,
{
async fn spawn_payload_service(
self,
Expand Down
5 changes: 3 additions & 2 deletions crates/optimism/node/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use reth_e2e_test_utils::{
};
use reth_node_api::NodeTypesWithDBAdapter;
use reth_optimism_chainspec::OpChainSpecBuilder;
use reth_optimism_primitives::OpTransactionSigned;
use reth_payload_builder::EthPayloadBuilderAttributes;
use reth_provider::providers::BlockchainProvider;
use reth_tasks::TaskManager;
Expand Down Expand Up @@ -35,7 +36,7 @@ pub async fn advance_chain(
length: usize,
node: &mut OpNode,
wallet: Arc<Mutex<Wallet>>,
) -> eyre::Result<Vec<(OpBuiltPayload, OpPayloadBuilderAttributes)>> {
) -> eyre::Result<Vec<(OpBuiltPayload, OpPayloadBuilderAttributes<OpTransactionSigned>)>> {
node.advance(length as u64, |_| {
let wallet = wallet.clone();
Box::pin(async move {
Expand All @@ -53,7 +54,7 @@ pub async fn advance_chain(
}

/// Helper function to create a new eth payload attributes
pub fn optimism_payload_attributes(timestamp: u64) -> OpPayloadBuilderAttributes {
pub fn optimism_payload_attributes<T>(timestamp: u64) -> OpPayloadBuilderAttributes<T> {
let attributes = PayloadAttributes {
timestamp,
prev_randao: B256::ZERO,
Expand Down
Loading
Loading