Skip to content

Commit 85f3634

Browse files
meyer9emhane
andcommitted
feat: add external state provider implementation (#197)
Based on #203 , #204 This PR implements `StateProvider` given a `OpProofsStorage` instance. It reads most data from the external database, but falls back on the latest provider for block hashes and code by hash similar to the existing historical provider in Reth. This is an important part to implementing live syncing since we're running the sync process on the DB being created. In the Reth implementation, `proof.rs` is contained in `trie/db`, so I think it makes sense to go in our DB crate. The `provider.rs` is in the `reth-provider` crate, but I don't think a separate provider crate helps us here, so I think we should also include that in the trie crate as well. --------- Co-authored-by: Emilia Hane <[email protected]>
1 parent 22c0f5f commit 85f3634

File tree

6 files changed

+801
-2
lines changed

6 files changed

+801
-2
lines changed

Cargo.lock

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/optimism/trie/Cargo.toml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,12 @@ workspace = true
1414
[dependencies]
1515
# reth
1616
reth-trie = { workspace = true, features = ["serde"] }
17-
reth-primitives-traits = { workspace = true, features = ["op"] }
18-
reth-db = { workspace = true, features = ["mdbx", "op"] }
17+
reth-primitives-traits = { workspace = true }
18+
reth-db = { workspace = true, features = ["mdbx"] }
19+
reth-revm = { workspace = true }
20+
reth-provider = { workspace = true }
21+
reth-db-api = { workspace = true }
22+
reth-execution-errors = { workspace = true }
1923

2024
# ethereum
2125
alloy-primitives.workspace = true

crates/optimism/trie/src/api.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ pub trait OpProofsHashedCursor: Send + Sync {
5252

5353
/// Move the cursor to the next entry and return it.
5454
fn next(&mut self) -> OpProofsStorageResult<Option<(B256, Self::Value)>>;
55+
56+
/// Returns `true` if there are no entries for a given key.
57+
fn is_storage_empty(&mut self) -> OpProofsStorageResult<bool> {
58+
Ok(self.seek(B256::ZERO)?.is_none())
59+
}
5560
}
5661

5762
/// Diff of trie updates and post state for a block.

crates/optimism/trie/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,7 @@ pub use in_memory::{
2727
};
2828

2929
pub mod db;
30+
31+
pub mod proof;
32+
33+
pub mod provider;

0 commit comments

Comments
 (0)