fix: capture child node as goroutine parameter to avoid closure bug, add clarifying comments about fullNode Children structure

This commit is contained in:
floor-licker 2025-12-10 07:39:23 -05:00
parent 4bc5c5c374
commit 56325ab7c5
No known key found for this signature in database
GPG key ID: 00CAB0DF8891321D

View file

@ -98,7 +98,9 @@ func (c *committer) commitChildren(path []byte, n *fullNode, parallel bool) {
} }
// If it's the hashed child, save the hash value directly. // If it's the hashed child, save the hash value directly.
// Note: it's impossible that the child in range [0, 15] // Note: it's impossible that the child in range [0, 15]
// is a valueNode. // is a valueNode. Values are only stored in Children[16]
// (the 17th slot) when a key terminates at a branch node.
// Children[0-15] are structural slots for hex digit routing.
if _, ok := child.(hashNode); ok { if _, ok := child.(hashNode); ok {
continue continue
} }
@ -109,14 +111,14 @@ func (c *committer) commitChildren(path []byte, n *fullNode, parallel bool) {
n.Children[i] = c.commit(append(path, byte(i)), child, false) n.Children[i] = c.commit(append(path, byte(i)), child, false)
} else { } else {
wg.Add(1) wg.Add(1)
go func(index int) { go func(index int, child node) {
defer wg.Done() defer wg.Done()
subset := trienode.NewNodeSet(c.nodes.Owner) subset := trienode.NewNodeSet(c.nodes.Owner)
subCom := newCommitter(subset, c.tracer, c.collectLeaf) subCom := newCommitter(subset, c.tracer, c.collectLeaf)
n.Children[index] = subCom.commit(append(path, byte(index)), child, false) n.Children[index] = subCom.commit(append(path, byte(index)), child, false)
subsets[index] = subset subsets[index] = subset
}(i) }(i, child)
} }
} }
if parallel { if parallel {