Skip to content

Commit 0cdc489

Browse files
committed
chore: make it a feature
1 parent d08659b commit 0cdc489

File tree

5 files changed

+47
-38
lines changed

5 files changed

+47
-38
lines changed

Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ alloy = { version = "=0.5.4", default-features = false, features = ["consensus",
3737
revm = { version = "18.0.0", default-features = false }
3838

3939
zenith-types = { version = "0.10", optional = true }
40-
dashmap = "6.1.0"
40+
41+
dashmap = { version = "6.1.0", optional = true }
4142

4243
[dev-dependencies]
4344
alloy-rlp = { version = "0.3", default-features = false }
@@ -57,6 +58,7 @@ tokio = { version = "1.39", features = ["macros", "rt-multi-thread"] }
5758
[features]
5859
default = [
5960
"std",
61+
"concurrent-db",
6062
"revm/std",
6163
"revm/c-kzg",
6264
"revm/blst",
@@ -66,6 +68,8 @@ default = [
6668

6769
std = ["revm/std", "alloy/std", "alloy-rlp/std", "alloy-primitives/std", "alloy-sol-types/std", "dep:zenith-types"]
6870

71+
concurrent-db = ["std", "dep:dashmap"]
72+
6973
test-utils = ["revm/test-utils", "revm/std", "revm/serde-json", "revm/alloydb"]
7074

7175
secp256k1 = ["revm/secp256k1"]

src/db/mod.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,34 @@ pub use sync_state::{ConcurrentState, StateInfo};
33

44
mod cache_state;
55
pub use cache_state::ConcurrentCacheState;
6+
7+
use crate::{EvmNeedsBlock, Trevm};
8+
use revm::{
9+
db::{states::bundle_state::BundleRetention, BundleState},
10+
DatabaseRef,
11+
};
12+
13+
impl<Ext, Db: DatabaseRef, TrevmState> Trevm<'_, Ext, ConcurrentState<Db>, TrevmState> {
14+
/// Set the [EIP-161] state clear flag, activated in the Spurious Dragon
15+
/// hardfork.
16+
pub fn set_state_clear_flag(&mut self, flag: bool) {
17+
self.inner.db_mut().set_state_clear_flag(flag)
18+
}
19+
}
20+
21+
impl<'a, Ext, Db: DatabaseRef> EvmNeedsBlock<'a, Ext, ConcurrentState<Db>> {
22+
/// Finish execution and return the outputs.
23+
///
24+
/// ## Panics
25+
///
26+
/// If the State has not been built with StateBuilder::with_bundle_update.
27+
///
28+
/// See [`State::merge_transitions`] and [`State::take_bundle`].
29+
pub fn finish(self) -> BundleState {
30+
let Self { inner: mut evm, .. } = self;
31+
evm.db_mut().merge_transitions(BundleRetention::Reverts);
32+
let bundle = evm.db_mut().take_bundle();
33+
34+
bundle
35+
}
36+
}

src/db/sync_state.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::db::ConcurrentCacheState;
2+
use alloc::{collections::BTreeMap, vec::Vec};
23
use alloy_primitives::{Address, B256, U256};
34
use dashmap::mapref::one::RefMut;
45
use revm::{
@@ -9,10 +10,7 @@ use revm::{
910
primitives::{Account, AccountInfo, Bytecode},
1011
Database, DatabaseCommit, DatabaseRef, TransitionAccount, TransitionState,
1112
};
12-
use std::{
13-
collections::{hash_map, BTreeMap},
14-
sync::RwLock,
15-
};
13+
use std::{collections::hash_map, sync::RwLock};
1614

1715
/// State of blockchain.
1816
///

src/evm.rs

Lines changed: 8 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use crate::{
2-
db::ConcurrentState, driver::DriveBlockResult, Block, BlockDriver, BundleDriver, Cfg,
3-
ChainDriver, DriveBundleResult, DriveChainResult, ErroredState, EvmErrored, EvmExtUnchecked,
4-
EvmNeedsBlock, EvmNeedsCfg, EvmNeedsTx, EvmReady, EvmTransacted, HasBlock, HasCfg, HasTx,
5-
NeedsCfg, NeedsTx, TransactedState, Tx,
2+
driver::DriveBlockResult, Block, BlockDriver, BundleDriver, Cfg, ChainDriver,
3+
DriveBundleResult, DriveChainResult, ErroredState, EvmErrored, EvmExtUnchecked, EvmNeedsBlock,
4+
EvmNeedsCfg, EvmNeedsTx, EvmReady, EvmTransacted, HasBlock, HasCfg, HasTx, NeedsCfg, NeedsTx,
5+
TransactedState, Tx,
66
};
77
use alloc::{boxed::Box, fmt};
88
use alloy_primitives::{Address, Bytes, U256};
@@ -20,8 +20,8 @@ use revm::{
2020
///
2121
/// See the [crate-level documentation](crate) for more information.
2222
pub struct Trevm<'a, Ext, Db: Database + DatabaseCommit, TrevmState> {
23-
inner: Box<Evm<'a, Ext, Db>>,
24-
state: TrevmState,
23+
pub(crate) inner: Box<Evm<'a, Ext, Db>>,
24+
pub(crate) state: TrevmState,
2525
}
2626

2727
impl<Ext, Db: Database + DatabaseCommit, TrevmState> fmt::Debug for Trevm<'_, Ext, Db, TrevmState> {
@@ -440,7 +440,7 @@ impl<Ext, Db: Database<Error = Infallible> + DatabaseCommit, TrevmState>
440440
}
441441
}
442442

443-
// --- ALL STATES, WITH State<Db> or ConcurrentState<Db>
443+
// --- ALL STATES, WITH State<Db>
444444

445445
impl<Ext, Db: Database + DatabaseCommit, TrevmState> Trevm<'_, Ext, State<Db>, TrevmState> {
446446
/// Set the [EIP-161] state clear flag, activated in the Spurious Dragon
@@ -450,14 +450,6 @@ impl<Ext, Db: Database + DatabaseCommit, TrevmState> Trevm<'_, Ext, State<Db>, T
450450
}
451451
}
452452

