Skip to content

Commit a182c76

Browse files
ucwongholiman
andauthored
consensus/clique: avoid a copy in clique (ethereum#23149)
* consensus/clique:optimize to avoid a copy in clique * consensus/clique: test for sealhash Co-authored-by: Martin Holst Swende <martin@swende.se>
1 parent 6ed812d commit a182c76

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

consensus/clique/clique.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,7 @@ func (c *Clique) APIs(chain consensus.ChainHeaderReader) []rpc.API {
710710
func SealHash(header *types.Header) (hash common.Hash) {
711711
hasher := sha3.NewLegacyKeccak256()
712712
encodeSigHeader(hasher, header)
713-
hasher.Sum(hash[:0])
713+
hasher.(crypto.KeccakState).Read(hash[:])
714714
return hash
715715
}
716716

consensus/clique/clique_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,16 @@ func TestReimportMirroredState(t *testing.T) {
112112
t.Fatalf("chain head mismatch: have %d, want %d", head, 3)
113113
}
114114
}
115+
116+
func TestSealHash(t *testing.T) {
117+
have := SealHash(&types.Header{
118+
Difficulty: new(big.Int),
119+
Number: new(big.Int),
120+
Extra: make([]byte, 32+65),
121+
BaseFee: new(big.Int),
122+
})
123+
want := common.HexToHash("0xbd3d1fa43fbc4c5bfcc91b179ec92e2861df3654de60468beb908ff805359e8f")
124+
if have != want {
125+
t.Errorf("have %x, want %x", have, want)
126+
}
127+
}

0 commit comments

Comments
 (0)