Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

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

4 changes: 4 additions & 0 deletions crates/optimism/exex/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ reth-node-api.workspace = true
reth-provider.workspace = true
reth-chainspec.workspace = true

# for ethereum types, `serde-bincode-compat` is added by `reth-storage-api`, however this does not work with `op` until
# `reth-storage-api` is updated to support `op`, so we add it here.
reth-optimism-primitives = { workspace = true, features = ["reth-codec", "serde-bincode-compat", "serde"] }
Comment on lines +22 to +24
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hopefully this is solved in #242 so that we don't have to mess with the manifests outside of the optimism directory for this op feature


# ethereum
alloy-primitives.workspace = true

Expand Down
17 changes: 13 additions & 4 deletions crates/optimism/trie/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ pub struct BlockStateDiff {
#[auto_impl(Arc)]
pub trait OpProofsStorage: Send + Sync + Debug {
/// Cursor for iterating over trie branches.
type TrieCursor: OpProofsTrieCursor;
type StorageTrieCursor: OpProofsTrieCursor;

/// Cursor for iterating over account trie branches.
type AccountTrieCursor: OpProofsTrieCursor;

/// Cursor for iterating over storage leaves.
type StorageCursor: OpProofsHashedCursor<Value = U256>;
Expand Down Expand Up @@ -123,11 +126,17 @@ pub trait OpProofsStorage: Send + Sync + Debug {
) -> impl Future<Output = OpProofsStorageResult<Option<(u64, B256)>>> + Send;

/// Get a trie cursor for the storage backend
fn trie_cursor(
fn storage_trie_cursor(
&self,
hashed_address: B256,
max_block_number: u64,
) -> OpProofsStorageResult<Self::StorageTrieCursor>;

/// Get a trie cursor for the account backend
fn account_trie_cursor(
&self,
hashed_address: Option<B256>,
max_block_number: u64,
) -> OpProofsStorageResult<Self::TrieCursor>;
) -> OpProofsStorageResult<Self::AccountTrieCursor>;

/// Get a storage cursor for the storage backend
fn storage_hashed_cursor(
Expand Down
10 changes: 5 additions & 5 deletions crates/optimism/trie/src/backfill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ mod tests {
job.backfill_accounts_trie().await.unwrap();

// Verify data was stored
let mut trie_cursor = storage.trie_cursor(None, 100).unwrap();
let mut trie_cursor = storage.account_trie_cursor(100).unwrap();
let mut count = 0;
while let Some((path, _node)) = trie_cursor.next().unwrap() {
assert_eq!(path, nodes[count].0 .0);
Expand Down Expand Up @@ -568,7 +568,7 @@ mod tests {
job.backfill_storages_trie().await.unwrap();

// Verify data was stored for addr1
let mut trie_cursor = storage.trie_cursor(Some(addr1), 100).unwrap();
let mut trie_cursor = storage.storage_trie_cursor(addr1, 100).unwrap();
let mut found = vec![];
while let Some((path, _node)) = trie_cursor.next().unwrap() {
found.push(path);
Expand All @@ -578,7 +578,7 @@ mod tests {
assert_eq!(found[1], nodes[1].1.nibbles.0);

// Verify data was stored for addr2
let mut trie_cursor = storage.trie_cursor(Some(addr2), 100).unwrap();
let mut trie_cursor = storage.storage_trie_cursor(addr2, 100).unwrap();
let mut found = vec![];
while let Some((path, _node)) = trie_cursor.next().unwrap() {
found.push(path);
Expand Down Expand Up @@ -662,10 +662,10 @@ mod tests {
let mut storage_cursor = storage.storage_hashed_cursor(addr, 100).unwrap();
assert!(storage_cursor.next().unwrap().is_some());

let mut trie_cursor = storage.trie_cursor(None, 100).unwrap();
let mut trie_cursor = storage.account_trie_cursor(100).unwrap();
assert!(trie_cursor.next().unwrap().is_some());

let mut storage_trie_cursor = storage.trie_cursor(Some(addr), 100).unwrap();
let mut storage_trie_cursor = storage.storage_trie_cursor(addr, 100).unwrap();
assert!(storage_trie_cursor.next().unwrap().is_some());
}

Expand Down
16 changes: 12 additions & 4 deletions crates/optimism/trie/src/db/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ impl MdbxProofsStorage {
}

impl OpProofsStorage for MdbxProofsStorage {
type TrieCursor = MdbxTrieCursor;
type StorageTrieCursor = MdbxTrieCursor;
type AccountTrieCursor = MdbxTrieCursor;
type StorageCursor = MdbxStorageCursor;
type AccountHashedCursor = MdbxAccountCursor;

Expand Down Expand Up @@ -73,11 +74,18 @@ impl OpProofsStorage for MdbxProofsStorage {
unimplemented!()
}

fn trie_cursor(
fn storage_trie_cursor(
&self,
_hashed_address: B256,
_max_block_number: u64,
) -> OpProofsStorageResult<Self::StorageTrieCursor> {
unimplemented!()
}

fn account_trie_cursor(
&self,
_hashed_address: Option<B256>,
_max_block_number: u64,
) -> OpProofsStorageResult<Self::TrieCursor> {
) -> OpProofsStorageResult<Self::AccountTrieCursor> {
unimplemented!()
}

Expand Down
22 changes: 17 additions & 5 deletions crates/optimism/trie/src/in_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,8 @@ impl OpProofsHashedCursor for InMemoryAccountCursor {
}

impl OpProofsStorage for InMemoryProofsStorage {
type TrieCursor = InMemoryTrieCursor;
type StorageTrieCursor = InMemoryTrieCursor;
type AccountTrieCursor = InMemoryTrieCursor;
type StorageCursor = InMemoryStorageCursor;
type AccountHashedCursor = InMemoryAccountCursor;

Expand Down Expand Up @@ -459,17 +460,28 @@ impl OpProofsStorage for InMemoryProofsStorage {
}
}

fn trie_cursor(
fn storage_trie_cursor(
&self,
hashed_address: Option<B256>,
hashed_address: B256,
max_block_number: u64,
) -> OpProofsStorageResult<Self::TrieCursor> {
) -> OpProofsStorageResult<Self::StorageTrieCursor> {
// For synchronous methods, we need to try_read() and handle potential blocking
let inner = self
.inner
.try_read()
.map_err(|_| OpProofsStorageError::Other(eyre::eyre!("Failed to acquire read lock")))?;
Ok(InMemoryTrieCursor::new(&inner, hashed_address, max_block_number))
Ok(InMemoryTrieCursor::new(&inner, Some(hashed_address), max_block_number))
}

fn account_trie_cursor(
&self,
max_block_number: u64,
) -> OpProofsStorageResult<Self::AccountTrieCursor> {
let inner = self
.inner
.try_read()
.map_err(|_| OpProofsStorageError::Other(eyre::eyre!("Failed to acquire read lock")))?;
Ok(InMemoryTrieCursor::new(&inner, None, max_block_number))
}

fn storage_hashed_cursor(
Expand Down
Loading
Loading