453-
impl<Ext, Db: DatabaseRef, TrevmState> Trevm<'_, Ext, ConcurrentState<Db>, TrevmState> {
454-
/// Set the [EIP-161] state clear flag, activated in the Spurious Dragon
455-
/// hardfork.
456-
pub fn set_state_clear_flag(&mut self, flag: bool) {
457-
self.inner.db_mut().set_state_clear_flag(flag)
458-
}
459-
}
460-
461453
// --- NEEDS CFG
462454

463455
impl<'a, Ext, Db: Database + DatabaseCommit> EvmNeedsCfg<'a, Ext, Db> {
@@ -886,7 +878,7 @@ impl<'a, Ext, Db: Database + DatabaseCommit, TrevmState: HasBlock> Trevm<'a, Ext
886878
}
887879
}
888880

889-
// --- Needs Block with State<Db> or ConcurrentState<Db>
881+
// --- Needs Block with State<Db>
890882

891883
impl<Ext, Db: Database> EvmNeedsBlock<'_, Ext, State<Db>> {
892884
/// Finish execution and return the outputs.
@@ -905,23 +897,6 @@ impl<Ext, Db: Database> EvmNeedsBlock<'_, Ext, State<Db>> {
905897
}
906898
}
907899

908-
impl<'a, Ext, Db: DatabaseRef> EvmNeedsBlock<'a, Ext, ConcurrentState<Db>> {
909-
/// Finish execution and return the outputs.
910-
///
911-
/// ## Panics
912-
///
913-
/// If the State has not been built with StateBuilder::with_bundle_update.
914-
///
915-
/// See [`State::merge_transitions`] and [`State::take_bundle`].
916-
pub fn finish(self) -> BundleState {
917-
let Self { inner: mut evm, .. } = self;
918-
evm.db_mut().merge_transitions(BundleRetention::Reverts);
919-
let bundle = evm.db_mut().take_bundle();
920-
921-
bundle
922-
}
923-
}
924-
925900
// --- NEEDS TX
926901

927902
impl<'a, Ext, Db: Database + DatabaseCommit> EvmNeedsTx<'a, Ext, Db> {

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,7 @@ mod connect;
367367
pub use connect::{DbConnect, EvmFactory};
368368

369369
/// Contains database implementations for concurrent EVM operation.
370+
#[cfg(feature = "concurrent-db")]
370371
pub mod db;
371372

372373
mod driver;

0 commit comments

Comments
 (0)