core/types: simplify CalcRequestsHash

Co-authored-by: Shude Li <islishude@gmail.com>
This commit is contained in:
Felix Lange 2024-10-09 10:23:36 +02:00
parent f27902e05c
commit b87d53679f

View file

@ -459,24 +459,15 @@ func CalcUncleHash(uncles []*Header) common.Hash {
// CalcRequestsHash creates the block requestsHash value for a list of requests. // CalcRequestsHash creates the block requestsHash value for a list of requests.
func CalcRequestsHash(requests [][]byte) common.Hash { func CalcRequestsHash(requests [][]byte) common.Hash {
// compute intermediate hashes h1, h2 := sha256.New(), sha256.New()
hashes := make([][32]byte, len(requests)) var buf common.Hash
h := sha256.New() for _, item := range requests {
for i, item := range requests { h1.Reset()
h.Reset() h1.Write(item)
h.Write(item) h2.Write(h1.Sum(buf[:0]))
var sum [32]byte
h.Sum(sum[:0])
hashes[i] = sum
} }
// final hash h2.Sum(buf[:0])
h.Reset() return buf
for _, hash := range hashes {
h.Write(hash[:])
}
var result common.Hash
h.Sum(result[:0])
return result
} }
// NewBlockWithHeader creates a block with the given header data. The // NewBlockWithHeader creates a block with the given header data. The