Skip to content

Commit

Permalink
fix: L1 block receipt
Browse files Browse the repository at this point in the history
  • Loading branch information
Wodann committed Dec 11, 2024
1 parent 4e6b709 commit e4411dd
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 24 deletions.
9 changes: 9 additions & 0 deletions crates/edr_eth/src/receipt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 11 additions & 1 deletion crates/edr_eth/src/receipt/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -15,6 +15,16 @@ pub struct BlockReceipt<ExecutionReceiptT: ExecutionReceipt<Log = FilterLog>> {
pub block_number: u64,
}

impl<ExecutionReceiptT: ExecutionReceipt<Log = FilterLog>> AsExecutionReceipt
for BlockReceipt<ExecutionReceiptT>
{
type ExecutionReceipt = ExecutionReceiptT;

fn as_execution_receipt(&self) -> &ExecutionReceiptT {
self.inner.as_execution_receipt()
}
}

impl<ExecutionReceiptT: ExecutionReceipt<Log = FilterLog>> Deref
for BlockReceipt<ExecutionReceiptT>
{
Expand Down
13 changes: 9 additions & 4 deletions crates/edr_eth/src/receipt/transaction.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use alloy_rlp::BufMut;

use super::{ExecutionReceipt, MapReceiptLogs};
use super::{AsExecutionReceipt, ExecutionReceipt, MapReceiptLogs};
use crate::{
l1,
result::{ExecutionResult, Output},
Expand Down Expand Up @@ -34,12 +34,17 @@ pub struct TransactionReceipt<ExecutionReceiptT: ExecutionReceipt> {
pub effective_gas_price: Option<U256>,
}

impl<ExecutionReceiptT: ExecutionReceipt> TransactionReceipt<ExecutionReceiptT> {
/// Returns a reference to the inner execution receipt.
pub fn as_execution_receipt(&self) -> &ExecutionReceiptT {
impl<ExecutionReceiptT: ExecutionReceipt> AsExecutionReceipt
for TransactionReceipt<ExecutionReceiptT>
{
type ExecutionReceipt = ExecutionReceiptT;

fn as_execution_receipt(&self) -> &ExecutionReceiptT {
&self.inner
}
}

impl<ExecutionReceiptT: ExecutionReceipt> TransactionReceipt<ExecutionReceiptT> {
/// Converts the instance into the inner execution receipt.
pub fn into_execution_receipt(self) -> ExecutionReceiptT {
self.inner
Expand Down
14 changes: 9 additions & 5 deletions crates/edr_evm/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -161,7 +162,10 @@ pub async fn run_full_block<
ChainSpecT: Debug
+ SyncRuntimeSpec<
BlockEnv: Default,
BlockReceipt: PartialEq,
BlockReceipt: AsExecutionReceipt<
ExecutionReceipt = ChainSpecT::ExecutionReceipt<FilterLog>,
>,
ExecutionReceipt<FilterLog>: PartialEq,
LocalBlock: BlockReceipts<
Arc<ChainSpecT::BlockReceipt>,
Error = BlockchainErrorForChainSpec<ChainSpecT>,
Expand Down Expand Up @@ -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(())
}
Expand Down
6 changes: 3 additions & 3 deletions crates/edr_generic/src/rpc/receipt.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand Down Expand Up @@ -112,11 +112,11 @@ impl RpcTypeFrom<crate::receipt::BlockReceipt<TypedEnvelope<Execution<FilterLog>
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),
},
Expand Down
10 changes: 9 additions & 1 deletion crates/edr_optimism/src/receipt/block.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -18,6 +18,14 @@ pub struct Block {
pub l1_block_info: Option<L1BlockInfo>,
}

impl AsExecutionReceipt for Block {
type ExecutionReceipt = TypedEnvelope<receipt::Execution<FilterLog>>;

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);
Expand Down
10 changes: 5 additions & 5 deletions crates/edr_optimism/src/rpc/receipt.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -30,21 +30,21 @@ impl RpcTypeFrom<receipt::Block> 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,
},
Expand Down
8 changes: 5 additions & 3 deletions crates/edr_rpc_eth/src/receipt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -103,11 +105,11 @@ impl RpcTypeFrom<receipt::BlockReceipt<TypedEnvelope<receipt::Execution<FilterLo
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),
},
Expand Down
10 changes: 8 additions & 2 deletions crates/tools/src/remote_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -43,7 +46,10 @@ where
ChainSpecT: Debug
+ SyncRuntimeSpec<
BlockEnv: Default,
BlockReceipt: PartialEq,
BlockReceipt: AsExecutionReceipt<
ExecutionReceipt = ChainSpecT::ExecutionReceipt<FilterLog>,
>,
ExecutionReceipt<FilterLog>: PartialEq,
LocalBlock: BlockReceipts<
Arc<ChainSpecT::BlockReceipt>,
Error = BlockchainErrorForChainSpec<ChainSpecT>,
Expand Down

0 comments on commit e4411dd

Please sign in to comment.