Skip to content
Merged
13 changes: 4 additions & 9 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,14 @@ jobs:
uses: actions/checkout@v4
with:
submodules: recursive

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: stable


- uses: Swatinem/rust-cache@v2
with:
key: cargo-check
cache-on-failure: true

- name: cargo check --workspace --all-features
run: cargo check --workspace --all-features
- name: cargo check --workspace --all-targets --all-features
run: cargo check --workspace --all-targets --all-features

cargo-clippy:
name: cargo clippy
Expand Down Expand Up @@ -86,4 +81,4 @@ jobs:
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- name: Run tests
run: cargo test --workspace --features ci -- --nocapture
run: cargo test --workspace --all-targets --features ci -- --nocapture
3 changes: 3 additions & 0 deletions Cargo.lock

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

8 changes: 8 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ reth-optimism-rpc = { git = "https://github.com/ethereum-optimism/optimism", ver
reth-optimism-primitives = { git = "https://github.com/ethereum-optimism/optimism", version = "1.11.3", tag = "op-reth/v1.11.3" }

reth-revm = { git = "https://github.com/paradigmxyz/reth", version = "1.11.3", tag = "v1.11.3" }
reth-evm = { git = "https://github.com/paradigmxyz/reth", version = "1.11.3", tag = "v1.11.3" }
reth-rpc-eth-api = { git = "https://github.com/paradigmxyz/reth", version = "1.11.3", tag = "v1.11.3" }
reth-storage-api = { git = "https://github.com/paradigmxyz/reth", version = "1.11.3", tag = "v1.11.3" }
reth-node-types = { git = "https://github.com/paradigmxyz/reth", version = "1.11.3", tag = "v1.11.3" }
Expand All @@ -62,6 +63,13 @@ revm = { version = "34.0.0", features = [
"optional_block_gas_limit",
"c-kzg",
], default-features = false }
op-revm = { version = "15.0.0", features = [
"std",
"secp256k1",
"optional_balance_check",
"optional_block_gas_limit",
"c-kzg",
], default-features = false }

# async
tokio = "1"
Expand Down
8 changes: 8 additions & 0 deletions crates/eth-network-exts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ pub trait EthNetworkExt: Send + Sync {
type TypeExt;

const CHAIN_ID: u64;

fn is_op_chain() -> bool {
match Self::CHAIN_ID {
1 | 11155111 => false,
8453 | 130 => true,
_ => unreachable!()
}
}
}

pub trait AllExtensions: std::fmt::Debug + Send + Sync + Clone + Copy + Unpin + 'static {}
Expand Down
45 changes: 24 additions & 21 deletions crates/lib-reth/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ reth-revm = { workspace = true, optional = true }
reth-rpc-eth-api = { workspace = true, optional = true }
reth-storage-api = { workspace = true, optional = true }
reth-node-types = { workspace = true, optional = true }
reth-evm = { workspace = true, optional = true }
uniswap-storage = { workspace = true, optional = true }
eth-network-exts.workspace = true

Expand Down Expand Up @@ -73,6 +74,7 @@ revm.workspace = true
revm-database = { workspace = true, default-features = false, features = [
"alloydb",
] }
op-revm = { workspace = true, optional = true }

# async
tokio = { workspace = true, features = ["full"] }
Expand All @@ -82,6 +84,7 @@ async-trait.workspace = true
# misc
eyre.workspace = true
exe-runners = { workspace = true, features = ["reth-tasks"] }
auto_impl.workspace = true


[dev-dependencies]
Expand All @@ -90,36 +93,22 @@ serial_test.workspace = true

[features]
default = ["full"]
full = ["ipc", "ws", "uniswap-storage", "revm", "reth-libmdbx"]
full = ["mainnet-full", "op-full", "ipc", "ws", "uniswap-storage"]


ipc = []
ws = []

rayon = ["exe-runners/rayon"]

mainnet-full = ["revm", "reth-db"]
op-full = ["op-revm", "op-reth-db"]

revm = [
"reth-libmdbx",
"dep:reth-rpc-eth-api",
"dep:reth-revm",
"dep:alloy-eips",
]

op-reth-libmdbx = [
"reth-libmdbx",
"dep:reth-optimism-chainspec",
"dep:reth-optimism-primitives",
"dep:reth-optimism-node",
"dep:reth-optimism-evm",
"dep:reth-optimism-rpc",
"dep:op-alloy-network",
"dep:op-alloy-consensus",
"uniswap-storage/l2-angstrom",
"eth-network-exts/l2",
]
revm = ["dep:alloy-eips", "dep:reth-revm", "dep:reth-evm"]
op-revm = ["revm", "dep:op-revm", "dep:op-alloy-network"]

reth-libmdbx = [

reth-db = [
"dep:reth-provider",
"dep:reth-rpc",
"dep:reth-transaction-pool",
Expand All @@ -134,7 +123,21 @@ reth-libmdbx = [
"dep:reth-storage-api",
"dep:reth-rpc-eth-api",
]
op-reth-db = [
"reth-db",
"dep:reth-optimism-chainspec",
"dep:reth-optimism-primitives",
"dep:reth-optimism-node",
"dep:reth-optimism-evm",
"dep:reth-optimism-rpc",
"dep:op-alloy-network",
"dep:op-alloy-consensus",
"uniswap-storage/l2-angstrom",
"eth-network-exts/l2",
]


uniswap-storage = ["dep:uniswap-storage", "dep:alloy-eips"]
rayon = ["exe-runners/rayon"]

ci = []
4 changes: 2 additions & 2 deletions crates/lib-reth/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ This crate provides a comprehensive library for connecting to Ethereum endpoints
- HTTP (default)
- IPC (feature = `ipc`)
- WebSocket (feature = `ws`)
- Direct database access via libmdbx (feature = `reth-libmdbx`)
- Direct database access via libmdbx (feature = `reth-db`)

## Features

- `full` - All connection types and integrations
- `revm` - REVM execution support
- `op-reth-libmdbx` - Optimism node support
- `op-reth-db` - Optimism node support
- `rayon` - Parallel execution support

## Supported Functionality
Expand Down
8 changes: 4 additions & 4 deletions crates/lib-reth/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
#![allow(ambiguous_glob_reexports)]

#[cfg(feature = "reth-libmdbx")]
#[cfg(feature = "reth-db")]
pub mod reth_libmdbx;

pub mod rpc;
pub mod traits;

#[cfg(feature = "op-reth-libmdbx")]
#[cfg(feature = "op-reth-db")]
pub mod op_reth {
pub use reth_optimism_chainspec::*;
pub use reth_optimism_node::*;
pub use reth_optimism_primitives::*;
}

#[cfg(feature = "reth-libmdbx")]
#[cfg(feature = "reth-db")]
pub use regular_reth::*;

#[cfg(feature = "reth-libmdbx")]
#[cfg(feature = "reth-db")]
mod regular_reth {
pub use reth_chainspec::*;
pub use reth_node_ethereum::EthereumNode;
Expand Down
33 changes: 20 additions & 13 deletions crates/lib-reth/src/reth_libmdbx/node_types/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use std::sync::Arc;

#[cfg(feature = "revm")]
use alloy_eips::BlockId;
use alloy_provider::{IpcConnect, RootProvider, WsConnect, builder};
use eth_network_exts::EthNetworkExt;
use reth_node_types::NodeTypes;
Expand All @@ -14,7 +12,7 @@ use reth_tasks::TaskSpawner;
use crate::{reth_libmdbx::DbConfig, traits::EthStream};

pub mod node;
#[cfg(feature = "op-reth-libmdbx")]
#[cfg(feature = "op-reth-db")]
pub mod op_node;

pub(crate) fn provider_runtime() -> eyre::Result<reth_tasks::Runtime> {
Expand Down Expand Up @@ -129,18 +127,27 @@ where
}

#[cfg(feature = "revm")]
impl<Ext: EthNetworkExt> crate::traits::EthRevm for RethNodeClient<Ext>
where
Ext::RethNode: NodeClientSpec
{
type InnerDb = crate::traits::reth_revm_utils::RethLibmdbxDatabaseRef;
mod revm_impl {

fn make_inner_db(&self, block: BlockId) -> eyre::Result<Self::InnerDb> {
use reth_provider::StateProviderFactory;
use reth_provider::StateProviderFactory;
use reth_revm::database::StateProviderDatabase;

let state_provider = self.eth_db_provider().state_by_block_id(block)?;
use super::*;
use crate::traits::{EthRevm, EthRevmParams, reth_revm_utils::RethLibmdbxDatabaseRef};

let this = reth_revm::database::StateProviderDatabase::new(state_provider);
Ok(crate::traits::reth_revm_utils::RethLibmdbxDatabaseRef::new(this))
impl<Ext> EthRevm for RethNodeClient<Ext>
where
Ext: EthNetworkExt,
Ext::RethNode: NodeClientSpec
{
type InnerDb = RethLibmdbxDatabaseRef;
type Params = EthRevmParams;

fn make_inner_db(&self, params: &EthRevmParams) -> eyre::Result<Self::InnerDb> {
let state_provider = self.eth_db_provider().state_by_block_id(params.block_id)?;

let this = StateProviderDatabase::new(state_provider);
Ok(RethLibmdbxDatabaseRef::new(this))
}
}
}
45 changes: 30 additions & 15 deletions crates/lib-reth/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ use alloy_rpc_client::WsConnect;
use alloy_rpc_types::Filter;
#[cfg(any(feature = "ipc", feature = "ws"))]
use futures::Stream;
#[cfg(feature = "revm")]
use revm_database::{AlloyDB, WrapDatabaseAsync};

#[cfg(any(feature = "ipc", feature = "ws"))]
use crate::traits::EthStream;
Expand Down Expand Up @@ -103,18 +101,35 @@ where
}

#[cfg(feature = "revm")]
impl<P, N> crate::traits::AsyncEthRevm for EthRpcClient<P, N>
where
P: Provider<N> + Clone,
N: Network
{
type InnerDb = AlloyDB<N, P>;

fn make_inner_db(
&self,
block_number: u64,
handle: tokio::runtime::Handle
) -> eyre::Result<WrapDatabaseAsync<Self::InnerDb>> {
Ok(WrapDatabaseAsync::with_handle(AlloyDB::new(self.provider.clone(), block_number.into()), handle))
mod revm_impl {

use revm_database::{AlloyDB, WrapDatabaseAsync};

use super::*;
use crate::traits::{AsyncEthRevmParams, EthRevm};

impl<P, N> EthRevm for EthRpcClient<P, N>
where
P: Provider<N> + Clone,
N: Network
{
type InnerDb = WrapDatabaseAsync<AlloyDB<N, P>>;
type Params = AsyncEthRevmParams;

fn make_inner_db(&self, params: &AsyncEthRevmParams) -> eyre::Result<Self::InnerDb> {
Ok(WrapDatabaseAsync::with_handle(AlloyDB::new(self.provider.clone(), params.block_id), params.handle.clone()))
}
}

impl<N> EthRevm for RootProvider<N>
where
N: Network
{
type InnerDb = WrapDatabaseAsync<AlloyDB<N, RootProvider<N>>>;
type Params = AsyncEthRevmParams;

fn make_inner_db(&self, params: &AsyncEthRevmParams) -> eyre::Result<Self::InnerDb> {
Ok(WrapDatabaseAsync::with_handle(AlloyDB::new(self.clone(), params.block_id), params.handle.clone()))
}
}
}
2 changes: 1 addition & 1 deletion crates/lib-reth/src/traits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ mod revm;
#[cfg(feature = "revm")]
pub use revm::*;

#[cfg(feature = "revm")]
#[cfg(all(feature = "revm", feature = "reth-db"))]
pub mod reth_revm_utils;
Loading
Loading