Skip to content

Commit cc3e859

Browse files
committed
all: implement eip-7002 EL triggered withdrawal requests
1 parent c3f13b2 commit cc3e859

File tree

12 files changed

+463
-128
lines changed

12 files changed

+463
-128
lines changed

beacon/engine/gen_ed.go

Lines changed: 44 additions & 38 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

beacon/engine/types.go

Lines changed: 43 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -60,25 +60,26 @@ type payloadAttributesMarshaling struct {
6060

6161
// ExecutableData is the data necessary to execute an EL payload.
6262
type ExecutableData struct {
63-
ParentHash common.Hash `json:"parentHash" gencodec:"required"`
64-
FeeRecipient common.Address `json:"feeRecipient" gencodec:"required"`
65-
StateRoot common.Hash `json:"stateRoot" gencodec:"required"`
66-
ReceiptsRoot common.Hash `json:"receiptsRoot" gencodec:"required"`
67-
LogsBloom []byte `json:"logsBloom" gencodec:"required"`
68-
Random common.Hash `json:"prevRandao" gencodec:"required"`
69-
Number uint64 `json:"blockNumber" gencodec:"required"`
70-
GasLimit uint64 `json:"gasLimit" gencodec:"required"`
71-
GasUsed uint64 `json:"gasUsed" gencodec:"required"`
72-
Timestamp uint64 `json:"timestamp" gencodec:"required"`
73-
ExtraData []byte `json:"extraData" gencodec:"required"`
74-
BaseFeePerGas *big.Int `json:"baseFeePerGas" gencodec:"required"`
75-
BlockHash common.Hash `json:"blockHash" gencodec:"required"`
76-
Transactions [][]byte `json:"transactions" gencodec:"required"`
77-
Withdrawals []*types.Withdrawal `json:"withdrawals"`
78-
BlobGasUsed *uint64 `json:"blobGasUsed"`
79-
ExcessBlobGas *uint64 `json:"excessBlobGas"`
80-
Deposits types.Deposits `json:"depositRequests"`
81-
ExecutionWitness *types.ExecutionWitness `json:"executionWitness,omitempty"`
63+
ParentHash common.Hash `json:"parentHash" gencodec:"required"`
64+
FeeRecipient common.Address `json:"feeRecipient" gencodec:"required"`
65+
StateRoot common.Hash `json:"stateRoot" gencodec:"required"`
66+
ReceiptsRoot common.Hash `json:"receiptsRoot" gencodec:"required"`
67+
LogsBloom []byte `json:"logsBloom" gencodec:"required"`
68+
Random common.Hash `json:"prevRandao" gencodec:"required"`
69+
Number uint64 `json:"blockNumber" gencodec:"required"`
70+
GasLimit uint64 `json:"gasLimit" gencodec:"required"`
71+
GasUsed uint64 `json:"gasUsed" gencodec:"required"`
72+
Timestamp uint64 `json:"timestamp" gencodec:"required"`
73+
ExtraData []byte `json:"extraData" gencodec:"required"`
74+
BaseFeePerGas *big.Int `json:"baseFeePerGas" gencodec:"required"`
75+
BlockHash common.Hash `json:"blockHash" gencodec:"required"`
76+
Transactions [][]byte `json:"transactions" gencodec:"required"`
77+
Withdrawals []*types.Withdrawal `json:"withdrawals"`
78+
BlobGasUsed *uint64 `json:"blobGasUsed"`
79+
ExcessBlobGas *uint64 `json:"excessBlobGas"`
80+
Deposits types.Deposits `json:"depositRequests"`
81+
WithdrawalRequests types.WithdrawalRequests `json:"withdrawalRequests"`
82+
ExecutionWitness *types.ExecutionWitness `json:"executionWitness,omitempty"`
8283
}
8384

8485
// JSON type overrides for executableData.
@@ -233,7 +234,9 @@ func ExecutableDataToBlock(data ExecutableData, versionedHashes []common.Hash, b
233234
h := types.DeriveSha(types.Withdrawals(data.Withdrawals), trie.NewStackTrie(nil))
234235
withdrawalsRoot = &h
235236
}
236-
// Compute requestsHash if any requests are non-nil.
237+
// Only set requestsHash if there exists requests in the ExecutableData. This
238+
// allows CLs to continue using the data structure before requests are
239+
// enabled.
237240
var (
238241
requestsHash *common.Hash
239242
requests types.Requests
@@ -243,9 +246,17 @@ func ExecutableDataToBlock(data ExecutableData, versionedHashes []common.Hash, b
243246
for _, d := range data.Deposits {
244247
requests = append(requests, types.NewRequest(d))
245248
}
249+
}
250+
if data.WithdrawalRequests != nil {
251+
for _, w := range data.WithdrawalRequests {
252+
requests = append(requests, types.NewRequest(w))
253+
}
254+
}
255+
if requests != nil {
246256
h := types.DeriveSha(requests, trie.NewStackTrie(nil))
247257
requestsHash = &h
248258
}
259+
249260
header := &types.Header{
250261
ParentHash: data.ParentHash,
251262
UncleHash: types.EmptyUncleHash,
@@ -320,22 +331,27 @@ func BlockToExecutableData(block *types.Block, fees *big.Int, sidecars []*types.
320331
// assigns them to the associated fields in ExecutableData.
321332
func setRequests(requests types.Requests, data *ExecutableData) {
322333
if requests != nil {
323-
// If requests is non-nil, it means deposits are available in block and we
324-
// should return an empty slice instead of nil if there are no deposits.
334+
// If requests is non-nil, it means the requests are available in block and
335+
// we should return an empty slice instead of nil.
325336
data.Deposits = make(types.Deposits, 0)
337+
data.WithdrawalRequests = make(types.WithdrawalRequests, 0)
326338
}
327339
for _, r := range requests {
328-
if d, ok := r.Inner().(*types.Deposit); ok {
329-
data.Deposits = append(data.Deposits, d)
340+
switch v := r.Inner().(type) {
341+
case *types.Deposit:
342+
data.Deposits = append(data.Deposits, v)
343+
case *types.WithdrawalRequest:
344+
data.WithdrawalRequests = append(data.WithdrawalRequests, v)
330345
}
331346
}
332347
}
333348

334349
// ExecutionPayloadBody is used in the response to GetPayloadBodiesByHash and GetPayloadBodiesByRange
335350
type ExecutionPayloadBody struct {
336-
TransactionData []hexutil.Bytes `json:"transactions"`
337-
Withdrawals []*types.Withdrawal `json:"withdrawals"`
338-
Deposits types.Deposits `json:"depositRequests"`
351+
TransactionData []hexutil.Bytes `json:"transactions"`
352+
Withdrawals []*types.Withdrawal `json:"withdrawals"`
353+
Deposits types.Deposits `json:"depositRequests"`
354+
WithdrawalRequests types.WithdrawalRequests `json:"withdrawalRequests"`
339355
}
340356

341357
// Client identifiers to support ClientVersionV1.

0 commit comments

Comments
 (0)