Skip to content

Commit a8ee0a1

Browse files
committed
fixups
1 parent 2c34f89 commit a8ee0a1

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

core/state/trie_prefetcher.go

+14-7
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ type usedMsg struct {
4545
used [][]byte
4646
}
4747

48+
type trieMsg struct {
49+
root common.Hash
50+
resultChan chan *subfetcher
51+
}
52+
4853
// triePrefetcher is an active prefetcher, which receives accounts or storage
4954
// items and does trie-loading of them. The goal is to get as much useful content
5055
// into the caches as possible.
@@ -61,7 +66,7 @@ type triePrefetcher struct {
6166
copyChan chan struct{}
6267
copyDoneChan chan *triePrefetcher
6368
prefetchChan chan *prefetchMsg // no need to wait for return
64-
trieChan chan *common.Hash
69+
trieChan chan *trieMsg
6570
trieDoneChan chan *subfetcher
6671
usedChan chan *usedMsg // no need to wait for return
6772

@@ -92,7 +97,7 @@ func newTriePrefetcher(db Database, root common.Hash, namespace string) *triePre
9297
closeMainChan: make(chan struct{}),
9398
closeMainDoneChan: make(chan struct{}),
9499
prefetchChan: make(chan *prefetchMsg, concurrentChanSize),
95-
trieChan: make(chan *common.Hash, concurrentChanSize),
100+
trieChan: make(chan *trieMsg, concurrentChanSize),
96101
trieDoneChan: make(chan *subfetcher, concurrentChanSize),
97102
usedChan: make(chan *usedMsg, concurrentChanSize),
98103
copyChan: make(chan struct{}, concurrentChanSize),
@@ -136,13 +141,13 @@ func (p *triePrefetcher) mainLoop() {
136141
}
137142
fetcher.schedule(pMsg.keys)
138143

139-
case tireHash := <-p.trieChan:
140-
fetcher := p.fetchers[*tireHash]
144+
case tireMsg := <-p.trieChan:
145+
fetcher := p.fetchers[tireMsg.root]
141146
// bail if no trie was prefetched for this root
142147
if fetcher == nil {
143148
p.deliveryMissMeter.Mark(1)
144149
}
145-
p.trieDoneChan <- fetcher
150+
tireMsg.resultChan <- fetcher
146151

147152
case uMsg := <-p.usedChan:
148153
if fetcher := p.fetchers[uMsg.root]; fetcher != nil {
@@ -262,8 +267,10 @@ func (p *triePrefetcher) trie(root common.Hash) Trie {
262267
return p.db.CopyTrie(trie)
263268
}
264269

265-
p.trieChan <- &root
266-
fetcher := <-p.trieDoneChan
270+
trieChan := make(chan *subfetcher)
271+
defer func() { close(trieChan) }()
272+
p.trieChan <- &trieMsg{root, trieChan}
273+
fetcher := <-trieChan
267274
if fetcher == nil {
268275
return nil
269276
}

0 commit comments

Comments
 (0)