trie: move locking into trieDB insert method (#25030)
Move locking into trieDB insert function
This commit is contained in:
parent
096daa9a7d
commit
6b3e6cb2ab
|
@ -193,9 +193,7 @@ func (c *committer) store(n node, db *Database) node {
|
||||||
} else if db != nil {
|
} else if db != nil {
|
||||||
// No leaf-callback used, but there's still a database. Do serial
|
// No leaf-callback used, but there's still a database. Do serial
|
||||||
// insertion
|
// insertion
|
||||||
db.lock.Lock()
|
|
||||||
db.insert(common.BytesToHash(hash), size, n)
|
db.insert(common.BytesToHash(hash), size, n)
|
||||||
db.lock.Unlock()
|
|
||||||
}
|
}
|
||||||
return hash
|
return hash
|
||||||
}
|
}
|
||||||
|
@ -209,9 +207,7 @@ func (c *committer) commitLoop(db *Database) {
|
||||||
n = item.node
|
n = item.node
|
||||||
)
|
)
|
||||||
// We are pooling the trie nodes into an intermediate memory cache
|
// We are pooling the trie nodes into an intermediate memory cache
|
||||||
db.lock.Lock()
|
|
||||||
db.insert(hash, size, n)
|
db.insert(hash, size, n)
|
||||||
db.lock.Unlock()
|
|
||||||
|
|
||||||
if c.onleaf != nil {
|
if c.onleaf != nil {
|
||||||
switch n := n.(type) {
|
switch n := n.(type) {
|
||||||
|
|
|
@ -310,6 +310,9 @@ func (db *Database) DiskDB() ethdb.KeyValueStore {
|
||||||
// All nodes inserted by this function will be reference tracked
|
// All nodes inserted by this function will be reference tracked
|
||||||
// and in theory should only used for **trie nodes** insertion.
|
// and in theory should only used for **trie nodes** insertion.
|
||||||
func (db *Database) insert(hash common.Hash, size int, node node) {
|
func (db *Database) insert(hash common.Hash, size int, node node) {
|
||||||
|
db.lock.Lock()
|
||||||
|
defer db.lock.Unlock()
|
||||||
|
|
||||||
// If the node's already cached, skip
|
// If the node's already cached, skip
|
||||||
if _, ok := db.dirties[hash]; ok {
|
if _, ok := db.dirties[hash]; ok {
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in New Issue