Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Expose TrieUpdates inner fields #9277

Merged
merged 1 commit into from
Jul 3, 2024
Merged
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
59 changes: 59 additions & 0 deletions crates/trie/trie/src/updates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ impl TrieUpdates {
&self.account_nodes
}

/// Returns a reference to removed account nodes.
pub const fn removed_nodes_ref(&self) -> &HashSet<Nibbles> {
&self.removed_nodes
}

/// Returns a reference to updated storage tries.
pub const fn storage_tries_ref(&self) -> &HashMap<B256, StorageTrieUpdates> {
&self.storage_tries
}

/// Insert storage updates for a given hashed address.
pub fn insert_storage_updates(
&mut self,
Expand Down Expand Up @@ -162,6 +172,21 @@ impl StorageTrieUpdates {
(self.is_deleted as usize) + self.storage_nodes.len() + self.removed_nodes.len()
}

/// Returns `true` if the trie was deleted.
pub const fn is_deleted(&self) -> bool {
self.is_deleted
}

/// Returns reference to updated storage nodes.
pub const fn storage_nodes_ref(&self) -> &HashMap<Nibbles, BranchNodeCompact> {
&self.storage_nodes
}

/// Returns reference to removed storage nodes.
pub const fn removed_nodes_ref(&self) -> &HashSet<Nibbles> {
&self.removed_nodes
}

/// Returns `true` if storage updates are empty.
pub fn is_empty(&self) -> bool {
!self.is_deleted && self.storage_nodes.is_empty() && self.removed_nodes.is_empty()
Expand Down Expand Up @@ -274,10 +299,44 @@ pub struct TrieUpdatesSorted {
pub(crate) storage_tries: Vec<(B256, StorageTrieUpdatesSorted)>,
}

impl TrieUpdatesSorted {
/// Returns reference to updated account nodes.
pub fn account_nodes_ref(&self) -> &[(Nibbles, BranchNodeCompact)] {
&self.account_nodes
}

/// Returns reference to removed account nodes.
pub const fn removed_nodes_ref(&self) -> &HashSet<Nibbles> {
&self.removed_nodes
}

/// Returns reference to updated storage tries.
pub fn storage_tries_ref(&self) -> &[(B256, StorageTrieUpdatesSorted)] {
&self.storage_tries
}
}

/// Sorted trie updates used for lookups and insertions.
#[derive(PartialEq, Eq, Clone, Default, Debug)]
pub struct StorageTrieUpdatesSorted {
pub(crate) is_deleted: bool,
pub(crate) storage_nodes: Vec<(Nibbles, BranchNodeCompact)>,
pub(crate) removed_nodes: HashSet<Nibbles>,
}

impl StorageTrieUpdatesSorted {
/// Returns `true` if the trie was deleted.
pub const fn is_deleted(&self) -> bool {
self.is_deleted
}

/// Returns reference to updated storage nodes.
pub fn storage_nodes_ref(&self) -> &[(Nibbles, BranchNodeCompact)] {
&self.storage_nodes
}

/// Returns reference to removed storage nodes.
pub const fn removed_nodes_ref(&self) -> &HashSet<Nibbles> {
&self.removed_nodes
}
}
Loading