From e4411dd1d6e4975939fb54e17a5469ace2fa0ab9 Mon Sep 17 00:00:00 2001 From: Wodann Date: Wed, 11 Dec 2024 16:59:05 +0000 Subject: [PATCH] fix: L1 block receipt --- crates/edr_eth/src/receipt.rs | 9 +++++++++ crates/edr_eth/src/receipt/block.rs | 12 +++++++++++- crates/edr_eth/src/receipt/transaction.rs | 13 +++++++++---- crates/edr_evm/src/test_utils.rs | 14 +++++++++----- crates/edr_generic/src/rpc/receipt.rs | 6 +++--- crates/edr_optimism/src/receipt/block.rs | 10 +++++++++- crates/edr_optimism/src/rpc/receipt.rs | 10 +++++----- crates/edr_rpc_eth/src/receipt.rs | 8 +++++--- crates/tools/src/remote_block.rs | 10 ++++++++-- 9 files changed, 68 insertions(+), 24 deletions(-) diff --git a/crates/edr_eth/src/receipt.rs b/crates/edr_eth/src/receipt.rs index 266851edd..b72bc6893 100644 --- a/crates/edr_eth/src/receipt.rs +++ b/crates/edr_eth/src/receipt.rs @@ -37,6 +37,15 @@ pub enum RootOrStatus<'root> { Status(bool), } +/// Trait for a receipt that internally contains an execution receipt. +pub trait AsExecutionReceipt { + /// The type of the inner execution receipt. + type ExecutionReceipt: ExecutionReceipt; + + /// Returns a reference to the inner execution receipt. + fn as_execution_receipt(&self) -> &Self::ExecutionReceipt; +} + /// Trait for a receipt that's generated after execution of a transaction. #[auto_impl(Box, Arc)] pub trait ExecutionReceipt { diff --git a/crates/edr_eth/src/receipt/block.rs b/crates/edr_eth/src/receipt/block.rs index adb359d79..1e6ea5c99 100644 --- a/crates/edr_eth/src/receipt/block.rs +++ b/crates/edr_eth/src/receipt/block.rs @@ -2,7 +2,7 @@ use std::ops::Deref; use alloy_rlp::BufMut; -use super::{ExecutionReceipt, ReceiptTrait, RootOrStatus, TransactionReceipt}; +use super::{AsExecutionReceipt, ExecutionReceipt, ReceiptTrait, RootOrStatus, TransactionReceipt}; use crate::{log::FilterLog, Address, Bloom, B256, U256}; /// Type for a receipt that's included in a block. @@ -15,6 +15,16 @@ pub struct BlockReceipt> { pub block_number: u64, } +impl> AsExecutionReceipt + for BlockReceipt +{ + type ExecutionReceipt = ExecutionReceiptT; + + fn as_execution_receipt(&self) -> &ExecutionReceiptT { + self.inner.as_execution_receipt() + } +} + impl> Deref for BlockReceipt { diff --git a/crates/edr_eth/src/receipt/transaction.rs b/crates/edr_eth/src/receipt/transaction.rs index dbbf67f67..dcde91391 100644 --- a/crates/edr_eth/src/receipt/transaction.rs +++ b/crates/edr_eth/src/receipt/transaction.rs @@ -1,6 +1,6 @@ use alloy_rlp::BufMut; -use super::{ExecutionReceipt, MapReceiptLogs}; +use super::{AsExecutionReceipt, ExecutionReceipt, MapReceiptLogs}; use crate::{ l1, result::{ExecutionResult, Output}, @@ -34,12 +34,17 @@ pub struct TransactionReceipt { pub effective_gas_price: Option, } -impl TransactionReceipt { - /// Returns a reference to the inner execution receipt. - pub fn as_execution_receipt(&self) -> &ExecutionReceiptT { +impl AsExecutionReceipt + for TransactionReceipt +{ + type ExecutionReceipt = ExecutionReceiptT; + + fn as_execution_receipt(&self) -> &ExecutionReceiptT { &self.inner } +} +impl TransactionReceipt { /// Converts the instance into the inner execution receipt. pub fn into_execution_receipt(self) -> ExecutionReceiptT { self.inner diff --git a/crates/edr_evm/src/test_utils.rs b/crates/edr_evm/src/test_utils.rs index f03ebe143..ac060ddf0 100644 --- a/crates/edr_evm/src/test_utils.rs +++ b/crates/edr_evm/src/test_utils.rs @@ -5,7 +5,8 @@ use edr_eth::{ account::AccountInfo, block::{miner_reward, BlockOptions}, l1::{self, L1ChainSpec}, - receipt::{ExecutionReceipt as _, ReceiptTrait as _}, + log::FilterLog, + receipt::{AsExecutionReceipt, ExecutionReceipt as _, ReceiptTrait as _}, result::InvalidTransaction, transaction::{TransactionValidation, TxKind}, withdrawal::Withdrawal, @@ -161,7 +162,10 @@ pub async fn run_full_block< ChainSpecT: Debug + SyncRuntimeSpec< BlockEnv: Default, - BlockReceipt: PartialEq, + BlockReceipt: AsExecutionReceipt< + ExecutionReceipt = ChainSpecT::ExecutionReceipt, + >, + ExecutionReceipt: PartialEq, LocalBlock: BlockReceipts< Arc, Error = BlockchainErrorForChainSpec, @@ -350,14 +354,14 @@ pub async fn run_full_block< replay_block.transactions()[expected.transaction_index() as usize] ); debug_assert_eq!( - expected, - *actual, + expected.as_execution_receipt(), + actual.as_execution_receipt(), "{:?}", replay_block.transactions()[expected.transaction_index() as usize] ); } - assert_eq!(mined_header, replay_header); + assert_eq!(replay_header, mined_header); Ok(()) } diff --git a/crates/edr_generic/src/rpc/receipt.rs b/crates/edr_generic/src/rpc/receipt.rs index d16cb4a05..b1dd538de 100644 --- a/crates/edr_generic/src/rpc/receipt.rs +++ b/crates/edr_generic/src/rpc/receipt.rs @@ -1,4 +1,4 @@ -use edr_eth::{l1, log::FilterLog}; +use edr_eth::{l1, log::FilterLog, receipt::AsExecutionReceipt as _}; use edr_rpc_eth::RpcTypeFrom; use serde::{Deserialize, Serialize}; @@ -112,11 +112,11 @@ impl RpcTypeFrom contract_address: value.inner.contract_address, logs: value.inner.transaction_logs().to_vec(), logs_bloom: *value.inner.logs_bloom(), - state_root: match value.inner.as_execution_receipt().data() { + state_root: match value.as_execution_receipt().data() { Execution::Legacy(receipt) => Some(receipt.root), Execution::Eip658(_) => None, }, - status: match value.inner.as_execution_receipt().data() { + status: match value.as_execution_receipt().data() { Execution::Legacy(_) => None, Execution::Eip658(receipt) => Some(receipt.status), }, diff --git a/crates/edr_optimism/src/receipt/block.rs b/crates/edr_optimism/src/receipt/block.rs index 3558665d4..412cedff0 100644 --- a/crates/edr_optimism/src/receipt/block.rs +++ b/crates/edr_optimism/src/receipt/block.rs @@ -1,6 +1,6 @@ use edr_eth::{ log::FilterLog, - receipt::{ExecutionReceipt, ReceiptTrait, RootOrStatus}, + receipt::{AsExecutionReceipt, ExecutionReceipt, ReceiptTrait, RootOrStatus}, Address, Bloom, B256, U256, }; use op_alloy_rpc_types::receipt::L1BlockInfo; @@ -18,6 +18,14 @@ pub struct Block { pub l1_block_info: Option, } +impl AsExecutionReceipt for Block { + type ExecutionReceipt = TypedEnvelope>; + + fn as_execution_receipt(&self) -> &Self::ExecutionReceipt { + self.eth.as_execution_receipt() + } +} + impl alloy_rlp::Encodable for Block { fn encode(&self, out: &mut dyn alloy_rlp::BufMut) { self.eth.encode(out); diff --git a/crates/edr_optimism/src/rpc/receipt.rs b/crates/edr_optimism/src/rpc/receipt.rs index fea7b85c0..278788155 100644 --- a/crates/edr_optimism/src/rpc/receipt.rs +++ b/crates/edr_optimism/src/rpc/receipt.rs @@ -1,5 +1,5 @@ use edr_eth::{ - receipt::{ExecutionReceipt as _, TransactionReceipt}, + receipt::{AsExecutionReceipt as _, ExecutionReceipt as _, TransactionReceipt}, transaction::TransactionType as _, }; use edr_rpc_eth::RpcTypeFrom; @@ -30,21 +30,21 @@ impl RpcTypeFrom for rpc::BlockReceipt { contract_address: value.eth.inner.contract_address, logs: value.eth.inner.transaction_logs().to_vec(), logs_bloom: *value.eth.inner.logs_bloom(), - state_root: match value.eth.inner.as_execution_receipt().data() { + state_root: match value.as_execution_receipt().data() { receipt::Execution::Legacy(receipt) => Some(receipt.root), receipt::Execution::Eip658(_) | receipt::Execution::Deposit(_) => None, }, - status: match value.eth.inner.as_execution_receipt().data() { + status: match value.as_execution_receipt().data() { receipt::Execution::Legacy(_) => None, receipt::Execution::Eip658(receipt) => Some(receipt.status), receipt::Execution::Deposit(receipt) => Some(receipt.status), }, effective_gas_price: value.eth.inner.effective_gas_price, - deposit_nonce: match value.eth.inner.as_execution_receipt().data() { + deposit_nonce: match value.as_execution_receipt().data() { receipt::Execution::Legacy(_) | receipt::Execution::Eip658(_) => None, receipt::Execution::Deposit(receipt) => Some(receipt.deposit_nonce), }, - deposit_receipt_version: match value.eth.inner.as_execution_receipt().data() { + deposit_receipt_version: match value.as_execution_receipt().data() { receipt::Execution::Legacy(_) | receipt::Execution::Eip658(_) => None, receipt::Execution::Deposit(receipt) => receipt.deposit_receipt_version, }, diff --git a/crates/edr_rpc_eth/src/receipt.rs b/crates/edr_rpc_eth/src/receipt.rs index 817d6ac60..b2e504be6 100644 --- a/crates/edr_rpc_eth/src/receipt.rs +++ b/crates/edr_rpc_eth/src/receipt.rs @@ -2,7 +2,9 @@ use edr_eth::{ eips::{eip2718::TypedEnvelope, eip7702}, l1, log::FilterLog, - receipt::{self, Execution, ExecutionReceipt as _, TransactionReceipt}, + receipt::{ + self, AsExecutionReceipt as _, Execution, ExecutionReceipt as _, TransactionReceipt, + }, transaction::{self, TransactionType as _}, Address, Bloom, B256, U256, }; @@ -103,11 +105,11 @@ impl RpcTypeFrom Some(receipt.root), Execution::Eip658(_) => None, }, - status: match value.inner.as_execution_receipt().data() { + status: match value.as_execution_receipt().data() { Execution::Legacy(_) => None, Execution::Eip658(receipt) => Some(receipt.status), }, diff --git a/crates/tools/src/remote_block.rs b/crates/tools/src/remote_block.rs index 5e5678eb1..d6a1d29fa 100644 --- a/crates/tools/src/remote_block.rs +++ b/crates/tools/src/remote_block.rs @@ -2,7 +2,10 @@ use core::fmt::Debug; use std::sync::Arc; use clap::ValueEnum; -use edr_eth::{l1::L1ChainSpec, result::InvalidTransaction, transaction::TransactionValidation}; +use edr_eth::{ + l1::L1ChainSpec, log::FilterLog, receipt::AsExecutionReceipt, result::InvalidTransaction, + transaction::TransactionValidation, +}; use edr_evm::{blockchain::BlockchainErrorForChainSpec, test_utils::run_full_block, BlockReceipts}; use edr_optimism::OptimismChainSpec; use edr_provider::spec::SyncRuntimeSpec; @@ -43,7 +46,10 @@ where ChainSpecT: Debug + SyncRuntimeSpec< BlockEnv: Default, - BlockReceipt: PartialEq, + BlockReceipt: AsExecutionReceipt< + ExecutionReceipt = ChainSpecT::ExecutionReceipt, + >, + ExecutionReceipt: PartialEq, LocalBlock: BlockReceipts< Arc, Error = BlockchainErrorForChainSpec,