@@ -179,7 +179,7 @@ func newlru(what string, maxItems int, new func(epoch uint64, epochLength uint64
179
179
// get retrieves or creates an item for the given epoch. The first return value is always
180
180
// non-nil. The second return value is non-nil if lru thinks that an item will be useful in
181
181
// the near future.
182
- func (lru * lru ) get (epoch uint64 , epochLength uint64 ) (item , future interface {}) {
182
+ func (lru * lru ) get (epoch uint64 , epochLength uint64 , ecip1099FBlock * uint64 ) (item , future interface {}) {
183
183
lru .mu .Lock ()
184
184
defer lru .mu .Unlock ()
185
185
@@ -194,11 +194,23 @@ func (lru *lru) get(epoch uint64, epochLength uint64) (item, future interface{})
194
194
}
195
195
lru .cache .Add (epoch , item )
196
196
}
197
+
198
+ // Ensure pre-generation handles ecip-1099 changeover correctly
199
+ var nextEpoch = epoch + 1
200
+ var nextEpochLength = epochLength
201
+ if ecip1099FBlock != nil {
202
+ nextEpochBlock := nextEpoch * epochLength
203
+ if nextEpochBlock == * ecip1099FBlock && epochLength == epochLengthDefault {
204
+ nextEpoch = nextEpoch / 2
205
+ nextEpochLength = epochLengthECIP1099
206
+ }
207
+ }
208
+
197
209
// Update the 'future item' if epoch is larger than previously seen.
198
- if epoch < maxEpoch - 1 && lru .future < epoch + 1 {
199
- log .Trace ("Requiring new future ethash " + lru .what , "epoch" , epoch + 1 )
200
- future = lru .new (epoch + 1 , epochLength )
201
- lru .future = epoch + 1
210
+ if epoch < maxEpoch - 1 && lru .future < nextEpoch {
211
+ log .Trace ("Requiring new future ethash " + lru .what , "epoch" , nextEpoch )
212
+ future = lru .new (nextEpoch , nextEpochLength )
213
+ lru .future = nextEpoch
202
214
lru .futureItem = future
203
215
}
204
216
return item , future
@@ -561,7 +573,7 @@ func (ethash *Ethash) Close() error {
561
573
func (ethash * Ethash ) cache (block uint64 ) * cache {
562
574
epochLength := calcEpochLength (block , ethash .config .ECIP1099Block )
563
575
epoch := calcEpoch (block , epochLength )
564
- currentI , futureI := ethash .caches .get (epoch , epochLength )
576
+ currentI , futureI := ethash .caches .get (epoch , epochLength , ethash . config . ECIP1099Block )
565
577
current := currentI .(* cache )
566
578
567
579
// Wait for generation finish.
@@ -585,7 +597,7 @@ func (ethash *Ethash) dataset(block uint64, async bool) *dataset {
585
597
// Retrieve the requested ethash dataset
586
598
epochLength := calcEpochLength (block , ethash .config .ECIP1099Block )
587
599
epoch := calcEpoch (block , epochLength )
588
- currentI , futureI := ethash .datasets .get (epoch , epochLength )
600
+ currentI , futureI := ethash .datasets .get (epoch , epochLength , ethash . config . ECIP1099Block )
589
601
current := currentI .(* dataset )
590
602
591
603
// If async is specified, generate everything in a background thread
0 commit comments