github.com/sberex/go-sberex@v1.8.2-0.20181113200658-ed96ac38f7d7/consensus/ethash/algorithm_go1.7.go (about)

     1  // This file is part of the go-sberex library. The go-sberex library is 
     2  // free software: you can redistribute it and/or modify it under the terms 
     3  // of the GNU Lesser General Public License as published by the Free 
     4  // Software Foundation, either version 3 of the License, or (at your option)
     5  // any later version.
     6  //
     7  // The go-sberex library is distributed in the hope that it will be useful, 
     8  // but WITHOUT ANY WARRANTY; without even the implied warranty of
     9  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 
    10  // General Public License <http://www.gnu.org/licenses/> for more details.
    11  
    12  // +build !go1.8
    13  
    14  package ethash
    15  
    16  // cacheSize calculates and returns the size of the ethash verification cache that
    17  // belongs to a certain block number. The cache size grows linearly, however, we
    18  // always take the highest prime below the linearly growing threshold in order to
    19  // reduce the risk of accidental regularities leading to cyclic behavior.
    20  func cacheSize(block uint64) uint64 {
    21  	// If we have a pre-generated value, use that
    22  	epoch := int(block / epochLength)
    23  	if epoch < maxEpoch {
    24  		return cacheSizes[epoch]
    25  	}
    26  	// We don't have a way to verify primes fast before Go 1.8
    27  	panic("fast prime testing unsupported in Go < 1.8")
    28  }
    29  
    30  // datasetSize calculates and returns the size of the ethash mining dataset that
    31  // belongs to a certain block number. The dataset size grows linearly, however, we
    32  // always take the highest prime below the linearly growing threshold in order to
    33  // reduce the risk of accidental regularities leading to cyclic behavior.
    34  func datasetSize(block uint64) uint64 {
    35  	// If we have a pre-generated value, use that
    36  	epoch := int(block / epochLength)
    37  	if epoch < maxEpoch {
    38  		return datasetSizes[epoch]
    39  	}
    40  	// We don't have a way to verify primes fast before Go 1.8
    41  	panic("fast prime testing unsupported in Go < 1.8")
    42  }