Skip to content

Commit

Permalink
Merge PR: eth TxHash optimize (#1647)
Browse files Browse the repository at this point in the history
  • Loading branch information
cwbhhjl authored Mar 10, 2022
1 parent 0261e6f commit 8ef62d4
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions libs/tendermint/crypto/etherhash/hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,22 @@ var keccakPool = sync.Pool{
New: func() interface{} { return sha3.NewLegacyKeccak256() },
}

type keccakState interface {
hash.Hash
Read([]byte) (int, error)
}

// Sum returns the non-standard Keccak256 of the bz.
func Sum(bz []byte) []byte {
sha := keccakPool.Get().(hash.Hash)
sha := keccakPool.Get().(keccakState)
defer func() {
// better to reset before putting it to the pool
sha.Reset()
keccakPool.Put(sha)
}()
sha.Reset()
sha.Write(bz)
return sha.Sum(nil)

var hashData [32]byte
sha.Read(hashData[:])
return hashData[:]
}

0 comments on commit 8ef62d4

Please sign in to comment.