Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

all: implement flat deposit requests encoding #30425

Merged
merged 32 commits into from
Oct 9, 2024
Merged
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
5db0c7b
all: implement flat deposit requests encoding
fjl Sep 12, 2024
89a441f
core/types: fix depositRequestType
fjl Sep 12, 2024
8735cf3
core/types: update deposit test
fjl Sep 12, 2024
a2abb4b
core/types: fix deposit request encoding
fjl Sep 12, 2024
b3cff4e
core/types: rename to CalcRequestsHash
fjl Sep 12, 2024
57f2ad1
internal/ethapi: return requests as hex
fjl Sep 12, 2024
c1c8a2c
internal/ethapi: avoid copying header
fjl Sep 12, 2024
54ac02b
eth/catalyst: fix withdrawals return
fjl Sep 12, 2024
c6ba1dc
eth/catalyst: improve test
fjl Sep 12, 2024
0fc9841
core: fix test
fjl Sep 12, 2024
ca1ed76
core/types: rename variable
fjl Sep 12, 2024
e9cf625
core/types: update requests hash
fjl Sep 30, 2024
c87fd76
core/types: update deposit request encoding
fjl Sep 30, 2024
e408488
all: update deposit requests format
fjl Sep 30, 2024
6690bdd
all: WIP remove requests from block body
fjl Sep 30, 2024
eb5aaa2
core/types: fix tests issue
fjl Sep 30, 2024
ff99699
internal/ethapi: remove requests
fjl Sep 30, 2024
0be1fe8
eth/downloader: remove requests
fjl Sep 30, 2024
11e82ef
core/types: update empty hash
fjl Sep 30, 2024
f9cc214
eth/catalyst: change newPayload parameter to requestsHash
fjl Oct 1, 2024
ded9d6b
beacon/engine: remove requestsHash in payload
fjl Oct 1, 2024
168d3eb
beacon/engine,eth/catalyst: ensure RequestsHash is passed to newPaylo…
lightclient Oct 2, 2024
9181bd3
core: remove deposits test
fjl Oct 7, 2024
9df0a64
core/types: remove empty requests hash
fjl Oct 7, 2024
d250deb
core/types: update requests hash function
fjl Oct 7, 2024
0310778
core: remove requests var
fjl Oct 7, 2024
cb08ea9
eth/catalyst: remove requests in GetPayloadBodies
fjl Oct 8, 2024
f27902e
core: add check for requests before prague
fjl Oct 8, 2024
b87d536
core/types: simplify CalcRequestsHash
fjl Oct 9, 2024
2509bde
core: fix deposit requests in GenerateChain
fjl Oct 9, 2024
92dc664
eth/catalyst: change back to passing requests
fjl Oct 9, 2024
b67f40b
beacon/engine: remove RequestsHash in EPE
fjl Oct 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
core/types: update requests hash function
  • Loading branch information
fjl committed Oct 7, 2024
commit d250deb70a7aea1f7805206a6f289021a38e1692
20 changes: 17 additions & 3 deletions core/types/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -457,12 +457,26 @@ func CalcUncleHash(uncles []*Header) common.Hash {
return rlpHash(uncles)
}

// CalcRequestsHash creates the block requestsHash value for a list of requests.
func CalcRequestsHash(requests [][]byte) common.Hash {
Copy link
Contributor

@islishude islishude Oct 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can be rewrote to following to eliminate memory allocation

func CalcRequestsHash(requests [][]byte) common.Hash {
	h1, h2 := sha256.New(), sha256.New()
	var buf common.Hash
	for _, item := range requests {
		h1.Reset()
		h1.Write(item)
		h2.Write(h1.Sum(buf[:0]))
	}
	h2.Sum(buf[:0])
	return buf
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a very clever suggestion!

// compute intermediate hashes
hashes := make([][32]byte, len(requests))
h := sha256.New()
for _, item := range requests {
for i, item := range requests {
h.Reset()
h.Write(item)
}
return common.Hash(h.Sum(nil))
var sum [32]byte
h.Sum(sum[:0])
hashes[i] = sum
}
// final hash
h.Reset()
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
Expand Down