trie: more review concerns

This commit is contained in:
Martin Holst Swende 2020-01-08 09:43:13 +01:00
parent e458b4248b
commit 692b758c75
No known key found for this signature in database
GPG key ID: 683B438C05A5DDF0
2 changed files with 6 additions and 6 deletions

View file

@ -30,8 +30,8 @@ import (
// some paralellism but not incur too much memory overhead. // some paralellism but not incur too much memory overhead.
const leafChanSize = 200 const leafChanSize = 200
// Leaf represents a trie leaf value // leaf represents a trie leaf value
type Leaf struct { type leaf struct {
size int // size of the rlp data (estimate) size int // size of the rlp data (estimate)
hash common.Hash // hash of rlp data hash common.Hash // hash of rlp data
node node // the node to commit node node // the node to commit
@ -49,7 +49,7 @@ type committer struct {
sha keccakState sha keccakState
onleaf LeafCallback onleaf LeafCallback
leafCh chan *Leaf leafCh chan *leaf
} }
// committers live in a global sync.Pool // committers live in a global sync.Pool
@ -81,7 +81,7 @@ func (c *committer) commitNeeded(n node) bool {
// commit collapses a node down into a hash node and inserts it into the database // commit collapses a node down into a hash node and inserts it into the database
func (c *committer) commit(n node, db *Database, force bool) (node, error) { func (c *committer) commit(n node, db *Database, force bool) (node, error) {
// If we're not storing the node, just hashing, use available cached data // if this path is clean, use available cached data
hash, dirty := n.cache() hash, dirty := n.cache()
if hash != nil && !dirty { if hash != nil && !dirty {
return hash, nil return hash, nil
@ -187,7 +187,7 @@ func (c *committer) store(n node, db *Database, force bool, hasVnodeChildren boo
// If we're using channel-based leaf-reporting, send to channel. // If we're using channel-based leaf-reporting, send to channel.
// The leaf channel will be active only when there an active leaf-callback // The leaf channel will be active only when there an active leaf-callback
if c.leafCh != nil { if c.leafCh != nil {
c.leafCh <- &Leaf{ c.leafCh <- &leaf{
size: size, size: size,
hash: common.BytesToHash(hash), hash: common.BytesToHash(hash),
node: n, node: n,

View file

@ -431,7 +431,7 @@ func (t *Trie) Commit(onleaf LeafCallback) (root common.Hash, err error) {
var wg sync.WaitGroup var wg sync.WaitGroup
if onleaf != nil { if onleaf != nil {
h.onleaf = onleaf h.onleaf = onleaf
h.leafCh = make(chan *Leaf, leafChanSize) h.leafCh = make(chan *leaf, leafChanSize)
wg.Add(1) wg.Add(1)
go func() { go func() {
defer wg.Done() defer wg.Done()