diff options
author | Felix Lange <fjl@twurst.com> | 2016-10-18 05:01:29 +0800 |
---|---|---|
committer | Felix Lange <fjl@twurst.com> | 2016-10-18 10:57:47 +0800 |
commit | 8d56bf5ceb74a7ed45c986450848a89e2df61189 (patch) | |
tree | 4d035a7ddd60c0407a5f05e61ab9bf664d0db90c /trie/trie_test.go | |
parent | 44f419ec0f491a632658213ac8bbd0c132e0ffcf (diff) | |
download | go-tangerine-8d56bf5ceb74a7ed45c986450848a89e2df61189.tar go-tangerine-8d56bf5ceb74a7ed45c986450848a89e2df61189.tar.gz go-tangerine-8d56bf5ceb74a7ed45c986450848a89e2df61189.tar.bz2 go-tangerine-8d56bf5ceb74a7ed45c986450848a89e2df61189.tar.lz go-tangerine-8d56bf5ceb74a7ed45c986450848a89e2df61189.tar.xz go-tangerine-8d56bf5ceb74a7ed45c986450848a89e2df61189.tar.zst go-tangerine-8d56bf5ceb74a7ed45c986450848a89e2df61189.zip |
trie: ensure dirty flag is unset for embedded child nodes
This was caught by the new invariant check.
Diffstat (limited to 'trie/trie_test.go')
-rw-r--r-- | trie/trie_test.go | 43 |
1 files changed, 28 insertions, 15 deletions
diff --git a/trie/trie_test.go b/trie/trie_test.go index da0d2360b..14ac5a666 100644 --- a/trie/trie_test.go +++ b/trie/trie_test.go @@ -462,31 +462,44 @@ func runRandTest(rt randTest) bool { return false } case opCheckCacheInvariant: - return checkCacheInvariant(tr.root, tr.cachegen, 0) + return checkCacheInvariant(tr.root, nil, tr.cachegen, false, 0) } } return true } -func checkCacheInvariant(n node, parentCachegen uint16, depth int) bool { +func checkCacheInvariant(n, parent node, parentCachegen uint16, parentDirty bool, depth int) bool { + var children []node + var flag nodeFlag switch n := n.(type) { case *shortNode: - if n.flags.gen > parentCachegen { - fmt.Printf("cache invariant violation: %d > %d\nat depth %d node %s", n.flags.gen, parentCachegen, depth, spew.Sdump(n)) - return false - } - return checkCacheInvariant(n.Val, n.flags.gen, depth+1) + flag = n.flags + children = []node{n.Val} case *fullNode: - if n.flags.gen > parentCachegen { - fmt.Printf("cache invariant violation: %d > %d\nat depth %d node %s", n.flags.gen, parentCachegen, depth, spew.Sdump(n)) + flag = n.flags + children = n.Children[:] + default: + return true + } + + showerror := func() { + fmt.Printf("at depth %d node %s", depth, spew.Sdump(n)) + fmt.Printf("parent: %s", spew.Sdump(parent)) + } + if flag.gen > parentCachegen { + fmt.Printf("cache invariant violation: %d > %d\n", flag.gen, parentCachegen) + showerror() + return false + } + if depth > 0 && !parentDirty && flag.dirty { + fmt.Printf("cache invariant violation: child is dirty but parent isn't\n") + showerror() + return false + } + for _, child := range children { + if !checkCacheInvariant(child, n, flag.gen, flag.dirty, depth+1) { return false } - for _, child := range n.Children { - if !checkCacheInvariant(child, n.flags.gen, depth+1) { - return false - } - } - return true } return true } |