Skip to content
Merged
Changes from 4 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
27 changes: 17 additions & 10 deletions crates/trie/sparse/src/trie.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,6 @@ impl<P> fmt::Debug for RevealedSparseTrie<P> {
.field("values", &self.values)
.field("prefix_set", &self.prefix_set)
.field("updates", &self.updates)
.field("rlp_buf", &hex::encode(&self.rlp_buf))
.finish_non_exhaustive()
}
}
Expand Down Expand Up @@ -452,8 +451,8 @@ impl<P> RevealedSparseTrie<P> {
branch_node_hash_masks: HashMap::default(),
values: HashMap::default(),
prefix_set: PrefixSetMut::default(),
rlp_buf: Vec::new(),
updates: None,
rlp_buf: Vec::new(),
}
.with_updates(retain_updates);
this.reveal_node(Nibbles::default(), node, masks)?;
Expand Down Expand Up @@ -875,14 +874,17 @@ impl<P> RevealedSparseTrie<P> {
self.prefix_set = new_prefix_set;

trace!(target: "trie::sparse", ?depth, ?targets, "Updating nodes at depth");

let mut temp_rlp_buf = core::mem::take(&mut self.rlp_buf);
for (level, path) in targets {
buffers.path_stack.push(RlpNodePathStackItem {
level,
path,
is_in_prefix_set: Some(true),
});
self.rlp_node(&mut prefix_set, &mut buffers);
self.rlp_node(&mut prefix_set, &mut buffers, &mut temp_rlp_buf);
}
self.rlp_buf = temp_rlp_buf;
}

/// Returns a list of (level, path) tuples identifying the nodes that have changed at the
Expand Down Expand Up @@ -971,7 +973,11 @@ impl<P> RevealedSparseTrie<P> {
/// If the node at provided path does not exist.
pub fn rlp_node_allocate(&mut self, prefix_set: &mut PrefixSet) -> RlpNode {
let mut buffers = RlpNodeBuffers::new_with_root_path();
self.rlp_node(prefix_set, &mut buffers)
let mut temp_rlp_buf = core::mem::take(&mut self.rlp_buf);
let result = self.rlp_node(prefix_set, &mut buffers, &mut temp_rlp_buf);
self.rlp_buf = temp_rlp_buf;

result
}

/// Looks up or computes the RLP encoding of the node specified by the current
Expand All @@ -992,6 +998,7 @@ impl<P> RevealedSparseTrie<P> {
&mut self,
prefix_set: &mut PrefixSet,
buffers: &mut RlpNodeBuffers,
rlp_buf: &mut Vec<u8>,
) -> RlpNode {
let _starting_path = buffers.path_stack.last().map(|item| item.path.clone());

Expand Down Expand Up @@ -1025,8 +1032,8 @@ impl<P> RevealedSparseTrie<P> {
(RlpNode::word_rlp(&hash), SparseNodeType::Leaf)
} else {
let value = self.values.get(&path).unwrap();
self.rlp_buf.clear();
let rlp_node = LeafNodeRef { key, value }.rlp(&mut self.rlp_buf);
rlp_buf.clear();
let rlp_node = LeafNodeRef { key, value }.rlp(rlp_buf);
*hash = rlp_node.as_hash();
(rlp_node, SparseNodeType::Leaf)
}
Expand All @@ -1047,8 +1054,8 @@ impl<P> RevealedSparseTrie<P> {
rlp_node: child,
node_type: child_node_type,
} = buffers.rlp_node_stack.pop().unwrap();
self.rlp_buf.clear();
let rlp_node = ExtensionNodeRef::new(key, &child).rlp(&mut self.rlp_buf);
rlp_buf.clear();
let rlp_node = ExtensionNodeRef::new(key, &child).rlp(rlp_buf);
*hash = rlp_node.as_hash();

let store_in_db_trie_value = child_node_type.store_in_db_trie();
Expand Down Expand Up @@ -1199,10 +1206,10 @@ impl<P> RevealedSparseTrie<P> {
"Branch node masks"
);

self.rlp_buf.clear();
rlp_buf.clear();
let branch_node_ref =
BranchNodeRef::new(&buffers.branch_value_stack_buf, *state_mask);
let rlp_node = branch_node_ref.rlp(&mut self.rlp_buf);
let rlp_node = branch_node_ref.rlp(rlp_buf);
*hash = rlp_node.as_hash();

// Save a branch node update only if it's not a root node, and we need to
Expand Down
Loading