diff --git a/trie/committer.go b/trie/committer.go index 92163cdb3b..526c2c5439 100644 --- a/trie/committer.go +++ b/trie/committer.go @@ -63,6 +63,11 @@ func (c *committer) commit(path []byte, n node) node { // otherwise it can only be hashNode or valueNode. if _, ok := cn.Val.(*fullNode); ok { collapsed.Val = c.commit(append(path, cn.Key...), cn.Val) + + // Mark all internal nodes between parent and child as deleted. + for i := 1; i < len(cn.Key); i++ { + c.nodes.AddNode(append(path, cn.Key[:i]...), trienode.NewDeleted()) + } } // The key needs to be copied, since we're adding it to the // modified nodeset. diff --git a/trie/iterator_test.go b/trie/iterator_test.go index 57d1f06a16..1eab9983f5 100644 --- a/trie/iterator_test.go +++ b/trie/iterator_test.go @@ -378,6 +378,9 @@ func testIteratorContinueAfterError(t *testing.T, memonly bool, scheme string) { ) if memonly { for path, n := range nodes.Nodes { + if n.IsDeleted() { + continue + } paths = append(paths, []byte(path)) hashes = append(hashes, n.Hash) }