trie: unset the edge valuenode as well

This commit is contained in:
rjl493456442 2020-04-23 18:54:02 +08:00
parent f63c68c245
commit 200f567e69
2 changed files with 14 additions and 4 deletions

View file

@ -264,11 +264,13 @@ func unset(root node, rest []byte, removeLeft bool) {
unset(rn.Children[rest[0]], rest[1:], removeLeft)
case *shortNode:
rn.flags = nodeFlag{dirty: true}
if _, ok := rn.Val.(valueNode); ok {
rn.Val = nil
return
}
unset(rn.Val, rest[len(rn.Key):], removeLeft)
case hashNode, nil:
case hashNode, nil, valueNode:
panic("it shouldn't happen")
case valueNode:
return
}
}

View file

@ -164,7 +164,7 @@ func TestBadRangeProof(t *testing.T) {
keys = append(keys, entries[i].k)
vals = append(vals, entries[i].v)
}
testcase := mrand.Intn(4)
testcase := mrand.Intn(6)
var index int
switch testcase {
case 0:
@ -188,6 +188,14 @@ func TestBadRangeProof(t *testing.T) {
index = mrand.Intn(end - start)
keys[index] = entries[len(entries)-1].k
vals[index] = entries[len(entries)-1].v
case 4:
// Set random key to nil
index = mrand.Intn(end - start)
keys[index] = nil
case 5:
// Set random value to nil
index = mrand.Intn(end - start)
vals[index] = nil
}
err := VerifyRangeProof(trie.Hash(), keys, vals, firstProof, lastProof)
if err == nil {