diff options
Diffstat (limited to 'pow/ethash_algo.go')
-rw-r--r-- | pow/ethash_algo.go | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/pow/ethash_algo.go b/pow/ethash_algo.go index ace482b93..3737cc5d7 100644 --- a/pow/ethash_algo.go +++ b/pow/ethash_algo.go @@ -225,7 +225,8 @@ func generateDataset(dest []uint32, epoch uint64, cache []uint32) { // Print some debug logs to allow analysis on low end devices logger := log.New("epoch", epoch) - defer func(start time.Time) { + start := time.Now() + defer func() { elapsed := time.Since(start) logFn := logger.Debug @@ -233,7 +234,7 @@ func generateDataset(dest []uint32, epoch uint64, cache []uint32) { logFn = logger.Info } logFn("Generated ethash verification cache", "elapsed", common.PrettyDuration(elapsed)) - }(time.Now()) + }() // Figure out whether the bytes need to be swapped for the machine swapped := !isLittleEndian() @@ -260,15 +261,15 @@ func generateDataset(dest []uint32, epoch uint64, cache []uint32) { keccak512 := makeHasher(sha3.NewKeccak512()) // Calculate the data segment this thread should generate - batch := uint32(size / hashBytes / uint64(threads)) - start := uint32(id) * batch - limit := start + batch + batch := uint32((size + hashBytes*uint64(threads) - 1) / (hashBytes * uint64(threads))) + first := uint32(id) * batch + limit := first + batch if limit > uint32(size/hashBytes) { limit = uint32(size / hashBytes) } // Calculate the dataset segment percent := uint32(size / hashBytes / 100) - for index := start; index < limit; index++ { + for index := first; index < limit; index++ { item := generateDatasetItem(cache, index, keccak512) if swapped { swap(item) @@ -276,7 +277,7 @@ func generateDataset(dest []uint32, epoch uint64, cache []uint32) { copy(dataset[index*hashBytes:], item) if status := atomic.AddUint32(&progress, 1); status%percent == 0 { - logger.Info("Generating DAG in progress", "percentage", uint64(status*100)/(size/hashBytes)) + logger.Info("Generating DAG in progress", "percentage", uint64(status*100)/(size/hashBytes), "elapsed", common.PrettyDuration(time.Since(start))) } } }(i) |