mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 02:12:23 +00:00
ethash: Use KeccackFast for cache generation
This commit is contained in:
parent
47cec850c1
commit
8e61afff2d
1 changed files with 4 additions and 16 deletions
|
|
@ -18,7 +18,6 @@ package ethash
|
|||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"hash"
|
||||
"math/big"
|
||||
"reflect"
|
||||
"runtime"
|
||||
|
|
@ -94,17 +93,6 @@ func calcDatasetSize(epoch int) uint64 {
|
|||
// reused between hash runs instead of requiring new ones to be created.
|
||||
type hasher func(dest []byte, data []byte)
|
||||
|
||||
// makeHasher creates a repetitive hasher, allowing the same hash data structures
|
||||
// to be reused between hash runs instead of requiring new ones to be created.
|
||||
// The returned function is not thread safe!
|
||||
func makeHasher(h hash.Hash) hasher {
|
||||
return func(dest []byte, data []byte) {
|
||||
h.Write(data)
|
||||
h.Sum(dest[:0])
|
||||
h.Reset()
|
||||
}
|
||||
}
|
||||
|
||||
// seedHash is the seed to use for generating a verification cache and the mining
|
||||
// dataset.
|
||||
func seedHash(block uint64) []byte {
|
||||
|
|
@ -112,7 +100,7 @@ func seedHash(block uint64) []byte {
|
|||
if block < epochLength {
|
||||
return seed
|
||||
}
|
||||
keccak256 := makeHasher(sha3.NewKeccak256())
|
||||
keccak256 := sha3.KeccakFast256
|
||||
for i := 0; i < int(block/epochLength); i++ {
|
||||
keccak256(seed, seed)
|
||||
}
|
||||
|
|
@ -166,7 +154,7 @@ func generateCache(dest []uint32, epoch uint64, seed []byte) {
|
|||
}
|
||||
}()
|
||||
// Create a hasher to reuse between invocations
|
||||
keccak512 := makeHasher(sha3.NewKeccak512())
|
||||
keccak512 := sha3.KeccakFast512
|
||||
|
||||
// Sequentially produce the initial dataset
|
||||
keccak512(cache, seed)
|
||||
|
|
@ -299,7 +287,7 @@ func generateDataset(dest []uint32, epoch uint64, cache []uint32) {
|
|||
defer pend.Done()
|
||||
|
||||
// Create a hasher to reuse between invocations
|
||||
keccak512 := makeHasher(sha3.NewKeccak512())
|
||||
keccak512 := sha3.KeccakFast512
|
||||
|
||||
// Calculate the data segment this thread should generate
|
||||
batch := uint32((size + hashBytes*uint64(threads) - 1) / (hashBytes * uint64(threads)))
|
||||
|
|
@ -373,7 +361,7 @@ func hashimoto(hash []byte, nonce uint64, size uint64, lookup func(index uint32)
|
|||
// in-memory cache) in order to produce our final value for a particular header
|
||||
// hash and nonce.
|
||||
func hashimotoLight(size uint64, cache []uint32, hash []byte, nonce uint64) ([]byte, []byte) {
|
||||
keccak512 := makeHasher(sha3.NewKeccak512())
|
||||
keccak512 := sha3.KeccakFast512
|
||||
|
||||
lookup := func(index uint32) []uint32 {
|
||||
rawData := generateDatasetItem(cache, index, keccak512)
|
||||
|
|
|
|||
Loading…
Reference in a new issue