Skip to content

Commit 121563a

Browse files
authored
feat: child db for concurrent state (#87)
* fix: restore commit bounds to drivers * feat: child db for concurrent state * tests: write em * test: even more stuff * chore: bump version * chore: lints and doclinks
1 parent ad3965b commit 121563a

File tree

6 files changed

+267
-101
lines changed

6 files changed

+267
-101
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "trevm"
3-
version = "0.19.9"
3+
version = "0.19.10"
44
rust-version = "1.83.0"
55
edition = "2021"
66
authors = ["init4"]

src/db/sync/cache.rs

+12
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,18 @@ impl ConcurrentCacheState {
4444
Self { accounts: DashMap::default(), contracts: DashMap::default(), has_state_clear }
4545
}
4646

47+
/// Absorb other into self, overwriting any existing values.
48+
pub fn absorb(&self, other: Self) {
49+
// NB: the `Extend` trait takes self by `&mut self`, so we have inlined
50+
// it here
51+
for pair in other.accounts.into_iter() {
52+
self.accounts.insert(pair.0, pair.1);
53+
}
54+
for pair in other.contracts.into_iter() {
55+
self.contracts.insert(pair.0, pair.1);
56+
}
57+
}
58+
4759
/// Set state clear flag. EIP-161.
4860
pub fn set_state_clear_flag(&mut self, has_state_clear: bool) {
4961
self.has_state_clear = has_state_clear;

src/db/sync/child.rs

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

src/db/sync/error.rs

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
use crate::db::ArcUpgradeError;
2+
3+
/// Errors that can occur when working with a concurrent state.
4+
#[derive(Debug, thiserror::Error, Clone, Copy, PartialEq, Eq)]
5+
pub enum ConcurrentStateError {
6+
/// Failed to upgrade the arc.
7+
#[error("{0}")]
8+
Arc(#[from] ArcUpgradeError),
9+
10+
/// This DB is not the parent of the child.
11+
#[error("Child belongs to a different parent")]
12+
NotParent,
13+
}
14+
15+
impl ConcurrentStateError {
16+
/// Create a new error for when the DB is not the parent of the child.
17+
pub const fn not_parent() -> Self {
18+
Self::NotParent
19+
}
20+
21+
/// Create a new error for when the arc upgrade fails.
22+
pub const fn not_unique() -> Self {
23+
Self::Arc(ArcUpgradeError::NotUnique)
24+
}
25+
}

src/db/sync/mod.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
mod builder;
2-
32
pub use builder::ConcurrentStateBuilder;
43

54
mod cache;
65
pub use cache::ConcurrentCacheState;
76

7+
mod error;
8+
pub use error::ConcurrentStateError;
9+
810
mod state;
9-
pub use state::{ConcurrentState, ConcurrentStateInfo};
11+
pub use state::{Child, ConcurrentState, ConcurrentStateInfo};
1012

1113
use crate::db::StateAcc;
1214
use revm::{

0 commit comments

Comments
 (0)