mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
ubqhash/algorithm: add blakeHasher (Sum based makeHasher) as blake2b has no Read func
This commit is contained in:
parent
fd3a68bd34
commit
354a3344c1
1 changed files with 15 additions and 1 deletions
|
|
@ -120,6 +120,20 @@ func makeHasher(h hash.Hash) hasher {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// blakeHasher 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!
|
||||||
|
// based on previous Sum based makeHasher as blake2b lacks a Read function - iquidus
|
||||||
|
func blakeHasher(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
|
// seedHash is the seed to use for generating a verification cache and the mining
|
||||||
// dataset.
|
// dataset.
|
||||||
func seedHash(block uint64) []byte {
|
func seedHash(block uint64) []byte {
|
||||||
|
|
@ -184,7 +198,7 @@ func generateCache(dest []uint32, epoch uint64, seed []byte) {
|
||||||
keccak512 := makeHasher(sha3.NewLegacyKeccak512())
|
keccak512 := makeHasher(sha3.NewLegacyKeccak512())
|
||||||
if epoch >= uip1Epoch {
|
if epoch >= uip1Epoch {
|
||||||
h, _ := blake2b.New512(nil)
|
h, _ := blake2b.New512(nil)
|
||||||
keccak512 = makeHasher(h)
|
keccak512 = blakeHasher(h) // use blakeHasher instead of makeHasher here.
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sequentially produce the initial dataset
|
// Sequentially produce the initial dataset
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue