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)
|
return stop(err)
|
||||||
}
|
}
|
||||||
// Fetch the next account and process it concurrently
|
// 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 {
|
if err != nil {
|
||||||
return stop(err)
|
return stop(err)
|
||||||
}
|
}
|
||||||
go func(hash common.Hash) {
|
h := it.Hash()
|
||||||
subroot, err := leafCallback(db, hash, common.BytesToHash(account.CodeHash), stats)
|
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 {
|
if err != nil {
|
||||||
results <- err
|
results <- err
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if account.Root != subroot {
|
if wantRoot != subroot {
|
||||||
results <- fmt.Errorf("invalid subroot(path %x), want %x, have %x", hash, account.Root, subroot)
|
results <- fmt.Errorf("invalid subroot(path %x), want %x, have %x", hash, wantRoot, subroot)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
results <- nil
|
results <- nil
|
||||||
}(it.Hash())
|
}(h, ch, wr)
|
||||||
fullData, err = rlp.EncodeToBytes(account)
|
fullData, err = rlp.EncodeToBytes(acc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return stop(err)
|
return stop(err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -294,23 +294,26 @@ func generateTrieRoot(it Iterator, account common.Hash, generatorFn trieHasherFn
|
||||||
return stop(err)
|
return stop(err)
|
||||||
}
|
}
|
||||||
// Fetch the next account and process it concurrently
|
// 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 {
|
if err != nil {
|
||||||
return stop(err)
|
return stop(err)
|
||||||
}
|
}
|
||||||
go func(hash common.Hash) {
|
h := it.Hash()
|
||||||
subroot, err := leafCallback(hash, common.BytesToHash(account.CodeHash), stats)
|
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 {
|
if err != nil {
|
||||||
results <- err
|
results <- err
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if account.Root != subroot {
|
if wantRoot != subroot {
|
||||||
results <- fmt.Errorf("invalid subroot(path %x), want %x, have %x", hash, account.Root, subroot)
|
results <- fmt.Errorf("invalid subroot(path %x), want %x, have %x", hash, wantRoot, subroot)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
results <- nil
|
results <- nil
|
||||||
}(it.Hash())
|
}(h, ch, wr)
|
||||||
fullData, err = rlp.EncodeToBytes(account)
|
fullData, err = rlp.EncodeToBytes(acc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return stop(err)
|
return stop(err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue