diff --git a/lib/trie/trie.go b/lib/trie/trie.go index 2658e3f40c..f0bb4b5463 100644 --- a/lib/trie/trie.go +++ b/lib/trie/trie.go @@ -764,7 +764,7 @@ func handleDeletion(p *node.Branch, key []byte) Node { // if branch has no children, just a value, turn it into a leaf if bitmap == 0 && p.Value != nil { - n = node.NewLeaf(key[:length], p.Value, true, 0) + n = node.NewLeaf(key[:length], p.Value, true, p.Generation) } else if p.NumChildren() == 1 && p.Value == nil { // there is only 1 child and no value, combine the child branch with this branch // find index of child @@ -779,7 +779,14 @@ func handleDeletion(p *node.Branch, key []byte) Node { child := p.Children[i] switch c := child.(type) { case *node.Leaf: - n = &node.Leaf{Key: append(append(p.Key, []byte{byte(i)}...), c.Key...), Value: c.Value} + key = append(append(p.Key, []byte{byte(i)}...), c.Key...) + const dirty = true + n = node.NewLeaf( + key, + c.Value, + dirty, + p.Generation, + ) case *node.Branch: br := new(node.Branch) br.Key = append(p.Key, append([]byte{byte(i)}, c.Key...)...) @@ -792,6 +799,7 @@ func handleDeletion(p *node.Branch, key []byte) Node { } br.Value = c.Value + br.Generation = p.Generation n = br default: // do nothing diff --git a/lib/trie/trie_endtoend_test.go b/lib/trie/trie_endtoend_test.go index 277a05b55f..d33c856027 100644 --- a/lib/trie/trie_endtoend_test.go +++ b/lib/trie/trie_endtoend_test.go @@ -938,8 +938,9 @@ func TestClearPrefix_Small(t *testing.T) { ssTrie.ClearPrefix([]byte("noo")) expectedRoot := &node.Leaf{ - Key: codec.KeyLEToNibbles([]byte("other")), - Value: []byte("other"), + Key: codec.KeyLEToNibbles([]byte("other")), + Value: []byte("other"), + Generation: 1, } expectedRoot.SetDirty(true)