Skip to content

Commit d2f2443

Browse files
authored
Split the EVM (#126)
* wip: split evm * docs: update DbConnect docs
1 parent 6213c9f commit d2f2443

22 files changed

+3147
-2533
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ alloy = { version = "1.0.25", default-features = false, features = [
4545
] }
4646

4747
revm = { version = "27.1", default-features = false }
48-
revm-inspectors = { version = "0.27.1", optional = true }
48+
revm-inspectors = { version = "0.27.3", optional = true }
4949

5050
dashmap = { version = "6.1.0", optional = true }
5151
tracing = { version = "0.1.41", optional = true }
@@ -86,7 +86,7 @@ concurrent-db = ["dep:dashmap"]
8686

8787
estimate_gas = ["optional_eip3607", "optional_no_base_fee", "dep:tracing"]
8888

89-
test-utils = ["revm/std", "revm/serde-json", "revm/alloydb"]
89+
test-utils = ["revm/std", "revm/serde-json", "revm/alloydb", "alloy/signers", "alloy/signer-local"]
9090

9191
secp256k1 = ["revm/secp256k1"]
9292
c-kzg = ["revm/c-kzg"]

src/db/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ pub mod sync;
44

55
/// Database abstraction traits.
66
mod traits;
7-
pub use traits::{ArcUpgradeError, CachingDb, StateAcc, TryCachingDb, TryStateAcc};
7+
pub use traits::{ArcUpgradeError, CachingDb, DbConnect, StateAcc, TryCachingDb, TryStateAcc};
88

99
/// Cache-on-write database. A memory cache that caches only on write, not on
1010
/// read. Intended to wrap some other caching database.

src/db/traits.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,42 @@ use revm::{
55
};
66
use std::{collections::BTreeMap, convert::Infallible, sync::Arc};
77

8+
/// Trait for types that can be used to connect to a database.
9+
///
10+
/// Connectors should contain configuration information like filesystem paths.
11+
/// They are intended to enable parallel instantiation of multiple EVMs in
12+
/// multiple threads sharing some database configuration
13+
///
14+
/// `DbConnect` is blanket implemented for clonable [`Database`] types by
15+
/// simply cloning the database instance. This allows already-instantiated DBs
16+
/// to be used as connectors, however, if the [`Database`] uses a shared
17+
/// resource like a file or network connection, care should be taken to ensure
18+
/// that the implementation does not share uintended state between EVM
19+
/// instances.
20+
pub trait DbConnect: Sync {
21+
/// The database type returned when connecting.
22+
type Database: Database;
23+
24+
/// The error type returned when connecting to the database.
25+
type Error: core::error::Error;
26+
27+
/// Connect to the database.
28+
fn connect(&self) -> Result<Self::Database, Self::Error>;
29+
}
30+
31+
impl<Db> DbConnect for Db
32+
where
33+
Db: Database + Clone + Sync,
34+
{
35+
type Database = Self;
36+
37+
type Error = Infallible;
38+
39+
fn connect(&self) -> Result<Self::Database, Self::Error> {
40+
Ok(self.clone())
41+
}
42+
}
43+
844
/// Abstraction trait covering types that accumulate state changes into a
945
/// [`BundleState`]. The prime example of this is [`State`]. These types are
1046
/// use to accumulate state changes during the execution of a sequence of

src/driver/bundle.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{helpers::Ctx, states::EvmBundleDriverErrored, EvmNeedsTx};
1+
use crate::{helpers::Ctx, EvmBundleDriverErrored, EvmNeedsTx};
22
use revm::{
33
context::result::EVMError, inspector::NoOpInspector, Database, DatabaseCommit, Inspector,
44
};

0 commit comments

Comments
 (0)