mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-22 04:36:42 +00:00
fix: closure capture race in generateTrieRoot goroutines
This commit is contained in:
parent
aa1a8dacae
commit
3e910b7a4c
2 changed files with 20 additions and 14 deletions
|
|
@ -298,23 +298,26 @@ func generateTrieRoot(db ethdb.KeyValueWriter, scheme string, it Iterator, accou
|
|||
return stop(err)
|
||||
}
|
||||
// Fetch the next account and process it concurrently
|
||||
account, err := types.FullAccount(it.(AccountIterator).Account())
|
||||
acc, err := types.FullAccount(it.(AccountIterator).Account())
|
||||
if err != nil {
|
||||
return stop(err)
|
||||
}
|
||||
go func(hash common.Hash) {
|
||||
subroot, err := leafCallback(db, hash, common.BytesToHash(account.CodeHash), stats)
|
||||
h := it.Hash()
|
||||
ch := common.BytesToHash(acc.CodeHash)
|
||||
wr := acc.Root
|
||||
go func(hash common.Hash, codeHash common.Hash, wantRoot common.Hash) {
|
||||
subroot, err := leafCallback(db, hash, codeHash, stats)
|
||||
if err != nil {
|
||||
results <- err
|
||||
return
|
||||
}
|
||||
if account.Root != subroot {
|
||||
results <- fmt.Errorf("invalid subroot(path %x), want %x, have %x", hash, account.Root, subroot)
|
||||
if wantRoot != subroot {
|
||||
results <- fmt.Errorf("invalid subroot(path %x), want %x, have %x", hash, wantRoot, subroot)
|
||||
return
|
||||
}
|
||||
results <- nil
|
||||
}(it.Hash())
|
||||
fullData, err = rlp.EncodeToBytes(account)
|
||||
}(h, ch, wr)
|
||||
fullData, err = rlp.EncodeToBytes(acc)
|
||||
if err != nil {
|
||||
return stop(err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -294,23 +294,26 @@ func generateTrieRoot(it Iterator, account common.Hash, generatorFn trieHasherFn
|
|||
return stop(err)
|
||||
}
|
||||
// Fetch the next account and process it concurrently
|
||||
account, err := types.FullAccount(it.(AccountIterator).Account())
|
||||
acc, err := types.FullAccount(it.(AccountIterator).Account())
|
||||
if err != nil {
|
||||
return stop(err)
|
||||
}
|
||||
go func(hash common.Hash) {
|
||||
subroot, err := leafCallback(hash, common.BytesToHash(account.CodeHash), stats)
|
||||
h := it.Hash()
|
||||
ch := common.BytesToHash(acc.CodeHash)
|
||||
wr := acc.Root
|
||||
go func(hash common.Hash, codeHash common.Hash, wantRoot common.Hash) {
|
||||
subroot, err := leafCallback(hash, codeHash, stats)
|
||||
if err != nil {
|
||||
results <- err
|
||||
return
|
||||
}
|
||||
if account.Root != subroot {
|
||||
results <- fmt.Errorf("invalid subroot(path %x), want %x, have %x", hash, account.Root, subroot)
|
||||
if wantRoot != subroot {
|
||||
results <- fmt.Errorf("invalid subroot(path %x), want %x, have %x", hash, wantRoot, subroot)
|
||||
return
|
||||
}
|
||||
results <- nil
|
||||
}(it.Hash())
|
||||
fullData, err = rlp.EncodeToBytes(account)
|
||||
}(h, ch, wr)
|
||||
fullData, err = rlp.EncodeToBytes(acc)
|
||||
if err != nil {
|
||||
return stop(err)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue