mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
chore(trie): rename in-memory trie cursors (#9203)
This commit is contained in:
@ -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();
|
||||
|
||||
@ -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<Self::AccountTrieCursor, DatabaseError> {
|
||||
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<Self::StorageTrieCursor, DatabaseError> {
|
||||
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<TrieKey>,
|
||||
}
|
||||
|
||||
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<TrieKey>,
|
||||
}
|
||||
|
||||
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,
|
||||
@ -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.
|
||||
|
||||
Reference in New Issue
Block a user