Skip to content

Commit

Permalink
fix: trie should check if stem_state_write.writes is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
morph-dev committed Jul 31, 2024
1 parent 65ce730 commit 8a91945
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 4 additions & 0 deletions portal-verkle-primitives/src/verkle/nodes/branch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ impl BranchNode {
/// Returns by how much the commitmant hash has changed and the path to the new branch node if
/// one was created.
pub fn update(&mut self, state_write: &StemStateWrite) -> (ScalarField, NewBranchNode) {
if state_write.writes.is_empty() {
return (ScalarField::zero(), None);
}

let index = state_write.stem[self.depth];
let child = &mut self.children[index as usize];
match child {
Expand Down
6 changes: 5 additions & 1 deletion portal-verkle-primitives/src/verkle/trie.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ impl VerkleTrie {
pub fn update(&mut self, state_writes: &StateWrites) -> HashSet<TriePath> {
let mut created_branches = HashSet::new();
for stem_state_write in state_writes.iter() {
if let Some(created_branch) = self.root_node.update(stem_state_write).1 {
if stem_state_write.writes.is_empty() {
continue;
}
let (_, created_branch) = self.root_node.update(stem_state_write);
if let Some(created_branch) = created_branch {
created_branches.insert(created_branch);
}
}
Expand Down

0 comments on commit 8a91945

Please sign in to comment.