Skip to content

Commit

Permalink
fix: pull out receipt construction
Browse files Browse the repository at this point in the history
  • Loading branch information
refcell committed Jun 17, 2024
1 parent e58cbcd commit 25e14d8
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 49 deletions.
64 changes: 16 additions & 48 deletions crates/executor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ use alloy_primitives::{address, keccak256, Address, Bytes, TxKind, B256, U256};
use anyhow::{anyhow, Result};
use kona_derive::types::{L2PayloadAttributes, RawTransaction, RollupConfig};
use kona_mpt::{ordered_trie_with_encoder, TrieDB, TrieDBFetcher, TrieDBHinter};
use op_alloy_consensus::{
Decodable2718, Eip658Value, Encodable2718, OpDepositReceipt, OpDepositReceiptWithBloom,
OpReceiptEnvelope, OpTxEnvelope, OpTxType, Receipt, ReceiptWithBloom,
};
use op_alloy_consensus::{Decodable2718, Encodable2718, OpReceiptEnvelope, OpTxEnvelope};
use revm::{
db::{states::bundle_state::BundleRetention, State},
primitives::{
Expand All @@ -33,7 +30,7 @@ mod canyon;
use canyon::ensure_create2_deployer_canyon;

mod util;
use util::{extract_tx_gas_limit, is_system_transaction, logs_bloom};
use util::{extract_tx_gas_limit, is_system_transaction, logs_bloom, receipt_envelope_from_parts};

/// The block executor for the L2 client program. Operates off of a [TrieDB] backed [State],
/// allowing for stateless block execution of OP Stack blocks.
Expand Down Expand Up @@ -196,49 +193,20 @@ where
cumulative_gas_used += result.gas_used();

// Create receipt envelope.
let logs_bloom = logs_bloom(result.logs());
let inner_receipt = Receipt {
status: Eip658Value::Eip658(result.is_success()),
cumulative_gas_used: cumulative_gas_used as u128,
logs: result.into_logs(),
};
let receipt_envelope = match transaction.tx_type() {
OpTxType::Legacy => OpReceiptEnvelope::Legacy(ReceiptWithBloom {
receipt: inner_receipt,
logs_bloom,
}),
OpTxType::Eip2930 => OpReceiptEnvelope::Eip2930(ReceiptWithBloom {
receipt: inner_receipt,
logs_bloom,
}),
OpTxType::Eip1559 => OpReceiptEnvelope::Eip1559(ReceiptWithBloom {
receipt: inner_receipt,
logs_bloom,
}),
OpTxType::Eip4844 => OpReceiptEnvelope::Eip4844(ReceiptWithBloom {
receipt: inner_receipt,
logs_bloom,
}),
OpTxType::Deposit => {
let inner = OpDepositReceiptWithBloom {
receipt: OpDepositReceipt {
inner: inner_receipt,
deposit_nonce: depositor.as_ref().map(|depositor| {
depositor.account_info().unwrap_or_default().nonce
}),
deposit_receipt_version: depositor
.is_some()
.then(|| {
self.config.is_canyon_active(payload.timestamp).then_some(1)
})
.flatten(),
},
logs_bloom,
};
OpReceiptEnvelope::Deposit(inner)
}
};
receipts.push(receipt_envelope);
let receipt = receipt_envelope_from_parts(
result.is_success(),
cumulative_gas_used as u128,
result.logs(),
transaction.tx_type(),
depositor
.as_ref()
.map(|depositor| depositor.account_info().unwrap_or_default().nonce),
depositor
.is_some()
.then(|| self.config.is_canyon_active(payload.timestamp).then_some(1))
.flatten(),
);
receipts.push(receipt);
}

info!(
Expand Down
45 changes: 44 additions & 1 deletion crates/executor/src/util.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,50 @@
//! Contains utilities for the L2 executor.
use alloc::vec::Vec;
use alloy_primitives::{Bloom, Log};
use op_alloy_consensus::{OpTxEnvelope, Transaction};
use op_alloy_consensus::{
Eip658Value, OpDepositReceipt, OpDepositReceiptWithBloom, OpReceiptEnvelope, OpTxEnvelope,
OpTxType, Receipt, ReceiptWithBloom, Transaction,
};

/// Constructs a [OpReceiptEnvelope] from a [Receipt] fields and [OpTxType].
pub(crate) fn receipt_envelope_from_parts<'a>(
status: bool,
cumulative_gas_used: u128,
logs: impl IntoIterator<Item = &'a Log>,
tx_type: OpTxType,
deposit_nonce: Option<u64>,
deposit_receipt_version: Option<u64>,
) -> OpReceiptEnvelope {
let logs = logs.into_iter().cloned().collect::<Vec<_>>();
let logs_bloom = logs_bloom(&logs);
let inner_receipt = Receipt { status: Eip658Value::Eip658(status), cumulative_gas_used, logs };
match tx_type {
OpTxType::Legacy => {
OpReceiptEnvelope::Legacy(ReceiptWithBloom { receipt: inner_receipt, logs_bloom })
}
OpTxType::Eip2930 => {
OpReceiptEnvelope::Eip2930(ReceiptWithBloom { receipt: inner_receipt, logs_bloom })
}
OpTxType::Eip1559 => {
OpReceiptEnvelope::Eip1559(ReceiptWithBloom { receipt: inner_receipt, logs_bloom })
}
OpTxType::Eip4844 => {
OpReceiptEnvelope::Eip4844(ReceiptWithBloom { receipt: inner_receipt, logs_bloom })
}
OpTxType::Deposit => {
let inner = OpDepositReceiptWithBloom {
receipt: OpDepositReceipt {
inner: inner_receipt,
deposit_nonce,
deposit_receipt_version,
},
logs_bloom,
};
OpReceiptEnvelope::Deposit(inner)
}
}
}

/// Compute the logs bloom filter for the given logs.
pub(crate) fn logs_bloom<'a>(logs: impl IntoIterator<Item = &'a Log>) -> Bloom {
Expand Down

0 comments on commit 25e14d8

Please sign in to comment.