Skip to content

Commit

Permalink
reopen trie
Browse files Browse the repository at this point in the history
  • Loading branch information
unclezoro committed Jan 4, 2022
1 parent c01740f commit 85e5b73
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions core/state/trie_prefetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"sync"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/gopool"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/metrics"
)
Expand Down Expand Up @@ -257,9 +256,7 @@ func newSubfetcher(db Database, root common.Hash, accountHash common.Hash) *subf
seen: make(map[string]struct{}),
accountHash: accountHash,
}
gopool.Submit(func() {
sf.loop()
})
go sf.loop()
return sf
}

Expand Down Expand Up @@ -323,7 +320,6 @@ func (sf *subfetcher) loop() {
}
if err != nil {
log.Debug("Trie prefetcher failed opening trie", "root", sf.root, "err", err)
return
}
sf.trie = trie

Expand All @@ -332,6 +328,18 @@ func (sf *subfetcher) loop() {
select {
case <-sf.wake:
// Subfetcher was woken up, retrieve any tasks to avoid spinning the lock
if sf.trie == nil {
if sf.accountHash == emptyAddr {
sf.trie, err = sf.db.OpenTrie(sf.root)
} else {
// address is useless
sf.trie, err = sf.db.OpenStorageTrie(sf.accountHash, sf.root)
}
if err != nil {
continue
}
}

sf.lock.Lock()
tasks := sf.tasks
sf.tasks = nil
Expand Down

0 comments on commit 85e5b73

Please sign in to comment.