diff --git a/beacon/engine/errors.go b/beacon/engine/errors.go
deleted file mode 100644
index 62773a0ea9..0000000000
--- a/beacon/engine/errors.go
+++ /dev/null
@@ -1,88 +0,0 @@
-// Copyright 2022 The go-ethereum Authors
-// This file is part of the go-ethereum library.
-//
-// The go-ethereum library is free software: you can redistribute it and/or modify
-// it under the terms of the GNU Lesser General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// The go-ethereum library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public License
-// along with the go-ethereum library. If not, see .
-
-package engine
-
-import (
- "github.com/ethereum/go-ethereum/common"
- "github.com/ethereum/go-ethereum/rpc"
-)
-
-// EngineAPIError is a standardized error message between consensus and execution
-// clients, also containing any custom error message Geth might include.
-type EngineAPIError struct {
- code int
- msg string
- err error
-}
-
-func (e *EngineAPIError) ErrorCode() int { return e.code }
-func (e *EngineAPIError) Error() string { return e.msg }
-func (e *EngineAPIError) ErrorData() interface{} {
- if e.err == nil {
- return nil
- }
- return struct {
- Error string `json:"err"`
- }{e.err.Error()}
-}
-
-// With returns a copy of the error with a new embedded custom data field.
-func (e *EngineAPIError) With(err error) *EngineAPIError {
- return &EngineAPIError{
- code: e.code,
- msg: e.msg,
- err: err,
- }
-}
-
-var (
- _ rpc.Error = new(EngineAPIError)
- _ rpc.DataError = new(EngineAPIError)
-)
-
-var (
- // VALID is returned by the engine API in the following calls:
- // - newPayloadV1: if the payload was already known or was just validated and executed
- // - forkchoiceUpdateV1: if the chain accepted the reorg (might ignore if it's stale)
- VALID = "VALID"
-
- // INVALID is returned by the engine API in the following calls:
- // - newPayloadV1: if the payload failed to execute on top of the local chain
- // - forkchoiceUpdateV1: if the new head is unknown, pre-merge, or reorg to it fails
- INVALID = "INVALID"
-
- // SYNCING is returned by the engine API in the following calls:
- // - newPayloadV1: if the payload was accepted on top of an active sync
- // - forkchoiceUpdateV1: if the new head was seen before, but not part of the chain
- SYNCING = "SYNCING"
-
- // ACCEPTED is returned by the engine API in the following calls:
- // - newPayloadV1: if the payload was accepted, but not processed (side chain)
- ACCEPTED = "ACCEPTED"
-
- GenericServerError = &EngineAPIError{code: -32000, msg: "Server error"}
- UnknownPayload = &EngineAPIError{code: -38001, msg: "Unknown payload"}
- InvalidForkChoiceState = &EngineAPIError{code: -38002, msg: "Invalid forkchoice state"}
- InvalidPayloadAttributes = &EngineAPIError{code: -38003, msg: "Invalid payload attributes"}
- TooLargeRequest = &EngineAPIError{code: -38004, msg: "Too large request"}
- InvalidParams = &EngineAPIError{code: -32602, msg: "Invalid parameters"}
- UnsupportedFork = &EngineAPIError{code: -38005, msg: "Unsupported fork"}
-
- STATUS_INVALID = ForkChoiceResponse{PayloadStatus: PayloadStatusV1{Status: INVALID}, PayloadID: nil}
- STATUS_SYNCING = ForkChoiceResponse{PayloadStatus: PayloadStatusV1{Status: SYNCING}, PayloadID: nil}
- INVALID_TERMINAL_BLOCK = PayloadStatusV1{Status: INVALID, LatestValidHash: &common.Hash{}}
-)
diff --git a/beacon/engine/gen_blockparams.go b/beacon/engine/gen_blockparams.go
deleted file mode 100644
index b1f01b50ff..0000000000
--- a/beacon/engine/gen_blockparams.go
+++ /dev/null
@@ -1,66 +0,0 @@
-// Code generated by github.com/fjl/gencodec. DO NOT EDIT.
-
-package engine
-
-import (
- "encoding/json"
- "errors"
-
- "github.com/ethereum/go-ethereum/common"
- "github.com/ethereum/go-ethereum/common/hexutil"
- "github.com/ethereum/go-ethereum/core/types"
-)
-
-var _ = (*payloadAttributesMarshaling)(nil)
-
-// MarshalJSON marshals as JSON.
-func (p PayloadAttributes) MarshalJSON() ([]byte, error) {
- type PayloadAttributes struct {
- Timestamp hexutil.Uint64 `json:"timestamp" gencodec:"required"`
- Random common.Hash `json:"prevRandao" gencodec:"required"`
- SuggestedFeeRecipient common.Address `json:"suggestedFeeRecipient" gencodec:"required"`
- Withdrawals []*types.Withdrawal `json:"withdrawals"`
- BeaconRoot *common.Hash `json:"parentBeaconBlockRoot"`
- }
- var enc PayloadAttributes
- enc.Timestamp = hexutil.Uint64(p.Timestamp)
- enc.Random = p.Random
- enc.SuggestedFeeRecipient = p.SuggestedFeeRecipient
- enc.Withdrawals = p.Withdrawals
- enc.BeaconRoot = p.BeaconRoot
- return json.Marshal(&enc)
-}
-
-// UnmarshalJSON unmarshals from JSON.
-func (p *PayloadAttributes) UnmarshalJSON(input []byte) error {
- type PayloadAttributes struct {
- Timestamp *hexutil.Uint64 `json:"timestamp" gencodec:"required"`
- Random *common.Hash `json:"prevRandao" gencodec:"required"`
- SuggestedFeeRecipient *common.Address `json:"suggestedFeeRecipient" gencodec:"required"`
- Withdrawals []*types.Withdrawal `json:"withdrawals"`
- BeaconRoot *common.Hash `json:"parentBeaconBlockRoot"`
- }
- var dec PayloadAttributes
- if err := json.Unmarshal(input, &dec); err != nil {
- return err
- }
- if dec.Timestamp == nil {
- return errors.New("missing required field 'timestamp' for PayloadAttributes")
- }
- p.Timestamp = uint64(*dec.Timestamp)
- if dec.Random == nil {
- return errors.New("missing required field 'prevRandao' for PayloadAttributes")
- }
- p.Random = *dec.Random
- if dec.SuggestedFeeRecipient == nil {
- return errors.New("missing required field 'suggestedFeeRecipient' for PayloadAttributes")
- }
- p.SuggestedFeeRecipient = *dec.SuggestedFeeRecipient
- if dec.Withdrawals != nil {
- p.Withdrawals = dec.Withdrawals
- }
- if dec.BeaconRoot != nil {
- p.BeaconRoot = dec.BeaconRoot
- }
- return nil
-}
diff --git a/beacon/engine/gen_ed.go b/beacon/engine/gen_ed.go
deleted file mode 100644
index 6893d64a16..0000000000
--- a/beacon/engine/gen_ed.go
+++ /dev/null
@@ -1,158 +0,0 @@
-// Code generated by github.com/fjl/gencodec. DO NOT EDIT.
-
-package engine
-
-import (
- "encoding/json"
- "errors"
- "math/big"
-
- "github.com/ethereum/go-ethereum/common"
- "github.com/ethereum/go-ethereum/common/hexutil"
- "github.com/ethereum/go-ethereum/core/types"
-)
-
-var _ = (*executableDataMarshaling)(nil)
-
-// MarshalJSON marshals as JSON.
-func (e ExecutableData) MarshalJSON() ([]byte, error) {
- type ExecutableData struct {
- ParentHash common.Hash `json:"parentHash" gencodec:"required"`
- FeeRecipient common.Address `json:"feeRecipient" gencodec:"required"`
- StateRoot common.Hash `json:"stateRoot" gencodec:"required"`
- ReceiptsRoot common.Hash `json:"receiptsRoot" gencodec:"required"`
- LogsBloom hexutil.Bytes `json:"logsBloom" gencodec:"required"`
- Random common.Hash `json:"prevRandao" gencodec:"required"`
- Number hexutil.Uint64 `json:"blockNumber" gencodec:"required"`
- GasLimit hexutil.Uint64 `json:"gasLimit" gencodec:"required"`
- GasUsed hexutil.Uint64 `json:"gasUsed" gencodec:"required"`
- Timestamp hexutil.Uint64 `json:"timestamp" gencodec:"required"`
- ExtraData hexutil.Bytes `json:"extraData" gencodec:"required"`
- BaseFeePerGas *hexutil.Big `json:"baseFeePerGas" gencodec:"required"`
- BlockHash common.Hash `json:"blockHash" gencodec:"required"`
- Transactions []hexutil.Bytes `json:"transactions" gencodec:"required"`
- Withdrawals []*types.Withdrawal `json:"withdrawals"`
- BlobGasUsed *hexutil.Uint64 `json:"blobGasUsed"`
- ExcessBlobGas *hexutil.Uint64 `json:"excessBlobGas"`
- }
- var enc ExecutableData
- enc.ParentHash = e.ParentHash
- enc.FeeRecipient = e.FeeRecipient
- enc.StateRoot = e.StateRoot
- enc.ReceiptsRoot = e.ReceiptsRoot
- enc.LogsBloom = e.LogsBloom
- enc.Random = e.Random
- enc.Number = hexutil.Uint64(e.Number)
- enc.GasLimit = hexutil.Uint64(e.GasLimit)
- enc.GasUsed = hexutil.Uint64(e.GasUsed)
- enc.Timestamp = hexutil.Uint64(e.Timestamp)
- enc.ExtraData = e.ExtraData
- enc.BaseFeePerGas = (*hexutil.Big)(e.BaseFeePerGas)
- enc.BlockHash = e.BlockHash
- if e.Transactions != nil {
- enc.Transactions = make([]hexutil.Bytes, len(e.Transactions))
- for k, v := range e.Transactions {
- enc.Transactions[k] = v
- }
- }
- enc.Withdrawals = e.Withdrawals
- enc.BlobGasUsed = (*hexutil.Uint64)(e.BlobGasUsed)
- enc.ExcessBlobGas = (*hexutil.Uint64)(e.ExcessBlobGas)
- return json.Marshal(&enc)
-}
-
-// UnmarshalJSON unmarshals from JSON.
-func (e *ExecutableData) UnmarshalJSON(input []byte) error {
- type ExecutableData struct {
- ParentHash *common.Hash `json:"parentHash" gencodec:"required"`
- FeeRecipient *common.Address `json:"feeRecipient" gencodec:"required"`
- StateRoot *common.Hash `json:"stateRoot" gencodec:"required"`
- ReceiptsRoot *common.Hash `json:"receiptsRoot" gencodec:"required"`
- LogsBloom *hexutil.Bytes `json:"logsBloom" gencodec:"required"`
- Random *common.Hash `json:"prevRandao" gencodec:"required"`
- Number *hexutil.Uint64 `json:"blockNumber" gencodec:"required"`
- GasLimit *hexutil.Uint64 `json:"gasLimit" gencodec:"required"`
- GasUsed *hexutil.Uint64 `json:"gasUsed" gencodec:"required"`
- Timestamp *hexutil.Uint64 `json:"timestamp" gencodec:"required"`
- ExtraData *hexutil.Bytes `json:"extraData" gencodec:"required"`
- BaseFeePerGas *hexutil.Big `json:"baseFeePerGas" gencodec:"required"`
- BlockHash *common.Hash `json:"blockHash" gencodec:"required"`
- Transactions []hexutil.Bytes `json:"transactions" gencodec:"required"`
- Withdrawals []*types.Withdrawal `json:"withdrawals"`
- BlobGasUsed *hexutil.Uint64 `json:"blobGasUsed"`
- ExcessBlobGas *hexutil.Uint64 `json:"excessBlobGas"`
- }
- var dec ExecutableData
- if err := json.Unmarshal(input, &dec); err != nil {
- return err
- }
- if dec.ParentHash == nil {
- return errors.New("missing required field 'parentHash' for ExecutableData")
- }
- e.ParentHash = *dec.ParentHash
- if dec.FeeRecipient == nil {
- return errors.New("missing required field 'feeRecipient' for ExecutableData")
- }
- e.FeeRecipient = *dec.FeeRecipient
- if dec.StateRoot == nil {
- return errors.New("missing required field 'stateRoot' for ExecutableData")
- }
- e.StateRoot = *dec.StateRoot
- if dec.ReceiptsRoot == nil {
- return errors.New("missing required field 'receiptsRoot' for ExecutableData")
- }
- e.ReceiptsRoot = *dec.ReceiptsRoot
- if dec.LogsBloom == nil {
- return errors.New("missing required field 'logsBloom' for ExecutableData")
- }
- e.LogsBloom = *dec.LogsBloom
- if dec.Random == nil {
- return errors.New("missing required field 'prevRandao' for ExecutableData")
- }
- e.Random = *dec.Random
- if dec.Number == nil {
- return errors.New("missing required field 'blockNumber' for ExecutableData")
- }
- e.Number = uint64(*dec.Number)
- if dec.GasLimit == nil {
- return errors.New("missing required field 'gasLimit' for ExecutableData")
- }
- e.GasLimit = uint64(*dec.GasLimit)
- if dec.GasUsed == nil {
- return errors.New("missing required field 'gasUsed' for ExecutableData")
- }
- e.GasUsed = uint64(*dec.GasUsed)
- if dec.Timestamp == nil {
- return errors.New("missing required field 'timestamp' for ExecutableData")
- }
- e.Timestamp = uint64(*dec.Timestamp)
- if dec.ExtraData == nil {
- return errors.New("missing required field 'extraData' for ExecutableData")
- }
- e.ExtraData = *dec.ExtraData
- if dec.BaseFeePerGas == nil {
- return errors.New("missing required field 'baseFeePerGas' for ExecutableData")
- }
- e.BaseFeePerGas = (*big.Int)(dec.BaseFeePerGas)
- if dec.BlockHash == nil {
- return errors.New("missing required field 'blockHash' for ExecutableData")
- }
- e.BlockHash = *dec.BlockHash
- if dec.Transactions == nil {
- return errors.New("missing required field 'transactions' for ExecutableData")
- }
- e.Transactions = make([][]byte, len(dec.Transactions))
- for k, v := range dec.Transactions {
- e.Transactions[k] = v
- }
- if dec.Withdrawals != nil {
- e.Withdrawals = dec.Withdrawals
- }
- if dec.BlobGasUsed != nil {
- e.BlobGasUsed = (*uint64)(dec.BlobGasUsed)
- }
- if dec.ExcessBlobGas != nil {
- e.ExcessBlobGas = (*uint64)(dec.ExcessBlobGas)
- }
- return nil
-}
diff --git a/beacon/engine/gen_epe.go b/beacon/engine/gen_epe.go
deleted file mode 100644
index e69f9a5951..0000000000
--- a/beacon/engine/gen_epe.go
+++ /dev/null
@@ -1,58 +0,0 @@
-// Code generated by github.com/fjl/gencodec. DO NOT EDIT.
-
-package engine
-
-import (
- "encoding/json"
- "errors"
- "math/big"
-
- "github.com/ethereum/go-ethereum/common/hexutil"
-)
-
-var _ = (*executionPayloadEnvelopeMarshaling)(nil)
-
-// MarshalJSON marshals as JSON.
-func (e ExecutionPayloadEnvelope) MarshalJSON() ([]byte, error) {
- type ExecutionPayloadEnvelope struct {
- ExecutionPayload *ExecutableData `json:"executionPayload" gencodec:"required"`
- BlockValue *hexutil.Big `json:"blockValue" gencodec:"required"`
- BlobsBundle *BlobsBundleV1 `json:"blobsBundle"`
- Override bool `json:"shouldOverrideBuilder"`
- }
- var enc ExecutionPayloadEnvelope
- enc.ExecutionPayload = e.ExecutionPayload
- enc.BlockValue = (*hexutil.Big)(e.BlockValue)
- enc.BlobsBundle = e.BlobsBundle
- enc.Override = e.Override
- return json.Marshal(&enc)
-}
-
-// UnmarshalJSON unmarshals from JSON.
-func (e *ExecutionPayloadEnvelope) UnmarshalJSON(input []byte) error {
- type ExecutionPayloadEnvelope struct {
- ExecutionPayload *ExecutableData `json:"executionPayload" gencodec:"required"`
- BlockValue *hexutil.Big `json:"blockValue" gencodec:"required"`
- BlobsBundle *BlobsBundleV1 `json:"blobsBundle"`
- Override *bool `json:"shouldOverrideBuilder"`
- }
- var dec ExecutionPayloadEnvelope
- if err := json.Unmarshal(input, &dec); err != nil {
- return err
- }
- if dec.ExecutionPayload == nil {
- return errors.New("missing required field 'executionPayload' for ExecutionPayloadEnvelope")
- }
- e.ExecutionPayload = dec.ExecutionPayload
- if dec.BlockValue == nil {
- return errors.New("missing required field 'blockValue' for ExecutionPayloadEnvelope")
- }
- e.BlockValue = (*big.Int)(dec.BlockValue)
- if dec.BlobsBundle != nil {
- e.BlobsBundle = dec.BlobsBundle
- }
- if dec.Override != nil {
- e.Override = *dec.Override
- }
- return nil
-}
diff --git a/beacon/engine/types.go b/beacon/engine/types.go
deleted file mode 100644
index 67f30d4455..0000000000
--- a/beacon/engine/types.go
+++ /dev/null
@@ -1,280 +0,0 @@
-// Copyright 2022 The go-ethereum Authors
-// This file is part of the go-ethereum library.
-//
-// The go-ethereum library is free software: you can redistribute it and/or modify
-// it under the terms of the GNU Lesser General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// The go-ethereum library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public License
-// along with the go-ethereum library. If not, see .
-
-package engine
-
-import (
- "fmt"
- "math/big"
-
- "github.com/ethereum/go-ethereum/common"
- "github.com/ethereum/go-ethereum/common/hexutil"
- "github.com/ethereum/go-ethereum/core/types"
- "github.com/ethereum/go-ethereum/trie"
-)
-
-//go:generate go run github.com/fjl/gencodec -type PayloadAttributes -field-override payloadAttributesMarshaling -out gen_blockparams.go
-
-// PayloadAttributes describes the environment context in which a block should
-// be built.
-type PayloadAttributes struct {
- Timestamp uint64 `json:"timestamp" gencodec:"required"`
- Random common.Hash `json:"prevRandao" gencodec:"required"`
- SuggestedFeeRecipient common.Address `json:"suggestedFeeRecipient" gencodec:"required"`
- Withdrawals []*types.Withdrawal `json:"withdrawals"`
- BeaconRoot *common.Hash `json:"parentBeaconBlockRoot"`
-}
-
-// JSON type overrides for PayloadAttributes.
-type payloadAttributesMarshaling struct {
- Timestamp hexutil.Uint64
-}
-
-//go:generate go run github.com/fjl/gencodec -type ExecutableData -field-override executableDataMarshaling -out gen_ed.go
-
-// ExecutableData is the data necessary to execute an EL payload.
-type ExecutableData struct {
- ParentHash common.Hash `json:"parentHash" gencodec:"required"`
- FeeRecipient common.Address `json:"feeRecipient" gencodec:"required"`
- StateRoot common.Hash `json:"stateRoot" gencodec:"required"`
- ReceiptsRoot common.Hash `json:"receiptsRoot" gencodec:"required"`
- LogsBloom []byte `json:"logsBloom" gencodec:"required"`
- Random common.Hash `json:"prevRandao" gencodec:"required"`
- Number uint64 `json:"blockNumber" gencodec:"required"`
- GasLimit uint64 `json:"gasLimit" gencodec:"required"`
- GasUsed uint64 `json:"gasUsed" gencodec:"required"`
- Timestamp uint64 `json:"timestamp" gencodec:"required"`
- ExtraData []byte `json:"extraData" gencodec:"required"`
- BaseFeePerGas *big.Int `json:"baseFeePerGas" gencodec:"required"`
- BlockHash common.Hash `json:"blockHash" gencodec:"required"`
- Transactions [][]byte `json:"transactions" gencodec:"required"`
- Withdrawals []*types.Withdrawal `json:"withdrawals"`
- BlobGasUsed *uint64 `json:"blobGasUsed"`
- ExcessBlobGas *uint64 `json:"excessBlobGas"`
-}
-
-// JSON type overrides for executableData.
-type executableDataMarshaling struct {
- Number hexutil.Uint64
- GasLimit hexutil.Uint64
- GasUsed hexutil.Uint64
- Timestamp hexutil.Uint64
- BaseFeePerGas *hexutil.Big
- ExtraData hexutil.Bytes
- LogsBloom hexutil.Bytes
- Transactions []hexutil.Bytes
- BlobGasUsed *hexutil.Uint64
- ExcessBlobGas *hexutil.Uint64
-}
-
-//go:generate go run github.com/fjl/gencodec -type ExecutionPayloadEnvelope -field-override executionPayloadEnvelopeMarshaling -out gen_epe.go
-
-type ExecutionPayloadEnvelope struct {
- ExecutionPayload *ExecutableData `json:"executionPayload" gencodec:"required"`
- BlockValue *big.Int `json:"blockValue" gencodec:"required"`
- BlobsBundle *BlobsBundleV1 `json:"blobsBundle"`
- Override bool `json:"shouldOverrideBuilder"`
-}
-
-type BlobsBundleV1 struct {
- Commitments []hexutil.Bytes `json:"commitments"`
- Proofs []hexutil.Bytes `json:"proofs"`
- Blobs []hexutil.Bytes `json:"blobs"`
-}
-
-// JSON type overrides for ExecutionPayloadEnvelope.
-type executionPayloadEnvelopeMarshaling struct {
- BlockValue *hexutil.Big
-}
-
-type PayloadStatusV1 struct {
- Status string `json:"status"`
- LatestValidHash *common.Hash `json:"latestValidHash"`
- ValidationError *string `json:"validationError"`
-}
-
-type TransitionConfigurationV1 struct {
- TerminalTotalDifficulty *hexutil.Big `json:"terminalTotalDifficulty"`
- TerminalBlockHash common.Hash `json:"terminalBlockHash"`
- TerminalBlockNumber hexutil.Uint64 `json:"terminalBlockNumber"`
-}
-
-// PayloadID is an identifier of the payload build process
-type PayloadID [8]byte
-
-func (b PayloadID) String() string {
- return hexutil.Encode(b[:])
-}
-
-func (b PayloadID) MarshalText() ([]byte, error) {
- return hexutil.Bytes(b[:]).MarshalText()
-}
-
-func (b *PayloadID) UnmarshalText(input []byte) error {
- err := hexutil.UnmarshalFixedText("PayloadID", input, b[:])
- if err != nil {
- return fmt.Errorf("invalid payload id %q: %w", input, err)
- }
- return nil
-}
-
-type ForkChoiceResponse struct {
- PayloadStatus PayloadStatusV1 `json:"payloadStatus"`
- PayloadID *PayloadID `json:"payloadId"`
-}
-
-type ForkchoiceStateV1 struct {
- HeadBlockHash common.Hash `json:"headBlockHash"`
- SafeBlockHash common.Hash `json:"safeBlockHash"`
- FinalizedBlockHash common.Hash `json:"finalizedBlockHash"`
-}
-
-func encodeTransactions(txs []*types.Transaction) [][]byte {
- var enc = make([][]byte, len(txs))
- for i, tx := range txs {
- enc[i], _ = tx.MarshalBinary()
- }
- return enc
-}
-
-func decodeTransactions(enc [][]byte) ([]*types.Transaction, error) {
- var txs = make([]*types.Transaction, len(enc))
- for i, encTx := range enc {
- var tx types.Transaction
- if err := tx.UnmarshalBinary(encTx); err != nil {
- return nil, fmt.Errorf("invalid transaction %d: %v", i, err)
- }
- txs[i] = &tx
- }
- return txs, nil
-}
-
-// ExecutableDataToBlock constructs a block from executable data.
-// It verifies that the following fields:
-//
-// len(extraData) <= 32
-// uncleHash = emptyUncleHash
-// difficulty = 0
-// if versionedHashes != nil, versionedHashes match to blob transactions
-//
-// and that the blockhash of the constructed block matches the parameters. Nil
-// Withdrawals value will propagate through the returned block. Empty
-// Withdrawals value must be passed via non-nil, length 0 value in params.
-func ExecutableDataToBlock(params ExecutableData, versionedHashes []common.Hash, beaconRoot *common.Hash) (*types.Block, error) {
- txs, err := decodeTransactions(params.Transactions)
- if err != nil {
- return nil, err
- }
- if len(params.ExtraData) > 32 {
- return nil, fmt.Errorf("invalid extradata length: %v", len(params.ExtraData))
- }
- if len(params.LogsBloom) != 256 {
- return nil, fmt.Errorf("invalid logsBloom length: %v", len(params.LogsBloom))
- }
- // Check that baseFeePerGas is not negative or too big
- if params.BaseFeePerGas != nil && (params.BaseFeePerGas.Sign() == -1 || params.BaseFeePerGas.BitLen() > 256) {
- return nil, fmt.Errorf("invalid baseFeePerGas: %v", params.BaseFeePerGas)
- }
- var blobHashes []common.Hash
- for _, tx := range txs {
- blobHashes = append(blobHashes, tx.BlobHashes()...)
- }
- if len(blobHashes) != len(versionedHashes) {
- return nil, fmt.Errorf("invalid number of versionedHashes: %v blobHashes: %v", versionedHashes, blobHashes)
- }
- for i := 0; i < len(blobHashes); i++ {
- if blobHashes[i] != versionedHashes[i] {
- return nil, fmt.Errorf("invalid versionedHash at %v: %v blobHashes: %v", i, versionedHashes, blobHashes)
- }
- }
- // Only set withdrawalsRoot if it is non-nil. This allows CLs to use
- // ExecutableData before withdrawals are enabled by marshaling
- // Withdrawals as the json null value.
- var withdrawalsRoot *common.Hash
- if params.Withdrawals != nil {
- h := types.DeriveSha(types.Withdrawals(params.Withdrawals), trie.NewStackTrie(nil))
- withdrawalsRoot = &h
- }
- header := &types.Header{
- ParentHash: params.ParentHash,
- UncleHash: types.EmptyUncleHash,
- Coinbase: params.FeeRecipient,
- Root: params.StateRoot,
- TxHash: types.DeriveSha(types.Transactions(txs), trie.NewStackTrie(nil)),
- ReceiptHash: params.ReceiptsRoot,
- Bloom: types.BytesToBloom(params.LogsBloom),
- Difficulty: common.Big0,
- Number: new(big.Int).SetUint64(params.Number),
- GasLimit: params.GasLimit,
- GasUsed: params.GasUsed,
- Time: params.Timestamp,
- BaseFee: params.BaseFeePerGas,
- Extra: params.ExtraData,
- MixDigest: params.Random,
- WithdrawalsHash: withdrawalsRoot,
- ExcessBlobGas: params.ExcessBlobGas,
- BlobGasUsed: params.BlobGasUsed,
- ParentBeaconRoot: beaconRoot,
- }
- block := types.NewBlockWithHeader(header).WithBody(txs, nil /* uncles */).WithWithdrawals(params.Withdrawals)
- if block.Hash() != params.BlockHash {
- return nil, fmt.Errorf("blockhash mismatch, want %x, got %x", params.BlockHash, block.Hash())
- }
- return block, nil
-}
-
-// BlockToExecutableData constructs the ExecutableData structure by filling the
-// fields from the given block. It assumes the given block is post-merge block.
-func BlockToExecutableData(block *types.Block, fees *big.Int, sidecars []*types.BlobTxSidecar) *ExecutionPayloadEnvelope {
- data := &ExecutableData{
- BlockHash: block.Hash(),
- ParentHash: block.ParentHash(),
- FeeRecipient: block.Coinbase(),
- StateRoot: block.Root(),
- Number: block.NumberU64(),
- GasLimit: block.GasLimit(),
- GasUsed: block.GasUsed(),
- BaseFeePerGas: block.BaseFee(),
- Timestamp: block.Time(),
- ReceiptsRoot: block.ReceiptHash(),
- LogsBloom: block.Bloom().Bytes(),
- Transactions: encodeTransactions(block.Transactions()),
- Random: block.MixDigest(),
- ExtraData: block.Extra(),
- Withdrawals: block.Withdrawals(),
- BlobGasUsed: block.BlobGasUsed(),
- ExcessBlobGas: block.ExcessBlobGas(),
- }
- bundle := BlobsBundleV1{
- Commitments: make([]hexutil.Bytes, 0),
- Blobs: make([]hexutil.Bytes, 0),
- Proofs: make([]hexutil.Bytes, 0),
- }
- for _, sidecar := range sidecars {
- for j := range sidecar.Blobs {
- bundle.Blobs = append(bundle.Blobs, hexutil.Bytes(sidecar.Blobs[j][:]))
- bundle.Commitments = append(bundle.Commitments, hexutil.Bytes(sidecar.Commitments[j][:]))
- bundle.Proofs = append(bundle.Proofs, hexutil.Bytes(sidecar.Proofs[j][:]))
- }
- }
- return &ExecutionPayloadEnvelope{ExecutionPayload: data, BlockValue: fees, BlobsBundle: &bundle, Override: false}
-}
-
-// ExecutionPayloadBodyV1 is used in the response to GetPayloadBodiesByHashV1 and GetPayloadBodiesByRangeV1
-type ExecutionPayloadBodyV1 struct {
- TransactionData []hexutil.Bytes `json:"transactions"`
- Withdrawals []*types.Withdrawal `json:"withdrawals"`
-}