trie: remove nodes in the middle of shortNode and fullNode

This commit is contained in:
Gary Rong 2023-09-19 13:43:25 +08:00
parent 90d5bd85bc
commit 53fefd79b2
2 changed files with 8 additions and 0 deletions

View file

@ -63,6 +63,11 @@ func (c *committer) commit(path []byte, n node) node {
// otherwise it can only be hashNode or valueNode. // otherwise it can only be hashNode or valueNode.
if _, ok := cn.Val.(*fullNode); ok { if _, ok := cn.Val.(*fullNode); ok {
collapsed.Val = c.commit(append(path, cn.Key...), cn.Val) 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 // The key needs to be copied, since we're adding it to the
// modified nodeset. // modified nodeset.

View file

@ -378,6 +378,9 @@ func testIteratorContinueAfterError(t *testing.T, memonly bool, scheme string) {
) )
if memonly { if memonly {
for path, n := range nodes.Nodes { for path, n := range nodes.Nodes {
if n.IsDeleted() {
continue
}
paths = append(paths, []byte(path)) paths = append(paths, []byte(path))
hashes = append(hashes, n.Hash) hashes = append(hashes, n.Hash)
} }