mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 07:06:42 +00:00
mutex protection on trieReader storages
This commit is contained in:
parent
6519ce6fbe
commit
375260e859
1 changed files with 14 additions and 6 deletions
|
|
@ -19,6 +19,7 @@ package state
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"maps"
|
"maps"
|
||||||
|
"sync"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/core/state/snapshot"
|
"github.com/ethereum/go-ethereum/core/state/snapshot"
|
||||||
|
|
@ -145,6 +146,8 @@ type trieReader struct {
|
||||||
mainTrie Trie // Main trie, resolved in constructor
|
mainTrie Trie // Main trie, resolved in constructor
|
||||||
subRoots map[common.Address]common.Hash // Set of storage roots, cached when the account is resolved
|
subRoots map[common.Address]common.Hash // Set of storage roots, cached when the account is resolved
|
||||||
subTries map[common.Address]Trie // Group of storage tries, cached when it's resolved
|
subTries map[common.Address]Trie // Group of storage tries, cached when it's resolved
|
||||||
|
muSubRoot sync.Mutex
|
||||||
|
muSubTries sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
// trieReader constructs a trie reader of the specific state. An error will be
|
// trieReader constructs a trie reader of the specific state. An error will be
|
||||||
|
|
@ -181,11 +184,14 @@ func (r *trieReader) Account(addr common.Address) (*types.StateAccount, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
r.muSubRoot.Lock()
|
||||||
if account == nil {
|
if account == nil {
|
||||||
r.subRoots[addr] = types.EmptyRootHash
|
r.subRoots[addr] = types.EmptyRootHash
|
||||||
} else {
|
} else {
|
||||||
r.subRoots[addr] = account.Root
|
r.subRoots[addr] = account.Root
|
||||||
}
|
}
|
||||||
|
r.muSubRoot.Unlock()
|
||||||
|
|
||||||
return account, nil
|
return account, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -221,7 +227,9 @@ func (r *trieReader) Storage(addr common.Address, key common.Hash) (common.Hash,
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return common.Hash{}, err
|
return common.Hash{}, err
|
||||||
}
|
}
|
||||||
|
r.muSubTries.Lock()
|
||||||
r.subTries[addr] = tr
|
r.subTries[addr] = tr
|
||||||
|
r.muSubTries.Unlock()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ret, err := tr.GetStorage(addr, key.Bytes())
|
ret, err := tr.GetStorage(addr, key.Bytes())
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue