Skip to content

Commit

Permalink
ubqhash/algorithm: add blakeHasher (Sum based makeHasher) as blake2b …
Browse files Browse the repository at this point in the history
…has no Read func
  • Loading branch information
iquidus committed May 20, 2019
1 parent fd3a68b commit 354a334
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion consensus/ubqhash/algorithm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
// dataset.
func seedHash(block uint64) []byte {
Expand Down Expand Up @@ -184,7 +198,7 @@ func generateCache(dest []uint32, epoch uint64, seed []byte) {
keccak512 := makeHasher(sha3.NewLegacyKeccak512())
if epoch >= uip1Epoch {
h, _ := blake2b.New512(nil)
keccak512 = makeHasher(h)
keccak512 = blakeHasher(h) // use blakeHasher instead of makeHasher here.
}

// Sequentially produce the initial dataset
Expand Down

0 comments on commit 354a334

Please sign in to comment.