perf: pass blinded_node path by reference (#13298)

This commit is contained in:
DaniPopes
2024-12-11 15:06:24 +01:00
committed by GitHub
parent 17d38c9152
commit 6550d82abd
4 changed files with 11 additions and 11 deletions

View File

@@ -24,7 +24,7 @@ pub trait BlindedProvider {
type Error: Into<SparseTrieError>;
/// Retrieve blinded node by path.
fn blinded_node(&mut self, path: Nibbles) -> Result<Option<Bytes>, Self::Error>;
fn blinded_node(&mut self, path: &Nibbles) -> Result<Option<Bytes>, Self::Error>;
}
/// Default blinded node provider factory that creates [`DefaultBlindedProvider`].
@@ -51,7 +51,7 @@ pub struct DefaultBlindedProvider;
impl BlindedProvider for DefaultBlindedProvider {
type Error = SparseTrieError;
fn blinded_node(&mut self, _path: Nibbles) -> Result<Option<Bytes>, Self::Error> {
fn blinded_node(&mut self, _path: &Nibbles) -> Result<Option<Bytes>, Self::Error> {
Ok(None)
}
}

View File

@@ -878,7 +878,7 @@ where
if self.updates.is_some() {
// Check if the extension node child is a hash that needs to be revealed
if self.nodes.get(&current).unwrap().is_hash() {
if let Some(node) = self.provider.blinded_node(current.clone())? {
if let Some(node) = self.provider.blinded_node(&current)? {
let decoded = TrieNode::decode(&mut &node[..])?;
trace!(target: "trie::sparse", ?current, ?decoded, "Revealing extension node child");
// We'll never have to update the revealed child node, only
@@ -1031,7 +1031,7 @@ where
if self.nodes.get(&child_path).unwrap().is_hash() {
trace!(target: "trie::sparse", ?child_path, "Retrieving remaining blinded branch child");
if let Some(node) = self.provider.blinded_node(child_path.clone())? {
if let Some(node) = self.provider.blinded_node(&child_path)? {
let decoded = TrieNode::decode(&mut &node[..])?;
trace!(target: "trie::sparse", ?child_path, ?decoded, "Revealing remaining blinded branch child");
// We'll never have to update the revealed branch node, only remove

View File

@@ -86,15 +86,15 @@ where
{
type Error = SparseTrieError;
fn blinded_node(&mut self, path: Nibbles) -> Result<Option<Bytes>, Self::Error> {
let targets = HashMap::from_iter([(pad_path_to_key(&path), HashSet::default())]);
fn blinded_node(&mut self, path: &Nibbles) -> Result<Option<Bytes>, Self::Error> {
let targets = HashMap::from_iter([(pad_path_to_key(path), HashSet::default())]);
let proof =
Proof::new(self.trie_cursor_factory.clone(), self.hashed_cursor_factory.clone())
.with_prefix_sets_mut(self.prefix_sets.as_ref().clone())
.multiproof(targets)
.map_err(|error| SparseTrieErrorKind::Other(Box::new(error)))?;
Ok(proof.account_subtree.into_inner().remove(&path))
Ok(proof.account_subtree.into_inner().remove(path))
}
}
@@ -130,8 +130,8 @@ where
{
type Error = SparseTrieError;
fn blinded_node(&mut self, path: Nibbles) -> Result<Option<Bytes>, Self::Error> {
let targets = HashSet::from_iter([pad_path_to_key(&path)]);
fn blinded_node(&mut self, path: &Nibbles) -> Result<Option<Bytes>, Self::Error> {
let targets = HashSet::from_iter([pad_path_to_key(path)]);
let storage_prefix_set =
self.prefix_sets.storage_prefix_sets.get(&self.account).cloned().unwrap_or_default();
let proof = StorageProof::new_hashed(
@@ -143,6 +143,6 @@ where
.storage_multiproof(targets)
.map_err(|error| SparseTrieErrorKind::Other(Box::new(error)))?;
Ok(proof.subtree.into_inner().remove(&path))
Ok(proof.subtree.into_inner().remove(path))
}
}

View File

@@ -249,7 +249,7 @@ where
{
type Error = P::Error;
fn blinded_node(&mut self, path: Nibbles) -> Result<Option<Bytes>, Self::Error> {
fn blinded_node(&mut self, path: &Nibbles) -> Result<Option<Bytes>, Self::Error> {
let maybe_node = self.provider.blinded_node(path)?;
if let Some(node) = &maybe_node {
self.tx