diff --git a/Cargo.toml b/Cargo.toml index 2dc2eee5..69625294 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -59,10 +59,6 @@ alloy = { version = "1.0.19", features = [ ] } alloy-contract = { version = "1.0.19", features = ["pubsub"] } -# Reth -reth = { git = "https://github.com/paradigmxyz/reth", tag = "v1.5.1" } -reth-exex = { git = "https://github.com/paradigmxyz/reth", tag = "v1.5.1" } - # Async tokio = { version = "1.43.0", features = ["macros"] } async-trait = "0.1.87" diff --git a/crates/test-utils/Cargo.toml b/crates/test-utils/Cargo.toml index 91908e3c..9ec1e481 100644 --- a/crates/test-utils/Cargo.toml +++ b/crates/test-utils/Cargo.toml @@ -21,8 +21,8 @@ trevm = { workspace = true, features = ["test-utils"] } alloy.workspace = true -reth.workspace = true -reth-exex.workspace = true - tracing-subscriber.workspace = true -tokio.workspace = true \ No newline at end of file +tokio.workspace = true + +[dev-dependencies] +tracing-subscriber = { workspace = true, features = ["env-filter"] } \ No newline at end of file diff --git a/crates/test-utils/src/convert.rs b/crates/test-utils/src/convert.rs deleted file mode 100644 index abfa6a0c..00000000 --- a/crates/test-utils/src/convert.rs +++ /dev/null @@ -1,99 +0,0 @@ -//! Bespoke conversion utilities for converting between alloy and reth types. - -use alloy::consensus::ReceiptEnvelope; -use signet_evm::ExecutionOutcome; -use signet_types::primitives::{RecoveredBlock, SealedBlock}; - -/// Utility trait to convert a type to a Reth primitive type. -/// This is used mainly where we need to convert to a reth primitive type -/// because reth does not support the alloy equivalents. -pub trait ToRethPrimitive { - /// The Reth primitive type that the type can be converted to. - type RethPrimitive; - - /// Convert the type to a Reth primitive type. - fn to_reth(self) -> Self::RethPrimitive; -} - -// Reth does not preserve envelope status for receipts, so -// the DB model will not support envelopes. -impl ToRethPrimitive for ReceiptEnvelope { - type RethPrimitive = reth::primitives::Receipt; - - fn to_reth(self) -> Self::RethPrimitive { - let success = self.is_success(); - let cumulative_gas_used = self.cumulative_gas_used(); - let tx_type = match self.tx_type() { - alloy::consensus::TxType::Legacy => reth::primitives::TxType::Legacy, - alloy::consensus::TxType::Eip2930 => reth::primitives::TxType::Eip2930, - alloy::consensus::TxType::Eip1559 => reth::primitives::TxType::Eip1559, - alloy::consensus::TxType::Eip4844 => reth::primitives::TxType::Eip4844, - alloy::consensus::TxType::Eip7702 => reth::primitives::TxType::Eip7702, - }; - - let r = match self { - ReceiptEnvelope::Legacy(r) - | ReceiptEnvelope::Eip2930(r) - | ReceiptEnvelope::Eip1559(r) - | ReceiptEnvelope::Eip4844(r) => r, - _ => panic!("unsupported receipt type"), - }; - - reth::primitives::Receipt { tx_type, success, cumulative_gas_used, logs: r.receipt.logs } - } -} - -impl ToRethPrimitive for SealedBlock { - type RethPrimitive = reth::primitives::SealedBlock; - - fn to_reth(self) -> Self::RethPrimitive { - let (hash, header) = self.header.split(); - reth::primitives::SealedBlock::new_unchecked( - reth::primitives::Block::new(header, self.body), - hash, - ) - } -} - -impl ToRethPrimitive for RecoveredBlock { - type RethPrimitive = reth::primitives::RecoveredBlock; - - fn to_reth(self) -> Self::RethPrimitive { - let hash = self.block.header.hash(); - reth::primitives::RecoveredBlock::new(self.block.to_reth().into_block(), self.senders, hash) - } -} - -impl ToRethPrimitive for crate::chain::Chain { - type RethPrimitive = reth::providers::Chain; - - fn to_reth(self) -> Self::RethPrimitive { - reth::providers::Chain::new(self.blocks.to_reth(), self.execution_outcome.to_reth(), None) - } -} - -impl ToRethPrimitive for Vec -where - T: ToRethPrimitive, -{ - type RethPrimitive = Vec; - - fn to_reth(self) -> Self::RethPrimitive { - self.into_iter().map(ToRethPrimitive::to_reth).collect() - } -} - -impl ToRethPrimitive for ExecutionOutcome { - type RethPrimitive = reth::providers::ExecutionOutcome; - - fn to_reth(self) -> Self::RethPrimitive { - let (bundle, receipts, first_block) = self.into_parts(); - - reth::providers::ExecutionOutcome { - bundle, - receipts: receipts.into_iter().map(ToRethPrimitive::to_reth).collect(), - first_block, - requests: vec![], - } - } -} diff --git a/crates/test-utils/src/evm.rs b/crates/test-utils/src/evm.rs index cf209e2c..7ccc1efd 100644 --- a/crates/test-utils/src/evm.rs +++ b/crates/test-utils/src/evm.rs @@ -1,6 +1,7 @@ -use reth::revm::context::CfgEnv; use signet_constants::test_utils::*; -use trevm::revm::{database::in_memory_db::InMemoryDB, primitives::hardfork::SpecId}; +use trevm::revm::{ + context::CfgEnv, database::in_memory_db::InMemoryDB, primitives::hardfork::SpecId, +}; /// Create a new Signet EVM with an in-memory database for testing. pub fn test_signet_evm() -> signet_evm::EvmNeedsBlock { diff --git a/crates/test-utils/src/lib.rs b/crates/test-utils/src/lib.rs index 905af884..3ade66c3 100644 --- a/crates/test-utils/src/lib.rs +++ b/crates/test-utils/src/lib.rs @@ -1,5 +1,4 @@ pub mod chain; -pub mod convert; pub mod evm; pub mod specs; pub mod users; diff --git a/crates/test-utils/src/specs/notif_spec.rs b/crates/test-utils/src/specs/notif_spec.rs index 69a3855e..24dd71d3 100644 --- a/crates/test-utils/src/specs/notif_spec.rs +++ b/crates/test-utils/src/specs/notif_spec.rs @@ -1,9 +1,30 @@ -use crate::{convert::ToRethPrimitive, specs::HostBlockSpec}; +use crate::{chain::Chain, specs::HostBlockSpec}; use alloy::consensus::BlobTransactionSidecar; -use reth_exex::ExExNotification; use signet_types::primitives::TransactionSigned; use std::{collections::BTreeMap, sync::Arc}; +/// A shim for reth_exex::ExExNotification that allows us to use it in tests. +#[derive(Debug, Clone, PartialEq, Eq)] +pub enum ExExNotification { + /// Chain got committed without a reorg, and only the new chain is returned. + Committed { + /// The new chain after commit. + new: Arc, + }, + /// Chain got reorged, and both the old and the new chains are returned. + Reorged { + /// The old chain before reorg. + old: Arc, + /// The new chain after reorg. + new: Arc, + }, + /// Chain got reverted, and only the old chain is returned. + Reverted { + /// The old chain before reversion. + old: Arc, + }, +} + /// A notification spec. #[derive(Debug, Default)] pub struct NotificationSpec { @@ -86,22 +107,18 @@ impl NotificationSpec { match (old_chain, new_chain) { (Some(old_chain), Some(new_chain)) => NotificationWithSidecars { - notification: ExExNotification::ChainReorged { - old: Arc::new(old_chain.to_reth()), - new: Arc::new(new_chain.to_reth()), + notification: ExExNotification::Reorged { + old: Arc::new(old_chain), + new: Arc::new(new_chain), }, sidecars, }, (Some(old_chain), None) => NotificationWithSidecars { - notification: ExExNotification::ChainReverted { - old: Arc::new(old_chain.to_reth()), - }, + notification: ExExNotification::Reverted { old: Arc::new(old_chain) }, sidecars, }, (None, Some(new_chain)) => NotificationWithSidecars { - notification: ExExNotification::ChainCommitted { - new: Arc::new(new_chain.to_reth()), - }, + notification: ExExNotification::Committed { new: Arc::new(new_chain) }, sidecars, }, (None, None) => panic!("missing old and new chains"),