Skip to content

Commit 30f9453

Browse files
committed
Update Empty requests list behaviour for Pectra-5 (#12985)
The updated EIP-7685 says requests with empty `request_data` should be dropped from `executionRequests` field in the API and ignored for hash calculation. See ethereum/EIPs#8989, ethereum/execution-apis#599 Issue board: #12401
1 parent 8288f26 commit 30f9453

File tree

11 files changed

+76
-61
lines changed

11 files changed

+76
-61
lines changed

consensus/merge/merge.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ func (s *Merge) Finalize(config *chain.Config, header *types.Header, state *stat
162162

163163
var rs types.FlatRequests
164164
if config.IsPrague(header.Time) {
165-
rs = make(types.FlatRequests, len(types.KnownRequestTypes))
165+
rs = make(types.FlatRequests, 0)
166166
allLogs := make(types.Logs, 0)
167167
for _, rec := range receipts {
168168
allLogs = append(allLogs, rec.Logs...)
@@ -171,11 +171,17 @@ func (s *Merge) Finalize(config *chain.Config, header *types.Header, state *stat
171171
if err != nil {
172172
return nil, nil, nil, fmt.Errorf("error: could not parse requests logs: %v", err)
173173
}
174-
rs[0] = *depositReqs
174+
if depositReqs != nil {
175+
rs = append(rs, *depositReqs)
176+
}
175177
withdrawalReq := misc.DequeueWithdrawalRequests7002(syscall)
176-
rs[1] = *withdrawalReq
178+
if withdrawalReq != nil {
179+
rs = append(rs, *withdrawalReq)
180+
}
177181
consolidations := misc.DequeueConsolidationRequests7251(syscall)
178-
rs[2] = *consolidations
182+
if consolidations != nil {
183+
rs = append(rs, *consolidations)
184+
}
179185
if header.RequestsHash != nil {
180186
rh := rs.Hash()
181187
if *header.RequestsHash != *rh {
@@ -194,15 +200,15 @@ func (s *Merge) FinalizeAndAssemble(config *chain.Config, header *types.Header,
194200
return s.eth1Engine.FinalizeAndAssemble(config, header, state, txs, uncles, receipts, withdrawals, chain, syscall, call, logger)
195201
}
196202
header.RequestsHash = nil
197-
outTxs, outReceipts, rs, err := s.Finalize(config, header, state, txs, uncles, receipts, withdrawals, chain, syscall, logger)
203+
outTxs, outReceipts, outRequests, err := s.Finalize(config, header, state, txs, uncles, receipts, withdrawals, chain, syscall, logger)
198204

199205
if err != nil {
200206
return nil, nil, nil, nil, err
201207
}
202208
if config.IsPrague(header.Time) {
203-
header.RequestsHash = rs.Hash()
209+
header.RequestsHash = outRequests.Hash()
204210
}
205-
return types.NewBlockForAsembling(header, outTxs, uncles, outReceipts, withdrawals), outTxs, outReceipts, rs, nil
211+
return types.NewBlockForAsembling(header, outTxs, uncles, outReceipts, withdrawals), outTxs, outReceipts, outRequests, nil
206212
}
207213

208214
func (s *Merge) SealHash(header *types.Header) (hash libcommon.Hash) {

consensus/misc/eip6110.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,5 +85,8 @@ func ParseDepositLogs(logs []*types.Log, depositContractAddress libcommon.Addres
8585
reqData = append(reqData, d...)
8686
}
8787
}
88-
return &types.FlatRequest{Type: types.DepositRequestType, RequestData: reqData}, nil
88+
if len(reqData) > 0 {
89+
return &types.FlatRequest{Type: types.DepositRequestType, RequestData: reqData}, nil
90+
}
91+
return nil, nil
8992
}

consensus/misc/eip7002.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ func DequeueWithdrawalRequests7002(syscall consensus.SystemCall) *types.FlatRequ
1414
log.Warn("Err with syscall to WithdrawalRequestAddress", "err", err)
1515
return nil
1616
}
17-
if res == nil {
18-
res = make([]byte, 0)
17+
if res != nil {
18+
// Just append the contract output
19+
return &types.FlatRequest{Type: types.WithdrawalRequestType, RequestData: res}
1920
}
20-
// Just append the contract outputs
21-
return &types.FlatRequest{Type: types.WithdrawalRequestType, RequestData: res}
21+
return nil
2222
}

consensus/misc/eip7251.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ func DequeueConsolidationRequests7251(syscall consensus.SystemCall) *types.FlatR
1414
log.Warn("Err with syscall to ConsolidationRequestAddress", "err", err)
1515
return nil
1616
}
17-
if res == nil {
18-
res = make([]byte, 0)
17+
if res != nil {
18+
// Just append the contract output as the request data
19+
return &types.FlatRequest{Type: types.ConsolidationRequestType, RequestData: res}
1920
}
20-
// Just append the contract outputs as the encoded request data
21-
return &types.FlatRequest{Type: types.ConsolidationRequestType, RequestData: res}
21+
return nil
2222
}

core/blockchain.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,6 @@ func FinalizeBlockExecution(
327327
if isMining {
328328
newBlock, newTxs, newReceipt, retRequests, err = engine.FinalizeAndAssemble(cc, header, ibs, txs, uncles, receipts, withdrawals, chainReader, syscall, nil, logger)
329329
} else {
330-
// var rss types.Requests
331330
newTxs, newReceipt, retRequests, err = engine.Finalize(cc, header, ibs, txs, uncles, receipts, withdrawals, chainReader, syscall, logger)
332331
}
333332
if err != nil {

core/types/block.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import (
3939

4040
var (
4141
EmptyRootHash = libcommon.HexToHash("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421")
42-
EmptyRequestsHash = libcommon.HexToHash("6036c41849da9c076ed79654d434017387a88fb833c2856b32e18218b3341c5f")
42+
EmptyRequestsHash = libcommon.HexToHash("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855") // sha256.Sum256([]byte(""))
4343
EmptyUncleHash = rlpHash([]*Header(nil))
4444

4545
ExtraVanityLength = 32 // Fixed number of extra-data prefix bytes reserved for signer vanity

core/types/eip7685_requests.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@ func (f *FlatRequest) copy() *FlatRequest {
5252
type FlatRequests []FlatRequest
5353

5454
func (r FlatRequests) Hash() *libcommon.Hash {
55-
if r == nil || len(r) < len(KnownRequestTypes) {
55+
if r == nil {
5656
return nil
5757
}
5858
sha := sha256.New()
59-
for i, t := range KnownRequestTypes {
60-
hi := sha256.Sum256(append([]byte{t}, r[i].RequestData...))
59+
for i, t := range r {
60+
hi := sha256.Sum256(append([]byte{t.Type}, r[i].RequestData...))
6161
sha.Write(hi[:])
6262
}
6363
h := libcommon.BytesToHash(sha.Sum(nil))

core/types/requests_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright 2025 The Erigon Authors
2+
// This file is part of Erigon.
3+
//
4+
// Erigon is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU Lesser General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// Erigon is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU Lesser General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU Lesser General Public License
15+
// along with Erigon. If not, see <http://www.gnu.org/licenses/>.
16+
17+
package types
18+
19+
import (
20+
"testing"
21+
)
22+
23+
func TestEmptyRequestsHashCalculation(t *testing.T) {
24+
reqs := make(FlatRequests, 0)
25+
h := reqs.Hash()
26+
testH := EmptyRequestsHash
27+
if *h != testH {
28+
t.Errorf("Requests Hash calculation error for empty hash, expected: %v, got: %v", testH, h)
29+
}
30+
}

turbo/builder/block_builder.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package builder
22

33
import (
4-
"fmt"
54
"sync"
65
"sync/atomic"
76
"time"
@@ -34,11 +33,7 @@ func NewBlockBuilder(build BlockBuilderFunc, param *core.BlockBuilderParameters)
3433
log.Warn("Failed to build a block", "err", err)
3534
} else {
3635
block := result.Block
37-
reqLenStr := "nil"
38-
if len(result.Requests) == 3 {
39-
reqLenStr = fmt.Sprint("Deposit Requests", len(result.Requests[0].RequestData), "Withdrawal Requests", len(result.Requests[1].RequestData), "Consolidation Requests", len(result.Requests[2].RequestData))
40-
}
41-
log.Info("Built block", "hash", block.Hash(), "height", block.NumberU64(), "txs", len(block.Transactions()), "executionRequests", len(result.Requests), "Requests", reqLenStr, "gas used %", 100*float64(block.GasUsed())/float64(block.GasLimit()), "time", time.Since(t))
36+
log.Info("Built block", "hash", block.Hash(), "height", block.NumberU64(), "txs", len(block.Transactions()), "executionRequests", len(result.Requests), "gas used %", 100*float64(block.GasUsed())/float64(block.GasLimit()), "time", time.Since(t))
4237
}
4338

4439
builder.syncCond.L.Lock()

turbo/engineapi/engine_server.go

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,6 @@ func (s *EngineServer) checkRequestsPresence(time uint64, executionRequests []he
126126
return &rpc.InvalidParamsError{Message: "requests before Prague"}
127127
}
128128
}
129-
// if s.config.IsPrague(time) {
130-
// if len(executionRequests) < 3 {
131-
// return &rpc.InvalidParamsError{Message: "missing requests list"}
132-
// }
133-
// }
134129
return nil
135130
}
136131

@@ -182,12 +177,12 @@ func (s *EngineServer) newPayload(ctx context.Context, req *engine_types.Executi
182177
return nil, err
183178
}
184179
if version >= clparams.ElectraVersion {
185-
requests = make(types.FlatRequests, len(types.KnownRequestTypes))
186-
for i, r := range types.KnownRequestTypes {
187-
if len(executionRequests) == i {
188-
executionRequests = append(executionRequests, []byte{})
180+
requests = make(types.FlatRequests, 0)
181+
for i, r := range executionRequests {
182+
if len(r) <= 1 {
183+
return nil, &rpc.InvalidParamsError{Message: fmt.Sprintf("Invalid Request at index %d", i)}
189184
}
190-
requests[i] = types.FlatRequest{Type: r, RequestData: executionRequests[i]}
185+
requests = append(requests, types.FlatRequest{Type: r[0], RequestData: r})
191186
}
192187
rh := requests.Hash()
193188
header.RequestsHash = rh
@@ -460,16 +455,9 @@ func (s *EngineServer) getPayload(ctx context.Context, payloadId uint64, version
460455
data := resp.Data
461456
var executionRequests []hexutility.Bytes
462457
if version >= clparams.ElectraVersion {
463-
executionRequests = make([]hexutility.Bytes, len(types.KnownRequestTypes))
464-
if len(data.Requests.Requests) != 3 {
465-
s.logger.Warn("Error in getPayload - data.Requests.Requests len not 3")
466-
}
467-
for i := 0; i < len(types.KnownRequestTypes); i++ {
468-
if len(data.Requests.Requests) < i+1 || data.Requests.Requests[i] == nil {
469-
executionRequests[i] = make(hexutility.Bytes, 0)
470-
} else {
471-
executionRequests[i] = data.Requests.Requests[i]
472-
}
458+
executionRequests = make([]hexutility.Bytes, 0)
459+
for _, r := range data.Requests.Requests {
460+
executionRequests = append(executionRequests, r)
473461
}
474462
}
475463

0 commit comments

Comments
 (0)