mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 02:12:23 +00:00
trie: fix mutex flaw
This commit is contained in:
parent
97de2299fd
commit
4abe141814
1 changed files with 4 additions and 4 deletions
|
|
@ -97,6 +97,7 @@ func (c *committer) commit(path []byte, n node, topmost bool) node {
|
||||||
func (c *committer) commitChildren(path []byte, n *fullNode, parallel bool) [17]node {
|
func (c *committer) commitChildren(path []byte, n *fullNode, parallel bool) [17]node {
|
||||||
var (
|
var (
|
||||||
wg sync.WaitGroup
|
wg sync.WaitGroup
|
||||||
|
nodesMu sync.Mutex
|
||||||
children [17]node
|
children [17]node
|
||||||
)
|
)
|
||||||
for i := 0; i < 16; i++ {
|
for i := 0; i < 16; i++ {
|
||||||
|
|
@ -118,15 +119,14 @@ func (c *committer) commitChildren(path []byte, n *fullNode, parallel bool) [17]
|
||||||
children[i] = c.commit(append(path, byte(i)), child, false)
|
children[i] = c.commit(append(path, byte(i)), child, false)
|
||||||
} else {
|
} else {
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
var nodesMu sync.Mutex
|
|
||||||
go func(index int) {
|
go func(index int) {
|
||||||
p := append(path, byte(i))
|
p := append(path, byte(i))
|
||||||
set := trienode.NewNodeSet(c.nodes.Owner)
|
childSet := trienode.NewNodeSet(c.nodes.Owner)
|
||||||
childComitter := newCommitter(set, c.tracer, c.collectLeaf, false)
|
childComitter := newCommitter(childSet, c.tracer, c.collectLeaf, false)
|
||||||
h := childComitter.commit(p, child, false)
|
h := childComitter.commit(p, child, false)
|
||||||
children[index] = h
|
children[index] = h
|
||||||
nodesMu.Lock()
|
nodesMu.Lock()
|
||||||
c.nodes.MergeSet(set)
|
c.nodes.MergeSet(childSet)
|
||||||
nodesMu.Unlock()
|
nodesMu.Unlock()
|
||||||
wg.Done()
|
wg.Done()
|
||||||
}(i)
|
}(i)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue