From f66c7cc80d135452aac8eea97c5cfac26005b9d9 Mon Sep 17 00:00:00 2001 From: Roman Krasiuk Date: Fri, 17 Jan 2025 13:46:16 +0100 Subject: [PATCH] chore(trie): make rlp_node fns pub (#13818) --- crates/trie/sparse/src/trie.rs | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/crates/trie/sparse/src/trie.rs b/crates/trie/sparse/src/trie.rs index 9c35f7dee..1c5453cb6 100644 --- a/crates/trie/sparse/src/trie.rs +++ b/crates/trie/sparse/src/trie.rs @@ -645,12 +645,26 @@ impl

RevealedSparseTrie

{ targets } - fn rlp_node_allocate(&mut self, path: Nibbles, prefix_set: &mut PrefixSet) -> RlpNode { + /// Look up or calculate the RLP of the node at the given path. + /// + /// # Panics + /// + /// If the node at provided path does not exist. + pub fn rlp_node_allocate(&mut self, path: Nibbles, prefix_set: &mut PrefixSet) -> RlpNode { let mut buffers = RlpNodeBuffers::new_with_path(path); self.rlp_node(prefix_set, &mut buffers) } - fn rlp_node(&mut self, prefix_set: &mut PrefixSet, buffers: &mut RlpNodeBuffers) -> RlpNode { + /// Look up or calculate the RLP of the node at the given path specified in [`RlpNodeBuffers`]. + /// + /// # Panics + /// + /// If the node at provided path does not exist. + pub fn rlp_node( + &mut self, + prefix_set: &mut PrefixSet, + buffers: &mut RlpNodeBuffers, + ) -> RlpNode { 'main: while let Some((path, mut is_in_prefix_set)) = buffers.path_stack.pop() { // Check if the path is in the prefix set. // First, check the cached value. If it's `None`, then check the prefix set, and update @@ -1338,7 +1352,7 @@ struct RemovedSparseNode { /// Collection of reusable buffers for [`RevealedSparseTrie::rlp_node`]. #[derive(Debug, Default)] -struct RlpNodeBuffers { +pub struct RlpNodeBuffers { /// Stack of paths we need rlp nodes for and whether the path is in the prefix set. path_stack: Vec<(Nibbles, Option)>, /// Stack of rlp nodes