[TRIE] bug fix : if subtree deleted and sibling is shortcut, sibling would not have moved up (sibling can be shortcut without resulting from delete)
@@ -293,18 +293,14 @@ func (s *Trie) updateParallel(lnode, rnode, root []byte, lkeys, rkeys, lvalues,
}
// Move up a shortcut node if it's sibling is default
- if lresult.deleted && rresult.deleted {
- // root is never default when moving up a shortcut
- s.deleteCacheNode(root)
- if bytes.Equal(s.defaultHashes[height-1], lresult.update) && bytes.Equal(s.defaultHashes[height-1], rresult.update) {
- ch <- mresult{s.defaultHashes[height], false, nil}
+ if lresult.deleted {
+ if s.maybeMoveUpShortcut(lresult.update, rresult.update, root, height, ch) {
return
}
- // Move up one of the shortcut nodes
- if bytes.Equal(s.defaultHashes[height-1], lresult.update) {
- ch <- mresult{rresult.update, true, nil}
- } else if bytes.Equal(s.defaultHashes[height-1], rresult.update) {
- ch <- mresult{lresult.update, true, nil}
+ }
+ if rresult.deleted {
+ if s.maybeMoveUpShortcut(rresult.update, lresult.update, root, height, ch) {
+ return
}
}
node := s.interiorHash(lresult.update, rresult.update, height-1, root)
@@ -348,6 +344,11 @@ func (s *Trie) maybeMoveUpShortcut(update, sibling, root []byte, height uint64,
ch <- mresult{sibling, true, nil}
return true
}
+ if bytes.Equal(s.defaultHashes[height-1], sibling) {
+ s.deleteCacheNode(root)
+ ch <- mresult{s.defaultHashes[height], false, nil}
+ return true
+ }
} else if bytes.Equal(s.defaultHashes[height-1], sibling) {
// If update deleted something and returned a shortcut, return that
// shortcut if the sibling is default
