aboutsummaryrefslogtreecommitdiffstats
path: root/pow/ethash.go
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2017-03-23 16:56:12 +0800
committerGitHub <noreply@github.com>2017-03-23 16:56:12 +0800
commit61d2150a0750a554250c3bf090ef994be6c060f0 (patch)
tree56dd67f447fcc2992cf88ef68b074799f9c1468c /pow/ethash.go
parent3fa0fa713bc1508835bdecd7dea78ff09803e327 (diff)
parent24dd0355a34a40b1798c9b8bd97a7332a77e2556 (diff)
downloadgo-tangerine-61d2150a0750a554250c3bf090ef994be6c060f0.tar
go-tangerine-61d2150a0750a554250c3bf090ef994be6c060f0.tar.gz
go-tangerine-61d2150a0750a554250c3bf090ef994be6c060f0.tar.bz2
go-tangerine-61d2150a0750a554250c3bf090ef994be6c060f0.tar.lz
go-tangerine-61d2150a0750a554250c3bf090ef994be6c060f0.tar.xz
go-tangerine-61d2150a0750a554250c3bf090ef994be6c060f0.tar.zst
go-tangerine-61d2150a0750a554250c3bf090ef994be6c060f0.zip
Merge pull request #3795 from fjl/pow-fix-test-mode
pow: fix Search with ethash test mode
Diffstat (limited to 'pow/ethash.go')
-rw-r--r--pow/ethash.go26
1 files changed, 10 insertions, 16 deletions
diff --git a/pow/ethash.go b/pow/ethash.go
index 1e577a587..9adc38540 100644
--- a/pow/ethash.go
+++ b/pow/ethash.go
@@ -428,7 +428,7 @@ func (ethash *Ethash) cache(block uint64) []uint32 {
current, future := ethash.caches[epoch], (*cache)(nil)
if current == nil {
// No in-memory cache, evict the oldest if the cache limit was reached
- for len(ethash.caches) >= ethash.cachesinmem {
+ for len(ethash.caches) > 0 && len(ethash.caches) >= ethash.cachesinmem {
var evict *cache
for _, cache := range ethash.caches {
if evict == nil || evict.used.After(cache.used) {
@@ -480,22 +480,16 @@ func (ethash *Ethash) cache(block uint64) []uint32 {
// Search implements PoW, attempting to find a nonce that satisfies the block's
// difficulty requirements.
func (ethash *Ethash) Search(block Block, stop <-chan struct{}) (uint64, []byte) {
- // Extract some data from the block
- var (
- hash = block.HashNoNonce().Bytes()
- diff = block.Difficulty()
- target = new(big.Int).Div(maxUint256, diff)
- )
- // Retrieve the mining dataset
- dataset, size := ethash.dataset(block.NumberU64()), datasetSize(block.NumberU64())
-
- // Start generating random nonces until we abort or find a good one
var (
+ hash = block.HashNoNonce().Bytes()
+ diff = block.Difficulty()
+ target = new(big.Int).Div(maxUint256, diff)
+ dataset = ethash.dataset(block.NumberU64())
+ rand = rand.New(rand.NewSource(time.Now().UnixNano()))
+ nonce = uint64(rand.Int63())
attempts int64
-
- rand = rand.New(rand.NewSource(time.Now().UnixNano()))
- nonce = uint64(rand.Int63())
)
+ // Start generating random nonces until we abort or find a good one
for {
select {
case <-stop:
@@ -511,7 +505,7 @@ func (ethash *Ethash) Search(block Block, stop <-chan struct{}) (uint64, []byte)
attempts = 0
}
// Compute the PoW value of this nonce
- digest, result := hashimotoFull(size, dataset, hash, nonce)
+ digest, result := hashimotoFull(dataset, hash, nonce)
if new(big.Int).SetBytes(result).Cmp(target) <= 0 {
return nonce, digest
}
@@ -532,7 +526,7 @@ func (ethash *Ethash) dataset(block uint64) []uint32 {
current, future := ethash.datasets[epoch], (*dataset)(nil)
if current == nil {
// No in-memory dataset, evict the oldest if the dataset limit was reached
- for len(ethash.datasets) >= ethash.dagsinmem {
+ for len(ethash.datasets) > 0 && len(ethash.datasets) >= ethash.dagsinmem {
var evict *dataset
for _, dataset := range ethash.datasets {
if evict == nil || evict.used.After(dataset.used) {