Skip to content

Commit

Permalink
perf(trie): use unstable sort when sorting for computing roots (parad…
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes authored Sep 27, 2024
1 parent 6c92f8a commit d8f16b8
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions crates/trie/common/src/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ pub fn state_root_unhashed<A: Into<TrieAccount>>(
pub fn state_root_unsorted<A: Into<TrieAccount>>(
state: impl IntoIterator<Item = (B256, A)>,
) -> B256 {
state_root(state.into_iter().sorted_by_key(|(key, _)| *key))
state_root(state.into_iter().sorted_unstable_by_key(|(key, _)| *key))
}

/// Calculates the root hash of the state represented as MPT.
Expand Down Expand Up @@ -105,7 +105,7 @@ pub fn storage_root_unhashed(storage: impl IntoIterator<Item = (B256, U256)>) ->
/// Sorts and calculates the root hash of account storage trie.
/// See [`storage_root`] for more info.
pub fn storage_root_unsorted(storage: impl IntoIterator<Item = (B256, U256)>) -> B256 {
storage_root(storage.into_iter().sorted_by_key(|(key, _)| *key))
storage_root(storage.into_iter().sorted_unstable_by_key(|(key, _)| *key))
}

/// Calculates the root hash of account storage trie.
Expand Down

0 comments on commit d8f16b8

Please sign in to comment.