mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat(trie): update sparse trie hashes below level (#11969)
This commit is contained in:
@ -518,34 +518,35 @@ impl RevealedSparseTrie {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Update node hashes only if their path exceeds the provided level.
|
/// Update hashes of the nodes that are located at a level deeper than or equal to the provided
|
||||||
pub fn update_rlp_node_level(&mut self, min_len: usize) {
|
/// depth. Root node has a level of 0.
|
||||||
let mut paths = Vec::from([Nibbles::default()]);
|
pub fn update_rlp_node_level(&mut self, depth: usize) {
|
||||||
|
let mut paths = Vec::from([(Nibbles::default(), 0)]);
|
||||||
let mut targets = HashSet::<Nibbles>::default();
|
let mut targets = HashSet::<Nibbles>::default();
|
||||||
|
|
||||||
while let Some(mut path) = paths.pop() {
|
while let Some((mut path, level)) = paths.pop() {
|
||||||
match self.nodes.get(&path).unwrap() {
|
match self.nodes.get(&path).unwrap() {
|
||||||
SparseNode::Empty | SparseNode::Hash(_) => {}
|
SparseNode::Empty | SparseNode::Hash(_) => {}
|
||||||
SparseNode::Leaf { .. } => {
|
SparseNode::Leaf { .. } => {
|
||||||
targets.insert(path);
|
targets.insert(path);
|
||||||
}
|
}
|
||||||
SparseNode::Extension { key, .. } => {
|
SparseNode::Extension { key, .. } => {
|
||||||
if path.len() >= min_len {
|
if level >= depth {
|
||||||
targets.insert(path);
|
targets.insert(path);
|
||||||
} else {
|
} else {
|
||||||
path.extend_from_slice_unchecked(key);
|
path.extend_from_slice_unchecked(key);
|
||||||
paths.push(path);
|
paths.push((path, level + 1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SparseNode::Branch { state_mask, .. } => {
|
SparseNode::Branch { state_mask, .. } => {
|
||||||
if path.len() >= min_len {
|
if level >= depth {
|
||||||
targets.insert(path);
|
targets.insert(path);
|
||||||
} else {
|
} else {
|
||||||
for bit in CHILD_INDEX_RANGE {
|
for bit in CHILD_INDEX_RANGE {
|
||||||
if state_mask.is_bit_set(bit) {
|
if state_mask.is_bit_set(bit) {
|
||||||
let mut child_path = path.clone();
|
let mut child_path = path.clone();
|
||||||
child_path.push_unchecked(bit);
|
child_path.push_unchecked(bit);
|
||||||
paths.push(child_path);
|
paths.push((child_path, level + 1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user