From a182c768158eb52da391bb52ce61c0c4bc2b20a3 Mon Sep 17 00:00:00 2001 From: ucwong Date: Fri, 2 Jul 2021 15:18:50 +0800 Subject: [PATCH] consensus/clique: avoid a copy in clique (#23149) * consensus/clique:optimize to avoid a copy in clique * consensus/clique: test for sealhash Co-authored-by: Martin Holst Swende --- consensus/clique/clique.go | 2 +- consensus/clique/clique_test.go | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/consensus/clique/clique.go b/consensus/clique/clique.go index b693e80518..449095e723 100644 --- a/consensus/clique/clique.go +++ b/consensus/clique/clique.go @@ -710,7 +710,7 @@ func (c *Clique) APIs(chain consensus.ChainHeaderReader) []rpc.API { func SealHash(header *types.Header) (hash common.Hash) { hasher := sha3.NewLegacyKeccak256() encodeSigHeader(hasher, header) - hasher.Sum(hash[:0]) + hasher.(crypto.KeccakState).Read(hash[:]) return hash } diff --git a/consensus/clique/clique_test.go b/consensus/clique/clique_test.go index 4b8ff807f6..1bd32acd37 100644 --- a/consensus/clique/clique_test.go +++ b/consensus/clique/clique_test.go @@ -112,3 +112,16 @@ func TestReimportMirroredState(t *testing.T) { t.Fatalf("chain head mismatch: have %d, want %d", head, 3) } } + +func TestSealHash(t *testing.T) { + have := SealHash(&types.Header{ + Difficulty: new(big.Int), + Number: new(big.Int), + Extra: make([]byte, 32+65), + BaseFee: new(big.Int), + }) + want := common.HexToHash("0xbd3d1fa43fbc4c5bfcc91b179ec92e2861df3654de60468beb908ff805359e8f") + if have != want { + t.Errorf("have %x, want %x", have, want) + } +}