aboutsummaryrefslogtreecommitdiffstats
path: root/consensus/ethash/consensus.go
diff options
context:
space:
mode:
Diffstat (limited to 'consensus/ethash/consensus.go')
-rw-r--r--consensus/ethash/consensus.go10
1 files changed, 7 insertions, 3 deletions
diff --git a/consensus/ethash/consensus.go b/consensus/ethash/consensus.go
index 82d23c92b..92a23d4a4 100644
--- a/consensus/ethash/consensus.go
+++ b/consensus/ethash/consensus.go
@@ -476,7 +476,7 @@ func (ethash *Ethash) VerifySeal(chain consensus.ChainReader, header *types.Head
}
// Sanity check that the block number is below the lookup table size (60M blocks)
number := header.Number.Uint64()
- if number/epochLength >= uint64(len(cacheSizes)) {
+ if number/epochLength >= maxEpoch {
// Go < 1.7 cannot calculate new cache/dataset sizes (no fast prime check)
return errNonceOutOfRange
}
@@ -484,14 +484,18 @@ func (ethash *Ethash) VerifySeal(chain consensus.ChainReader, header *types.Head
if header.Difficulty.Sign() <= 0 {
return errInvalidDifficulty
}
+
// Recompute the digest and PoW value and verify against the header
cache := ethash.cache(number)
-
size := datasetSize(number)
if ethash.config.PowMode == ModeTest {
size = 32 * 1024
}
- digest, result := hashimotoLight(size, cache, header.HashNoNonce().Bytes(), header.Nonce.Uint64())
+ digest, result := hashimotoLight(size, cache.cache, header.HashNoNonce().Bytes(), header.Nonce.Uint64())
+ // Caches are unmapped in a finalizer. Ensure that the cache stays live
+ // until after the call to hashimotoLight so it's not unmapped while being used.
+ runtime.KeepAlive(cache)
+
if !bytes.Equal(header.MixDigest[:], digest) {
return errInvalidMixDigest
}