aboutsummaryrefslogtreecommitdiffstats
path: root/trie/hasher.go
diff options
context:
space:
mode:
authorFelix Lange <fjl@twurst.com>2016-10-18 05:01:29 +0800
committerFelix Lange <fjl@twurst.com>2016-10-18 10:57:47 +0800
commit8d56bf5ceb74a7ed45c986450848a89e2df61189 (patch)
tree4d035a7ddd60c0407a5f05e61ab9bf664d0db90c /trie/hasher.go
parent44f419ec0f491a632658213ac8bbd0c132e0ffcf (diff)
downloadgo-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/hasher.go')
-rw-r--r--trie/hasher.go31
1 files changed, 14 insertions, 17 deletions
diff --git a/trie/hasher.go b/trie/hasher.go
index 57e156ebf..b6223bf32 100644
--- a/trie/hasher.go
+++ b/trie/hasher.go
@@ -75,23 +75,20 @@ func (h *hasher) hash(n node, db DatabaseWriter, force bool) (node, node, error)
if err != nil {
return hashNode{}, n, err
}
- // Cache the hash of the ndoe for later reuse.
- if hash, ok := hashed.(hashNode); ok && !force {
- switch cached := cached.(type) {
- case *shortNode:
- cached = cached.copy()
- cached.flags.hash = hash
- if db != nil {
- cached.flags.dirty = false
- }
- return hashed, cached, nil
- case *fullNode:
- cached = cached.copy()
- cached.flags.hash = hash
- if db != nil {
- cached.flags.dirty = false
- }
- return hashed, cached, nil
+ // Cache the hash of the ndoe for later reuse and remove
+ // the dirty flag in commit mode. It's fine to assign these values directly
+ // without copying the node first because hashChildren copies it.
+ cachedHash, _ := hashed.(hashNode)
+ switch cn := cached.(type) {
+ case *shortNode:
+ cn.flags.hash = cachedHash
+ if db != nil {
+ cn.flags.dirty = false
+ }
+ case *fullNode:
+ cn.flags.hash = cachedHash
+ if db != nil {
+ cn.flags.dirty = false
}
}
return hashed, cached, nil