From 8ef62d4a8137d44878d09264e79a42f7ec188b0f Mon Sep 17 00:00:00 2001 From: cwbhhjl Date: Thu, 10 Mar 2022 16:23:06 +0800 Subject: [PATCH] Merge PR: eth TxHash optimize (#1647) --- libs/tendermint/crypto/etherhash/hash.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/libs/tendermint/crypto/etherhash/hash.go b/libs/tendermint/crypto/etherhash/hash.go index 985d84f678..8ba5850c67 100644 --- a/libs/tendermint/crypto/etherhash/hash.go +++ b/libs/tendermint/crypto/etherhash/hash.go @@ -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[:] }