Skip to content

Commit

Permalink
gc when delete
Browse files Browse the repository at this point in the history
  • Loading branch information
lightsing committed Sep 13, 2024
1 parent d208469 commit 338924c
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/trie/zktrie/imp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,13 +429,14 @@ impl<H: HashScheme, Db: KVDatabase, K: KeyHasher<H>> ZkTrie<H, Db, K> {
if level >= H::TRIE_MAX_LEVELS {
return Err(ZkTrieError::MaxLevelReached);
}
let root = self.get_node_by_hash(root_hash)?;
let root = self.get_node_by_hash(root_hash.clone())?;
match root.node_type() {
NodeType::Empty => Err(ZkTrieError::NodeNotFound),
NodeType::Leaf => {
if root.as_leaf().unwrap().node_key() != &node_key {
Err(ZkTrieError::NodeNotFound)
} else {
self.gc_nodes.insert(root_hash);
Ok((LazyNodeHash::Hash(ZkHash::ZERO), true))
}
}
Expand Down Expand Up @@ -502,6 +503,7 @@ impl<H: HashScheme, Db: KVDatabase, K: KeyHasher<H>> ZkTrie<H, Db, K> {
resolved: new_parent.node_hash.clone(),
});

self.gc_nodes.insert(root_hash);
self.dirty_branch_nodes.push(new_parent);

Ok((lazy_hash, false))
Expand Down

0 comments on commit 338924c

Please sign in to comment.