Skip to content

Commit

Permalink
consensus/clique: avoid a copy in clique (#23149)
Browse files Browse the repository at this point in the history
* consensus/clique:optimize to avoid a copy in clique

* consensus/clique: test for sealhash

Co-authored-by: Martin Holst Swende <[email protected]>
  • Loading branch information
ucwong and holiman authored Jul 2, 2021
1 parent 6ed812d commit a182c76
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion consensus/clique/clique.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
13 changes: 13 additions & 0 deletions consensus/clique/clique_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

0 comments on commit a182c76

Please sign in to comment.