@@ -45,6 +45,11 @@ type usedMsg struct {
45
45
used [][]byte
46
46
}
47
47
48
+ type trieMsg struct {
49
+ root common.Hash
50
+ resultChan chan * subfetcher
51
+ }
52
+
48
53
// triePrefetcher is an active prefetcher, which receives accounts or storage
49
54
// items and does trie-loading of them. The goal is to get as much useful content
50
55
// into the caches as possible.
@@ -61,7 +66,7 @@ type triePrefetcher struct {
61
66
copyChan chan struct {}
62
67
copyDoneChan chan * triePrefetcher
63
68
prefetchChan chan * prefetchMsg // no need to wait for return
64
- trieChan chan * common. Hash
69
+ trieChan chan * trieMsg
65
70
trieDoneChan chan * subfetcher
66
71
usedChan chan * usedMsg // no need to wait for return
67
72
@@ -92,7 +97,7 @@ func newTriePrefetcher(db Database, root common.Hash, namespace string) *triePre
92
97
closeMainChan : make (chan struct {}),
93
98
closeMainDoneChan : make (chan struct {}),
94
99
prefetchChan : make (chan * prefetchMsg , concurrentChanSize ),
95
- trieChan : make (chan * common. Hash , concurrentChanSize ),
100
+ trieChan : make (chan * trieMsg , concurrentChanSize ),
96
101
trieDoneChan : make (chan * subfetcher , concurrentChanSize ),
97
102
usedChan : make (chan * usedMsg , concurrentChanSize ),
98
103
copyChan : make (chan struct {}, concurrentChanSize ),
@@ -136,13 +141,13 @@ func (p *triePrefetcher) mainLoop() {
136
141
}
137
142
fetcher .schedule (pMsg .keys )
138
143
139
- case tireHash := <- p .trieChan :
140
- fetcher := p .fetchers [* tireHash ]
144
+ case tireMsg := <- p .trieChan :
145
+ fetcher := p .fetchers [tireMsg . root ]
141
146
// bail if no trie was prefetched for this root
142
147
if fetcher == nil {
143
148
p .deliveryMissMeter .Mark (1 )
144
149
}
145
- p . trieDoneChan <- fetcher
150
+ tireMsg . resultChan <- fetcher
146
151
147
152
case uMsg := <- p .usedChan :
148
153
if fetcher := p .fetchers [uMsg .root ]; fetcher != nil {
@@ -262,8 +267,10 @@ func (p *triePrefetcher) trie(root common.Hash) Trie {
262
267
return p .db .CopyTrie (trie )
263
268
}
264
269
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
267
274
if fetcher == nil {
268
275
return nil
269
276
}
0 commit comments