diff --git a/crates/trie/trie/src/trie.rs b/crates/trie/trie/src/trie.rs index b3ac9dec1d07..0ae43cdf849a 100644 --- a/crates/trie/trie/src/trie.rs +++ b/crates/trie/trie/src/trie.rs @@ -549,7 +549,7 @@ mod tests { hashed_cursor::HashedPostStateCursorFactory, prefix_set::PrefixSetMut, test_utils::{state_root, state_root_prehashed, storage_root, storage_root_prehashed}, - trie_cursor::TrieUpdatesCursorFactory, + trie_cursor::InMemoryTrieCursorFactory, BranchNodeCompact, HashedPostState, HashedStorage, TrieMask, }; use proptest::{prelude::ProptestConfig, proptest}; @@ -1488,7 +1488,7 @@ mod tests { tx, &post_state.clone().into_sorted(), )) - .with_trie_cursor_factory(TrieUpdatesCursorFactory::new(tx, &update.sorted())) + .with_trie_cursor_factory(InMemoryTrieCursorFactory::new(tx, &update.sorted())) .with_prefix_set(prefix_sets.storage_prefix_sets.remove(&keccak256(address)).unwrap()) .root_with_updates() .unwrap(); diff --git a/crates/trie/trie/src/trie_cursor/update.rs b/crates/trie/trie/src/trie_cursor/in_memory.rs similarity index 87% rename from crates/trie/trie/src/trie_cursor/update.rs rename to crates/trie/trie/src/trie_cursor/in_memory.rs index 0c5d9b046882..5f607f314db0 100644 --- a/crates/trie/trie/src/trie_cursor/update.rs +++ b/crates/trie/trie/src/trie_cursor/in_memory.rs @@ -6,25 +6,25 @@ use reth_trie_common::{BranchNodeCompact, Nibbles}; /// The trie cursor factory for the trie updates. #[derive(Debug, Clone)] -pub struct TrieUpdatesCursorFactory<'a, CF> { +pub struct InMemoryTrieCursorFactory<'a, CF> { cursor_factory: CF, trie_updates: &'a TrieUpdatesSorted, } -impl<'a, CF> TrieUpdatesCursorFactory<'a, CF> { +impl<'a, CF> InMemoryTrieCursorFactory<'a, CF> { /// Create a new trie cursor factory. pub const fn new(cursor_factory: CF, trie_updates: &'a TrieUpdatesSorted) -> Self { Self { cursor_factory, trie_updates } } } -impl<'a, CF: TrieCursorFactory> TrieCursorFactory for TrieUpdatesCursorFactory<'a, CF> { - type AccountTrieCursor = TrieUpdatesAccountTrieCursor<'a, CF::AccountTrieCursor>; - type StorageTrieCursor = TrieUpdatesStorageTrieCursor<'a, CF::StorageTrieCursor>; +impl<'a, CF: TrieCursorFactory> TrieCursorFactory for InMemoryTrieCursorFactory<'a, CF> { + type AccountTrieCursor = InMemoryAccountTrieCursor<'a, CF::AccountTrieCursor>; + type StorageTrieCursor = InMemoryStorageTrieCursor<'a, CF::StorageTrieCursor>; fn account_trie_cursor(&self) -> Result { let cursor = self.cursor_factory.account_trie_cursor()?; - Ok(TrieUpdatesAccountTrieCursor::new(cursor, self.trie_updates)) + Ok(InMemoryAccountTrieCursor::new(cursor, self.trie_updates)) } fn storage_trie_cursor( @@ -32,26 +32,26 @@ impl<'a, CF: TrieCursorFactory> TrieCursorFactory for TrieUpdatesCursorFactory<' hashed_address: B256, ) -> Result { let cursor = self.cursor_factory.storage_trie_cursor(hashed_address)?; - Ok(TrieUpdatesStorageTrieCursor::new(cursor, hashed_address, self.trie_updates)) + Ok(InMemoryStorageTrieCursor::new(cursor, hashed_address, self.trie_updates)) } } /// The cursor to iterate over account trie updates and corresponding database entries. /// It will always give precedence to the data from the trie updates. #[derive(Debug)] -pub struct TrieUpdatesAccountTrieCursor<'a, C> { +pub struct InMemoryAccountTrieCursor<'a, C> { cursor: C, trie_updates: &'a TrieUpdatesSorted, last_key: Option, } -impl<'a, C> TrieUpdatesAccountTrieCursor<'a, C> { +impl<'a, C> InMemoryAccountTrieCursor<'a, C> { const fn new(cursor: C, trie_updates: &'a TrieUpdatesSorted) -> Self { Self { cursor, trie_updates, last_key: None } } } -impl<'a, C: TrieCursor> TrieCursor for TrieUpdatesAccountTrieCursor<'a, C> { +impl<'a, C: TrieCursor> TrieCursor for InMemoryAccountTrieCursor<'a, C> { fn seek_exact( &mut self, key: Nibbles, @@ -109,7 +109,7 @@ impl<'a, C: TrieCursor> TrieCursor for TrieUpdatesAccountTrieCursor<'a, C> { /// The cursor to iterate over storage trie updates and corresponding database entries. /// It will always give precedence to the data from the trie updates. #[derive(Debug)] -pub struct TrieUpdatesStorageTrieCursor<'a, C> { +pub struct InMemoryStorageTrieCursor<'a, C> { cursor: C, trie_update_index: usize, trie_updates: &'a TrieUpdatesSorted, @@ -117,13 +117,13 @@ pub struct TrieUpdatesStorageTrieCursor<'a, C> { last_key: Option, } -impl<'a, C> TrieUpdatesStorageTrieCursor<'a, C> { +impl<'a, C> InMemoryStorageTrieCursor<'a, C> { const fn new(cursor: C, hashed_address: B256, trie_updates: &'a TrieUpdatesSorted) -> Self { Self { cursor, trie_updates, trie_update_index: 0, hashed_address, last_key: None } } } -impl<'a, C: TrieCursor> TrieCursor for TrieUpdatesStorageTrieCursor<'a, C> { +impl<'a, C: TrieCursor> TrieCursor for InMemoryStorageTrieCursor<'a, C> { fn seek_exact( &mut self, key: Nibbles, diff --git a/crates/trie/trie/src/trie_cursor/mod.rs b/crates/trie/trie/src/trie_cursor/mod.rs index f5f50a0d0151..a8e0a01cf093 100644 --- a/crates/trie/trie/src/trie_cursor/mod.rs +++ b/crates/trie/trie/src/trie_cursor/mod.rs @@ -1,17 +1,23 @@ use crate::{updates::TrieKey, BranchNodeCompact, Nibbles}; use reth_db::DatabaseError; use reth_primitives::B256; + +/// Database implementations of trie cursors. mod database_cursors; + +/// In-memory implementations of trie cursors. +mod in_memory; + +/// Cursor for iterating over a subtrie. mod subnode; -mod update; /// Noop trie cursor implementations. pub mod noop; pub use self::{ database_cursors::{DatabaseAccountTrieCursor, DatabaseStorageTrieCursor}, + in_memory::*, subnode::CursorSubNode, - update::*, }; /// Factory for creating trie cursors.