From 0d5a52d20d4209ba08fcef2cedacf25a090061d4 Mon Sep 17 00:00:00 2001 From: james-prysm <90280386+james-prysm@users.noreply.github.com> Date: Tue, 27 May 2025 15:34:24 -0500 Subject: [PATCH] merge builder and structs payload types (#15283) * wip * more wip * commenting out builder redefinition of payload types * removing unneeded commented out code and unused type conversions * fixing unit tests and removing irrelevant unit tests * gaz * adding changelog * Update api/server/structs/conversions_block_execution.go Co-authored-by: Preston Van Loon * Update api/server/structs/conversions_block_execution.go Co-authored-by: Preston Van Loon * Revert some changes to test files, change the minimum to support the new type changes * Remove commented block * fixing import --------- Co-authored-by: Preston Van Loon --- api/client/builder/BUILD.bazel | 2 - api/client/builder/client_test.go | 8 +- api/client/builder/types.go | 965 +----------------- api/client/builder/types_test.go | 351 ++----- api/server/structs/BUILD.bazel | 2 + .../structs/conversions_block_execution.go | 17 + changelog/james-prysm_merge-payload-types.md | 3 + testing/middleware/builder/builder.go | 75 +- 8 files changed, 173 insertions(+), 1250 deletions(-) create mode 100644 changelog/james-prysm_merge-payload-types.md diff --git a/api/client/builder/BUILD.bazel b/api/client/builder/BUILD.bazel index 4db00d3834..028e0191c1 100644 --- a/api/client/builder/BUILD.bazel +++ b/api/client/builder/BUILD.bazel @@ -13,7 +13,6 @@ go_library( deps = [ "//api:go_default_library", "//api/client:go_default_library", - "//api/server:go_default_library", "//api/server/structs:go_default_library", "//config/fieldparams:go_default_library", "//config/params:go_default_library", @@ -28,7 +27,6 @@ go_library( "//proto/engine/v1:go_default_library", "//proto/prysm/v1alpha1:go_default_library", "//runtime/version:go_default_library", - "@com_github_ethereum_go_ethereum//common:go_default_library", "@com_github_ethereum_go_ethereum//common/hexutil:go_default_library", "@com_github_pkg_errors//:go_default_library", "@com_github_prysmaticlabs_fastssz//:go_default_library", diff --git a/api/client/builder/client_test.go b/api/client/builder/client_test.go index 3ae65f4a1b..0b8c147644 100644 --- a/api/client/builder/client_test.go +++ b/api/client/builder/client_test.go @@ -640,9 +640,9 @@ func TestSubmitBlindedBlock(t *testing.T) { require.Equal(t, api.OctetStreamMediaType, r.Header.Get("Accept")) epr := &ExecutionPayloadResponse{} require.NoError(t, json.Unmarshal([]byte(testExampleExecutionPayload), epr)) - ep := &ExecutionPayload{} + ep := &structs.ExecutionPayload{} require.NoError(t, json.Unmarshal(epr.Data, ep)) - pro, err := ep.ToProto() + pro, err := ep.ToConsensus() require.NoError(t, err) ssz, err := pro.MarshalSSZ() require.NoError(t, err) @@ -710,9 +710,9 @@ func TestSubmitBlindedBlock(t *testing.T) { require.Equal(t, api.OctetStreamMediaType, r.Header.Get("Accept")) epr := &ExecutionPayloadResponse{} require.NoError(t, json.Unmarshal([]byte(testExampleExecutionPayloadCapella), epr)) - ep := &ExecutionPayloadCapella{} + ep := &structs.ExecutionPayloadCapella{} require.NoError(t, json.Unmarshal(epr.Data, ep)) - pro, err := ep.ToProto() + pro, err := ep.ToConsensus() require.NoError(t, err) ssz, err := pro.MarshalSSZ() require.NoError(t, err) diff --git a/api/client/builder/types.go b/api/client/builder/types.go index ad3c6c9f6e..df7a52e4ca 100644 --- a/api/client/builder/types.go +++ b/api/client/builder/types.go @@ -7,7 +7,7 @@ import ( "strconv" "strings" - "github.com/OffchainLabs/prysm/v6/api/server" + "github.com/OffchainLabs/prysm/v6/api/server/structs" fieldparams "github.com/OffchainLabs/prysm/v6/config/fieldparams" "github.com/OffchainLabs/prysm/v6/config/params" consensusblocks "github.com/OffchainLabs/prysm/v6/consensus-types/blocks" @@ -17,7 +17,6 @@ import ( v1 "github.com/OffchainLabs/prysm/v6/proto/engine/v1" eth "github.com/OffchainLabs/prysm/v6/proto/prysm/v1alpha1" "github.com/OffchainLabs/prysm/v6/runtime/version" - "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" "github.com/pkg/errors" "google.golang.org/protobuf/proto" @@ -153,7 +152,7 @@ func (ehr *ExecHeaderResponse) ToProto() (*eth.SignedBuilderBid, error) { // ToProto returns a BuilderBid Proto for Bellatrix. func (bb *BuilderBid) ToProto() (*eth.BuilderBid, error) { - header, err := bb.Header.ToProto() + header, err := bb.Header.ToConsensus() if err != nil { return nil, err } @@ -166,254 +165,11 @@ func (bb *BuilderBid) ToProto() (*eth.BuilderBid, error) { }, nil } -// ToProto returns a ExecutionPayloadHeader for Bellatrix. -func (h *ExecutionPayloadHeader) ToProto() (*v1.ExecutionPayloadHeader, error) { - return &v1.ExecutionPayloadHeader{ - ParentHash: bytesutil.SafeCopyBytes(h.ParentHash), - FeeRecipient: bytesutil.SafeCopyBytes(h.FeeRecipient), - StateRoot: bytesutil.SafeCopyBytes(h.StateRoot), - ReceiptsRoot: bytesutil.SafeCopyBytes(h.ReceiptsRoot), - LogsBloom: bytesutil.SafeCopyBytes(h.LogsBloom), - PrevRandao: bytesutil.SafeCopyBytes(h.PrevRandao), - BlockNumber: uint64(h.BlockNumber), - GasLimit: uint64(h.GasLimit), - GasUsed: uint64(h.GasUsed), - Timestamp: uint64(h.Timestamp), - ExtraData: bytesutil.SafeCopyBytes(h.ExtraData), - BaseFeePerGas: bytesutil.SafeCopyBytes(h.BaseFeePerGas.SSZBytes()), - BlockHash: bytesutil.SafeCopyBytes(h.BlockHash), - TransactionsRoot: bytesutil.SafeCopyBytes(h.TransactionsRoot), - }, nil -} - // BuilderBid is part of ExecHeaderResponse for Bellatrix. type BuilderBid struct { - Header *ExecutionPayloadHeader `json:"header"` - Value Uint256 `json:"value"` - Pubkey hexutil.Bytes `json:"pubkey"` -} - -// ExecutionPayloadHeader is a field in BuilderBid. -type ExecutionPayloadHeader struct { - ParentHash hexutil.Bytes `json:"parent_hash"` - FeeRecipient hexutil.Bytes `json:"fee_recipient"` - StateRoot hexutil.Bytes `json:"state_root"` - ReceiptsRoot hexutil.Bytes `json:"receipts_root"` - LogsBloom hexutil.Bytes `json:"logs_bloom"` - PrevRandao hexutil.Bytes `json:"prev_randao"` - BlockNumber Uint64String `json:"block_number"` - GasLimit Uint64String `json:"gas_limit"` - GasUsed Uint64String `json:"gas_used"` - Timestamp Uint64String `json:"timestamp"` - ExtraData hexutil.Bytes `json:"extra_data"` - BaseFeePerGas Uint256 `json:"base_fee_per_gas"` - BlockHash hexutil.Bytes `json:"block_hash"` - TransactionsRoot hexutil.Bytes `json:"transactions_root"` - *v1.ExecutionPayloadHeader -} - -// MarshalJSON returns the JSON bytes representation of ExecutionPayloadHeader. -func (h *ExecutionPayloadHeader) MarshalJSON() ([]byte, error) { - type MarshalCaller ExecutionPayloadHeader - baseFeePerGas, err := sszBytesToUint256(h.ExecutionPayloadHeader.BaseFeePerGas) - if err != nil { - return []byte{}, errors.Wrapf(err, "invalid BaseFeePerGas") - } - return json.Marshal(&MarshalCaller{ - ParentHash: h.ExecutionPayloadHeader.ParentHash, - FeeRecipient: h.ExecutionPayloadHeader.FeeRecipient, - StateRoot: h.ExecutionPayloadHeader.StateRoot, - ReceiptsRoot: h.ExecutionPayloadHeader.ReceiptsRoot, - LogsBloom: h.ExecutionPayloadHeader.LogsBloom, - PrevRandao: h.ExecutionPayloadHeader.PrevRandao, - BlockNumber: Uint64String(h.ExecutionPayloadHeader.BlockNumber), - GasLimit: Uint64String(h.ExecutionPayloadHeader.GasLimit), - GasUsed: Uint64String(h.ExecutionPayloadHeader.GasUsed), - Timestamp: Uint64String(h.ExecutionPayloadHeader.Timestamp), - ExtraData: h.ExecutionPayloadHeader.ExtraData, - BaseFeePerGas: baseFeePerGas, - BlockHash: h.ExecutionPayloadHeader.BlockHash, - TransactionsRoot: h.ExecutionPayloadHeader.TransactionsRoot, - }) -} - -// UnmarshalJSON takes in a JSON byte array and sets ExecutionPayloadHeader. -func (h *ExecutionPayloadHeader) UnmarshalJSON(b []byte) error { - type UnmarshalCaller ExecutionPayloadHeader - uc := &UnmarshalCaller{} - if err := json.Unmarshal(b, uc); err != nil { - return err - } - ep := ExecutionPayloadHeader(*uc) - *h = ep - var err error - h.ExecutionPayloadHeader, err = h.ToProto() - return err -} - -// ExecPayloadResponse is the builder API /eth/v1/builder/blinded_blocks for Bellatrix. -type ExecPayloadResponse struct { - Version string `json:"version"` - Data ExecutionPayload `json:"data"` -} - -// ExecutionPayload is a field of ExecPayloadResponse -type ExecutionPayload struct { - ParentHash hexutil.Bytes `json:"parent_hash"` - FeeRecipient hexutil.Bytes `json:"fee_recipient"` - StateRoot hexutil.Bytes `json:"state_root"` - ReceiptsRoot hexutil.Bytes `json:"receipts_root"` - LogsBloom hexutil.Bytes `json:"logs_bloom"` - PrevRandao hexutil.Bytes `json:"prev_randao"` - BlockNumber Uint64String `json:"block_number"` - GasLimit Uint64String `json:"gas_limit"` - GasUsed Uint64String `json:"gas_used"` - Timestamp Uint64String `json:"timestamp"` - ExtraData hexutil.Bytes `json:"extra_data"` - BaseFeePerGas Uint256 `json:"base_fee_per_gas"` - BlockHash hexutil.Bytes `json:"block_hash"` - Transactions []hexutil.Bytes `json:"transactions"` -} - -// ToProto returns a ExecutionPayload Proto from ExecPayloadResponse -func (r *ExecPayloadResponse) ToProto() (*v1.ExecutionPayload, error) { - return r.Data.ToProto() -} - -func (r *ExecutionPayload) PayloadProto() (proto.Message, error) { - pb, err := r.ToProto() - return pb, err -} - -// ToProto returns a ExecutionPayload Proto -func (p *ExecutionPayload) ToProto() (*v1.ExecutionPayload, error) { - txs := make([][]byte, len(p.Transactions)) - for i := range p.Transactions { - txs[i] = bytesutil.SafeCopyBytes(p.Transactions[i]) - } - return &v1.ExecutionPayload{ - ParentHash: bytesutil.SafeCopyBytes(p.ParentHash), - FeeRecipient: bytesutil.SafeCopyBytes(p.FeeRecipient), - StateRoot: bytesutil.SafeCopyBytes(p.StateRoot), - ReceiptsRoot: bytesutil.SafeCopyBytes(p.ReceiptsRoot), - LogsBloom: bytesutil.SafeCopyBytes(p.LogsBloom), - PrevRandao: bytesutil.SafeCopyBytes(p.PrevRandao), - BlockNumber: uint64(p.BlockNumber), - GasLimit: uint64(p.GasLimit), - GasUsed: uint64(p.GasUsed), - Timestamp: uint64(p.Timestamp), - ExtraData: bytesutil.SafeCopyBytes(p.ExtraData), - BaseFeePerGas: bytesutil.SafeCopyBytes(p.BaseFeePerGas.SSZBytes()), - BlockHash: bytesutil.SafeCopyBytes(p.BlockHash), - Transactions: txs, - }, nil -} - -// FromProto converts a proto execution payload type to our builder -// compatible payload type. -func FromProto(payload *v1.ExecutionPayload) (ExecutionPayload, error) { - bFee, err := sszBytesToUint256(payload.BaseFeePerGas) - if err != nil { - return ExecutionPayload{}, err - } - txs := make([]hexutil.Bytes, len(payload.Transactions)) - for i := range payload.Transactions { - txs[i] = bytesutil.SafeCopyBytes(payload.Transactions[i]) - } - return ExecutionPayload{ - ParentHash: bytesutil.SafeCopyBytes(payload.ParentHash), - FeeRecipient: bytesutil.SafeCopyBytes(payload.FeeRecipient), - StateRoot: bytesutil.SafeCopyBytes(payload.StateRoot), - ReceiptsRoot: bytesutil.SafeCopyBytes(payload.ReceiptsRoot), - LogsBloom: bytesutil.SafeCopyBytes(payload.LogsBloom), - PrevRandao: bytesutil.SafeCopyBytes(payload.PrevRandao), - BlockNumber: Uint64String(payload.BlockNumber), - GasLimit: Uint64String(payload.GasLimit), - GasUsed: Uint64String(payload.GasUsed), - Timestamp: Uint64String(payload.Timestamp), - ExtraData: bytesutil.SafeCopyBytes(payload.ExtraData), - BaseFeePerGas: bFee, - BlockHash: bytesutil.SafeCopyBytes(payload.BlockHash), - Transactions: txs, - }, nil -} - -// FromProtoCapella converts a proto execution payload type for capella to our -// builder compatible payload type. -func FromProtoCapella(payload *v1.ExecutionPayloadCapella) (ExecutionPayloadCapella, error) { - bFee, err := sszBytesToUint256(payload.BaseFeePerGas) - if err != nil { - return ExecutionPayloadCapella{}, err - } - txs := make([]hexutil.Bytes, len(payload.Transactions)) - for i := range payload.Transactions { - txs[i] = bytesutil.SafeCopyBytes(payload.Transactions[i]) - } - withdrawals := make([]Withdrawal, len(payload.Withdrawals)) - for i, w := range payload.Withdrawals { - withdrawals[i] = Withdrawal{ - Index: Uint256{Int: big.NewInt(0).SetUint64(w.Index)}, - ValidatorIndex: Uint256{Int: big.NewInt(0).SetUint64(uint64(w.ValidatorIndex))}, - Address: bytesutil.SafeCopyBytes(w.Address), - Amount: Uint256{Int: big.NewInt(0).SetUint64(w.Amount)}, - } - } - return ExecutionPayloadCapella{ - ParentHash: bytesutil.SafeCopyBytes(payload.ParentHash), - FeeRecipient: bytesutil.SafeCopyBytes(payload.FeeRecipient), - StateRoot: bytesutil.SafeCopyBytes(payload.StateRoot), - ReceiptsRoot: bytesutil.SafeCopyBytes(payload.ReceiptsRoot), - LogsBloom: bytesutil.SafeCopyBytes(payload.LogsBloom), - PrevRandao: bytesutil.SafeCopyBytes(payload.PrevRandao), - BlockNumber: Uint64String(payload.BlockNumber), - GasLimit: Uint64String(payload.GasLimit), - GasUsed: Uint64String(payload.GasUsed), - Timestamp: Uint64String(payload.Timestamp), - ExtraData: bytesutil.SafeCopyBytes(payload.ExtraData), - BaseFeePerGas: bFee, - BlockHash: bytesutil.SafeCopyBytes(payload.BlockHash), - Transactions: txs, - Withdrawals: withdrawals, - }, nil -} - -func FromProtoDeneb(payload *v1.ExecutionPayloadDeneb) (ExecutionPayloadDeneb, error) { - bFee, err := sszBytesToUint256(payload.BaseFeePerGas) - if err != nil { - return ExecutionPayloadDeneb{}, err - } - txs := make([]hexutil.Bytes, len(payload.Transactions)) - for i := range payload.Transactions { - txs[i] = bytesutil.SafeCopyBytes(payload.Transactions[i]) - } - withdrawals := make([]Withdrawal, len(payload.Withdrawals)) - for i, w := range payload.Withdrawals { - withdrawals[i] = Withdrawal{ - Index: Uint256{Int: big.NewInt(0).SetUint64(w.Index)}, - ValidatorIndex: Uint256{Int: big.NewInt(0).SetUint64(uint64(w.ValidatorIndex))}, - Address: bytesutil.SafeCopyBytes(w.Address), - Amount: Uint256{Int: big.NewInt(0).SetUint64(w.Amount)}, - } - } - return ExecutionPayloadDeneb{ - ParentHash: bytesutil.SafeCopyBytes(payload.ParentHash), - FeeRecipient: bytesutil.SafeCopyBytes(payload.FeeRecipient), - StateRoot: bytesutil.SafeCopyBytes(payload.StateRoot), - ReceiptsRoot: bytesutil.SafeCopyBytes(payload.ReceiptsRoot), - LogsBloom: bytesutil.SafeCopyBytes(payload.LogsBloom), - PrevRandao: bytesutil.SafeCopyBytes(payload.PrevRandao), - BlockNumber: Uint64String(payload.BlockNumber), - GasLimit: Uint64String(payload.GasLimit), - GasUsed: Uint64String(payload.GasUsed), - Timestamp: Uint64String(payload.Timestamp), - ExtraData: bytesutil.SafeCopyBytes(payload.ExtraData), - BaseFeePerGas: bFee, - BlockHash: bytesutil.SafeCopyBytes(payload.BlockHash), - Transactions: txs, - Withdrawals: withdrawals, - BlobGasUsed: Uint64String(payload.BlobGasUsed), - ExcessBlobGas: Uint64String(payload.ExcessBlobGas), - }, nil + Header *structs.ExecutionPayloadHeader `json:"header"` + Value Uint256 `json:"value"` + Pubkey hexutil.Bytes `json:"pubkey"` } // ExecHeaderResponseCapella is the response of builder API /eth/v1/builder/header/{slot}/{parent_hash}/{pubkey} for Capella. @@ -439,7 +195,7 @@ func (ehr *ExecHeaderResponseCapella) ToProto() (*eth.SignedBuilderBidCapella, e // ToProto returns a BuilderBidCapella Proto. func (bb *BuilderBidCapella) ToProto() (*eth.BuilderBidCapella, error) { - header, err := bb.Header.ToProto() + header, err := bb.Header.ToConsensus() if err != nil { return nil, err } @@ -452,98 +208,17 @@ func (bb *BuilderBidCapella) ToProto() (*eth.BuilderBidCapella, error) { }, nil } -// ToProto returns a ExecutionPayloadHeaderCapella Proto -func (h *ExecutionPayloadHeaderCapella) ToProto() (*v1.ExecutionPayloadHeaderCapella, error) { - return &v1.ExecutionPayloadHeaderCapella{ - ParentHash: bytesutil.SafeCopyBytes(h.ParentHash), - FeeRecipient: bytesutil.SafeCopyBytes(h.FeeRecipient), - StateRoot: bytesutil.SafeCopyBytes(h.StateRoot), - ReceiptsRoot: bytesutil.SafeCopyBytes(h.ReceiptsRoot), - LogsBloom: bytesutil.SafeCopyBytes(h.LogsBloom), - PrevRandao: bytesutil.SafeCopyBytes(h.PrevRandao), - BlockNumber: uint64(h.BlockNumber), - GasLimit: uint64(h.GasLimit), - GasUsed: uint64(h.GasUsed), - Timestamp: uint64(h.Timestamp), - ExtraData: bytesutil.SafeCopyBytes(h.ExtraData), - BaseFeePerGas: bytesutil.SafeCopyBytes(h.BaseFeePerGas.SSZBytes()), - BlockHash: bytesutil.SafeCopyBytes(h.BlockHash), - TransactionsRoot: bytesutil.SafeCopyBytes(h.TransactionsRoot), - WithdrawalsRoot: bytesutil.SafeCopyBytes(h.WithdrawalsRoot), - }, nil -} - // BuilderBidCapella is field of ExecHeaderResponseCapella. type BuilderBidCapella struct { - Header *ExecutionPayloadHeaderCapella `json:"header"` - Value Uint256 `json:"value"` - Pubkey hexutil.Bytes `json:"pubkey"` -} - -// ExecutionPayloadHeaderCapella is a field in BuilderBidCapella. -type ExecutionPayloadHeaderCapella struct { - ParentHash hexutil.Bytes `json:"parent_hash"` - FeeRecipient hexutil.Bytes `json:"fee_recipient"` - StateRoot hexutil.Bytes `json:"state_root"` - ReceiptsRoot hexutil.Bytes `json:"receipts_root"` - LogsBloom hexutil.Bytes `json:"logs_bloom"` - PrevRandao hexutil.Bytes `json:"prev_randao"` - BlockNumber Uint64String `json:"block_number"` - GasLimit Uint64String `json:"gas_limit"` - GasUsed Uint64String `json:"gas_used"` - Timestamp Uint64String `json:"timestamp"` - ExtraData hexutil.Bytes `json:"extra_data"` - BaseFeePerGas Uint256 `json:"base_fee_per_gas"` - BlockHash hexutil.Bytes `json:"block_hash"` - TransactionsRoot hexutil.Bytes `json:"transactions_root"` - WithdrawalsRoot hexutil.Bytes `json:"withdrawals_root"` - *v1.ExecutionPayloadHeaderCapella -} - -// MarshalJSON returns a JSON byte representation of ExecutionPayloadHeaderCapella. -func (h *ExecutionPayloadHeaderCapella) MarshalJSON() ([]byte, error) { - type MarshalCaller ExecutionPayloadHeaderCapella - baseFeePerGas, err := sszBytesToUint256(h.ExecutionPayloadHeaderCapella.BaseFeePerGas) - if err != nil { - return []byte{}, errors.Wrapf(err, "invalid BaseFeePerGas") - } - return json.Marshal(&MarshalCaller{ - ParentHash: h.ExecutionPayloadHeaderCapella.ParentHash, - FeeRecipient: h.ExecutionPayloadHeaderCapella.FeeRecipient, - StateRoot: h.ExecutionPayloadHeaderCapella.StateRoot, - ReceiptsRoot: h.ExecutionPayloadHeaderCapella.ReceiptsRoot, - LogsBloom: h.ExecutionPayloadHeaderCapella.LogsBloom, - PrevRandao: h.ExecutionPayloadHeaderCapella.PrevRandao, - BlockNumber: Uint64String(h.ExecutionPayloadHeaderCapella.BlockNumber), - GasLimit: Uint64String(h.ExecutionPayloadHeaderCapella.GasLimit), - GasUsed: Uint64String(h.ExecutionPayloadHeaderCapella.GasUsed), - Timestamp: Uint64String(h.ExecutionPayloadHeaderCapella.Timestamp), - ExtraData: h.ExecutionPayloadHeaderCapella.ExtraData, - BaseFeePerGas: baseFeePerGas, - BlockHash: h.ExecutionPayloadHeaderCapella.BlockHash, - TransactionsRoot: h.ExecutionPayloadHeaderCapella.TransactionsRoot, - WithdrawalsRoot: h.ExecutionPayloadHeaderCapella.WithdrawalsRoot, - }) -} - -// UnmarshalJSON takes a JSON byte array and sets ExecutionPayloadHeaderCapella. -func (h *ExecutionPayloadHeaderCapella) UnmarshalJSON(b []byte) error { - type UnmarshalCaller ExecutionPayloadHeaderCapella - uc := &UnmarshalCaller{} - if err := json.Unmarshal(b, uc); err != nil { - return err - } - ep := ExecutionPayloadHeaderCapella(*uc) - *h = ep - var err error - h.ExecutionPayloadHeaderCapella, err = h.ToProto() - return err + Header *structs.ExecutionPayloadHeaderCapella `json:"header"` + Value Uint256 `json:"value"` + Pubkey hexutil.Bytes `json:"pubkey"` } // ExecPayloadResponseCapella is the builder API /eth/v1/builder/blinded_blocks for Capella. type ExecPayloadResponseCapella struct { - Version string `json:"version"` - Data ExecutionPayloadCapella `json:"data"` + Version string `json:"version"` + Data structs.ExecutionPayloadCapella `json:"data"` } // ExecutionPayloadResponse allows for unmarshaling just the Version field of the payload. @@ -577,80 +252,24 @@ func (r *ExecutionPayloadResponse) ParsePayload() (ParsedPayload, error) { if v >= version.Deneb { toProto = &ExecutionPayloadDenebAndBlobsBundle{} } else if v >= version.Capella { - toProto = &ExecutionPayloadCapella{} + toProto = &structs.ExecutionPayloadCapella{} } else if v >= version.Bellatrix { - toProto = &ExecutionPayload{} + toProto = &structs.ExecutionPayload{} } else { return nil, fmt.Errorf("unsupported version %s", strings.ToLower(r.Version)) } - + if len(r.Data) == 0 { + return nil, errors.Wrap(consensusblocks.ErrNilObject, "empty payload data response") + } if err := json.Unmarshal(r.Data, toProto); err != nil { return nil, errors.Wrap(err, "failed to unmarshal the response .Data field with the stated version schema") } return toProto, nil } -// ExecutionPayloadCapella is a field of ExecPayloadResponseCapella. -type ExecutionPayloadCapella struct { - ParentHash hexutil.Bytes `json:"parent_hash"` - FeeRecipient hexutil.Bytes `json:"fee_recipient"` - StateRoot hexutil.Bytes `json:"state_root"` - ReceiptsRoot hexutil.Bytes `json:"receipts_root"` - LogsBloom hexutil.Bytes `json:"logs_bloom"` - PrevRandao hexutil.Bytes `json:"prev_randao"` - BlockNumber Uint64String `json:"block_number"` - GasLimit Uint64String `json:"gas_limit"` - GasUsed Uint64String `json:"gas_used"` - Timestamp Uint64String `json:"timestamp"` - ExtraData hexutil.Bytes `json:"extra_data"` - BaseFeePerGas Uint256 `json:"base_fee_per_gas"` - BlockHash hexutil.Bytes `json:"block_hash"` - Transactions []hexutil.Bytes `json:"transactions"` - Withdrawals []Withdrawal `json:"withdrawals"` -} - // ToProto returns a ExecutionPayloadCapella Proto. func (r *ExecPayloadResponseCapella) ToProto() (*v1.ExecutionPayloadCapella, error) { - return r.Data.ToProto() -} - -func (p *ExecutionPayloadCapella) PayloadProto() (proto.Message, error) { - pb, err := p.ToProto() - return pb, err -} - -// ToProto returns a ExecutionPayloadCapella Proto. -func (p *ExecutionPayloadCapella) ToProto() (*v1.ExecutionPayloadCapella, error) { - txs := make([][]byte, len(p.Transactions)) - for i := range p.Transactions { - txs[i] = bytesutil.SafeCopyBytes(p.Transactions[i]) - } - withdrawals := make([]*v1.Withdrawal, len(p.Withdrawals)) - for i, w := range p.Withdrawals { - withdrawals[i] = &v1.Withdrawal{ - Index: w.Index.Uint64(), - ValidatorIndex: types.ValidatorIndex(w.ValidatorIndex.Uint64()), - Address: bytesutil.SafeCopyBytes(w.Address), - Amount: w.Amount.Uint64(), - } - } - return &v1.ExecutionPayloadCapella{ - ParentHash: bytesutil.SafeCopyBytes(p.ParentHash), - FeeRecipient: bytesutil.SafeCopyBytes(p.FeeRecipient), - StateRoot: bytesutil.SafeCopyBytes(p.StateRoot), - ReceiptsRoot: bytesutil.SafeCopyBytes(p.ReceiptsRoot), - LogsBloom: bytesutil.SafeCopyBytes(p.LogsBloom), - PrevRandao: bytesutil.SafeCopyBytes(p.PrevRandao), - BlockNumber: uint64(p.BlockNumber), - GasLimit: uint64(p.GasLimit), - GasUsed: uint64(p.GasUsed), - Timestamp: uint64(p.Timestamp), - ExtraData: bytesutil.SafeCopyBytes(p.ExtraData), - BaseFeePerGas: bytesutil.SafeCopyBytes(p.BaseFeePerGas.SSZBytes()), - BlockHash: bytesutil.SafeCopyBytes(p.BlockHash), - Transactions: txs, - Withdrawals: withdrawals, - }, nil + return r.Data.ToConsensus() } // Withdrawal is a field of ExecutionPayloadCapella. @@ -720,240 +339,6 @@ func (h *BeaconBlockHeader) MarshalJSON() ([]byte, error) { }) } -// IndexedAttestation is a field of AttesterSlashing. -type IndexedAttestation struct { - *eth.IndexedAttestation -} - -// MarshalJSON returns a JSON byte array representation of IndexedAttestation. -func (a *IndexedAttestation) MarshalJSON() ([]byte, error) { - indices := make([]string, len(a.IndexedAttestation.AttestingIndices)) - for i := range a.IndexedAttestation.AttestingIndices { - indices[i] = fmt.Sprintf("%d", a.AttestingIndices[i]) - } - return json.Marshal(struct { - AttestingIndices []string `json:"attesting_indices"` - Data *AttestationData `json:"data"` - Signature hexutil.Bytes `json:"signature"` - }{ - AttestingIndices: indices, - Data: &AttestationData{a.IndexedAttestation.Data}, - Signature: a.IndexedAttestation.Signature, - }) -} - -// AttesterSlashing is a field of a Beacon Block Body. -type AttesterSlashing struct { - *eth.AttesterSlashing -} - -// MarshalJSON returns a JSON byte array representation of AttesterSlashing. -func (s *AttesterSlashing) MarshalJSON() ([]byte, error) { - return json.Marshal(struct { - Attestation1 *IndexedAttestation `json:"attestation_1"` - Attestation2 *IndexedAttestation `json:"attestation_2"` - }{ - Attestation1: &IndexedAttestation{s.Attestation_1}, - Attestation2: &IndexedAttestation{s.Attestation_2}, - }) -} - -// Checkpoint is a field of AttestationData. -type Checkpoint struct { - *eth.Checkpoint -} - -// MarshalJSON returns a JSON byte array representation of Checkpoint. -func (c *Checkpoint) MarshalJSON() ([]byte, error) { - return json.Marshal(struct { - Epoch string `json:"epoch"` - Root hexutil.Bytes `json:"root"` - }{ - Epoch: fmt.Sprintf("%d", c.Checkpoint.Epoch), - Root: c.Checkpoint.Root, - }) -} - -// AttestationData is a field of IndexedAttestation. -type AttestationData struct { - *eth.AttestationData -} - -// MarshalJSON returns a JSON byte array representation of AttestationData. -func (a *AttestationData) MarshalJSON() ([]byte, error) { - return json.Marshal(struct { - Slot string `json:"slot"` - Index string `json:"index"` - BeaconBlockRoot hexutil.Bytes `json:"beacon_block_root"` - Source *Checkpoint `json:"source"` - Target *Checkpoint `json:"target"` - }{ - Slot: fmt.Sprintf("%d", a.AttestationData.Slot), - Index: fmt.Sprintf("%d", a.AttestationData.CommitteeIndex), - BeaconBlockRoot: a.AttestationData.BeaconBlockRoot, - Source: &Checkpoint{a.AttestationData.Source}, - Target: &Checkpoint{a.AttestationData.Target}, - }) -} - -// Attestation is a field of Beacon Block Body. -type Attestation struct { - *eth.Attestation -} - -// MarshalJSON returns a JSON byte array representation of Attestation. -func (a *Attestation) MarshalJSON() ([]byte, error) { - return json.Marshal(struct { - AggregationBits hexutil.Bytes `json:"aggregation_bits"` - Data *AttestationData `json:"data"` - Signature hexutil.Bytes `json:"signature" ssz-size:"96"` - }{ - AggregationBits: hexutil.Bytes(a.Attestation.AggregationBits), - Data: &AttestationData{a.Attestation.Data}, - Signature: a.Attestation.Signature, - }) -} - -// DepositData is a field of Deposit. -type DepositData struct { - *eth.Deposit_Data -} - -// MarshalJSON returns a JSON byte array representation of DepositData. -func (d *DepositData) MarshalJSON() ([]byte, error) { - return json.Marshal(struct { - PublicKey hexutil.Bytes `json:"pubkey"` - WithdrawalCredentials hexutil.Bytes `json:"withdrawal_credentials"` - Amount string `json:"amount"` - Signature hexutil.Bytes `json:"signature"` - }{ - PublicKey: d.PublicKey, - WithdrawalCredentials: d.WithdrawalCredentials, - Amount: fmt.Sprintf("%d", d.Amount), - Signature: d.Signature, - }) -} - -// Deposit is a field of Beacon Block Body. -type Deposit struct { - *eth.Deposit -} - -// MarshalJSON returns a JSON byte array representation of Deposit. -func (d *Deposit) MarshalJSON() ([]byte, error) { - proof := make([]hexutil.Bytes, len(d.Proof)) - for i := range d.Proof { - proof[i] = d.Proof[i] - } - return json.Marshal(struct { - Proof []hexutil.Bytes `json:"proof"` - Data *DepositData `json:"data"` - }{ - Proof: proof, - Data: &DepositData{Deposit_Data: d.Deposit.Data}, - }) -} - -// SignedVoluntaryExit is a field of Beacon Block Body. -type SignedVoluntaryExit struct { - *eth.SignedVoluntaryExit -} - -// MarshalJSON returns a JSON byte array representation of SignedVoluntaryExit. -func (sve *SignedVoluntaryExit) MarshalJSON() ([]byte, error) { - return json.Marshal(struct { - Message *VoluntaryExit `json:"message"` - Signature hexutil.Bytes `json:"signature"` - }{ - Signature: sve.SignedVoluntaryExit.Signature, - Message: &VoluntaryExit{sve.SignedVoluntaryExit.Exit}, - }) -} - -// VoluntaryExit is a field in SignedVoluntaryExit -type VoluntaryExit struct { - *eth.VoluntaryExit -} - -// MarshalJSON returns a JSON byte array representation of VoluntaryExit -func (ve *VoluntaryExit) MarshalJSON() ([]byte, error) { - return json.Marshal(struct { - Epoch string `json:"epoch"` - ValidatorIndex string `json:"validator_index"` - }{ - Epoch: fmt.Sprintf("%d", ve.Epoch), - ValidatorIndex: fmt.Sprintf("%d", ve.ValidatorIndex), - }) -} - -// SyncAggregate is a field of Beacon Block Body. -type SyncAggregate struct { - *eth.SyncAggregate -} - -// MarshalJSON returns a JSON byte array representation of SyncAggregate. -func (s *SyncAggregate) MarshalJSON() ([]byte, error) { - return json.Marshal(struct { - SyncCommitteeBits hexutil.Bytes `json:"sync_committee_bits"` - SyncCommitteeSignature hexutil.Bytes `json:"sync_committee_signature"` - }{ - SyncCommitteeBits: hexutil.Bytes(s.SyncAggregate.SyncCommitteeBits), - SyncCommitteeSignature: s.SyncAggregate.SyncCommitteeSignature, - }) -} - -// Eth1Data is a field of Beacon Block Body. -type Eth1Data struct { - *eth.Eth1Data -} - -// MarshalJSON returns a JSON byte array representation of Eth1Data. -func (e *Eth1Data) MarshalJSON() ([]byte, error) { - return json.Marshal(struct { - DepositRoot hexutil.Bytes `json:"deposit_root"` - DepositCount string `json:"deposit_count"` - BlockHash hexutil.Bytes `json:"block_hash"` - }{ - DepositRoot: e.DepositRoot, - DepositCount: fmt.Sprintf("%d", e.DepositCount), - BlockHash: e.BlockHash, - }) -} - -// SignedBLSToExecutionChange is a field in Beacon Block Body for capella and above. -type SignedBLSToExecutionChange struct { - *eth.SignedBLSToExecutionChange -} - -// MarshalJSON returns a JSON byte array representation of SignedBLSToExecutionChange. -func (ch *SignedBLSToExecutionChange) MarshalJSON() ([]byte, error) { - return json.Marshal(struct { - Message *BLSToExecutionChange `json:"message"` - Signature hexutil.Bytes `json:"signature"` - }{ - Signature: ch.Signature, - Message: &BLSToExecutionChange{ch.Message}, - }) -} - -// BLSToExecutionChange is a field in SignedBLSToExecutionChange. -type BLSToExecutionChange struct { - *eth.BLSToExecutionChange -} - -// MarshalJSON returns a JSON byte array representation of BLSToExecutionChange. -func (ch *BLSToExecutionChange) MarshalJSON() ([]byte, error) { - return json.Marshal(struct { - ValidatorIndex string `json:"validator_index"` - FromBlsPubkey hexutil.Bytes `json:"from_bls_pubkey"` - ToExecutionAddress hexutil.Bytes `json:"to_execution_address"` - }{ - ValidatorIndex: fmt.Sprintf("%d", ch.ValidatorIndex), - FromBlsPubkey: ch.FromBlsPubkey, - ToExecutionAddress: ch.ToExecutionAddress, - }) -} - // ExecHeaderResponseDeneb is the header response for builder API /eth/v1/builder/header/{slot}/{parent_hash}/{pubkey}. type ExecHeaderResponseDeneb struct { Version string `json:"version"` @@ -977,7 +362,7 @@ func (ehr *ExecHeaderResponseDeneb) ToProto() (*eth.SignedBuilderBidDeneb, error // ToProto creates a BuilderBidDeneb Proto from BuilderBidDeneb. func (bb *BuilderBidDeneb) ToProto() (*eth.BuilderBidDeneb, error) { - header, err := bb.Header.ToProto() + header, err := bb.Header.ToConsensus() if err != nil { return nil, err } @@ -1003,97 +388,10 @@ func (bb *BuilderBidDeneb) ToProto() (*eth.BuilderBidDeneb, error) { // BuilderBidDeneb is a field of ExecHeaderResponseDeneb. type BuilderBidDeneb struct { - Header *ExecutionPayloadHeaderDeneb `json:"header"` - BlobKzgCommitments []hexutil.Bytes `json:"blob_kzg_commitments"` - Value Uint256 `json:"value"` - Pubkey hexutil.Bytes `json:"pubkey"` -} - -// ExecutionPayloadHeaderDeneb a field part of the BuilderBidDeneb. -type ExecutionPayloadHeaderDeneb struct { - ParentHash hexutil.Bytes `json:"parent_hash"` - FeeRecipient hexutil.Bytes `json:"fee_recipient"` - StateRoot hexutil.Bytes `json:"state_root"` - ReceiptsRoot hexutil.Bytes `json:"receipts_root"` - LogsBloom hexutil.Bytes `json:"logs_bloom"` - PrevRandao hexutil.Bytes `json:"prev_randao"` - BlockNumber Uint64String `json:"block_number"` - GasLimit Uint64String `json:"gas_limit"` - GasUsed Uint64String `json:"gas_used"` - Timestamp Uint64String `json:"timestamp"` - ExtraData hexutil.Bytes `json:"extra_data"` - BaseFeePerGas Uint256 `json:"base_fee_per_gas"` - BlockHash hexutil.Bytes `json:"block_hash"` - TransactionsRoot hexutil.Bytes `json:"transactions_root"` - WithdrawalsRoot hexutil.Bytes `json:"withdrawals_root"` - BlobGasUsed Uint64String `json:"blob_gas_used"` // new in deneb - ExcessBlobGas Uint64String `json:"excess_blob_gas"` // new in deneb - *v1.ExecutionPayloadHeaderDeneb -} - -// MarshalJSON returns a JSON byte array representing the ExecutionPayloadHeaderDeneb struct. -func (h *ExecutionPayloadHeaderDeneb) MarshalJSON() ([]byte, error) { - type MarshalCaller ExecutionPayloadHeaderDeneb - baseFeePerGas, err := sszBytesToUint256(h.ExecutionPayloadHeaderDeneb.BaseFeePerGas) - if err != nil { - return []byte{}, errors.Wrapf(err, "invalid BaseFeePerGas") - } - return json.Marshal(&MarshalCaller{ - ParentHash: h.ExecutionPayloadHeaderDeneb.ParentHash, - FeeRecipient: h.ExecutionPayloadHeaderDeneb.FeeRecipient, - StateRoot: h.ExecutionPayloadHeaderDeneb.StateRoot, - ReceiptsRoot: h.ExecutionPayloadHeaderDeneb.ReceiptsRoot, - LogsBloom: h.ExecutionPayloadHeaderDeneb.LogsBloom, - PrevRandao: h.ExecutionPayloadHeaderDeneb.PrevRandao, - BlockNumber: Uint64String(h.ExecutionPayloadHeaderDeneb.BlockNumber), - GasLimit: Uint64String(h.ExecutionPayloadHeaderDeneb.GasLimit), - GasUsed: Uint64String(h.ExecutionPayloadHeaderDeneb.GasUsed), - Timestamp: Uint64String(h.ExecutionPayloadHeaderDeneb.Timestamp), - ExtraData: h.ExecutionPayloadHeaderDeneb.ExtraData, - BaseFeePerGas: baseFeePerGas, - BlockHash: h.ExecutionPayloadHeaderDeneb.BlockHash, - TransactionsRoot: h.ExecutionPayloadHeaderDeneb.TransactionsRoot, - WithdrawalsRoot: h.ExecutionPayloadHeaderDeneb.WithdrawalsRoot, - BlobGasUsed: Uint64String(h.ExecutionPayloadHeaderDeneb.BlobGasUsed), - ExcessBlobGas: Uint64String(h.ExecutionPayloadHeaderDeneb.ExcessBlobGas), - }) -} - -// UnmarshalJSON takes in a byte array and unmarshals the value into ExecutionPayloadHeaderDeneb. -func (h *ExecutionPayloadHeaderDeneb) UnmarshalJSON(b []byte) error { - type UnmarshalCaller ExecutionPayloadHeaderDeneb - uc := &UnmarshalCaller{} - if err := json.Unmarshal(b, uc); err != nil { - return err - } - ep := ExecutionPayloadHeaderDeneb(*uc) - *h = ep - var err error - h.ExecutionPayloadHeaderDeneb, err = h.ToProto() - return err -} - -// ToProto returns a ExecutionPayloadHeaderDeneb Proto object. -func (h *ExecutionPayloadHeaderDeneb) ToProto() (*v1.ExecutionPayloadHeaderDeneb, error) { - return &v1.ExecutionPayloadHeaderDeneb{ - ParentHash: bytesutil.SafeCopyBytes(h.ParentHash), - FeeRecipient: bytesutil.SafeCopyBytes(h.FeeRecipient), - StateRoot: bytesutil.SafeCopyBytes(h.StateRoot), - ReceiptsRoot: bytesutil.SafeCopyBytes(h.ReceiptsRoot), - LogsBloom: bytesutil.SafeCopyBytes(h.LogsBloom), - PrevRandao: bytesutil.SafeCopyBytes(h.PrevRandao), - BlockNumber: uint64(h.BlockNumber), - GasLimit: uint64(h.GasLimit), - GasUsed: uint64(h.GasUsed), - Timestamp: uint64(h.Timestamp), - ExtraData: bytesutil.SafeCopyBytes(h.ExtraData), - BaseFeePerGas: bytesutil.SafeCopyBytes(h.BaseFeePerGas.SSZBytes()), - BlockHash: bytesutil.SafeCopyBytes(h.BlockHash), - TransactionsRoot: bytesutil.SafeCopyBytes(h.TransactionsRoot), - WithdrawalsRoot: bytesutil.SafeCopyBytes(h.WithdrawalsRoot), - BlobGasUsed: uint64(h.BlobGasUsed), - ExcessBlobGas: uint64(h.ExcessBlobGas), - }, nil + Header *structs.ExecutionPayloadHeaderDeneb `json:"header"` + BlobKzgCommitments []hexutil.Bytes `json:"blob_kzg_commitments"` + Value Uint256 `json:"value"` + Pubkey hexutil.Bytes `json:"pubkey"` } // ExecPayloadResponseDeneb the response to the build API /eth/v1/builder/blinded_blocks that includes the version, execution payload object , and blobs bundle object. @@ -1104,29 +402,8 @@ type ExecPayloadResponseDeneb struct { // ExecutionPayloadDenebAndBlobsBundle the main field used in ExecPayloadResponseDeneb. type ExecutionPayloadDenebAndBlobsBundle struct { - ExecutionPayload *ExecutionPayloadDeneb `json:"execution_payload"` - BlobsBundle *BlobsBundle `json:"blobs_bundle"` -} - -// ExecutionPayloadDeneb is a field used in ExecutionPayloadDenebAndBlobsBundle. -type ExecutionPayloadDeneb struct { - ParentHash hexutil.Bytes `json:"parent_hash"` - FeeRecipient hexutil.Bytes `json:"fee_recipient"` - StateRoot hexutil.Bytes `json:"state_root"` - ReceiptsRoot hexutil.Bytes `json:"receipts_root"` - LogsBloom hexutil.Bytes `json:"logs_bloom"` - PrevRandao hexutil.Bytes `json:"prev_randao"` - BlockNumber Uint64String `json:"block_number"` - GasLimit Uint64String `json:"gas_limit"` - GasUsed Uint64String `json:"gas_used"` - Timestamp Uint64String `json:"timestamp"` - ExtraData hexutil.Bytes `json:"extra_data"` - BaseFeePerGas Uint256 `json:"base_fee_per_gas"` - BlockHash hexutil.Bytes `json:"block_hash"` - Transactions []hexutil.Bytes `json:"transactions"` - Withdrawals []Withdrawal `json:"withdrawals"` - BlobGasUsed Uint64String `json:"blob_gas_used"` // new in deneb - ExcessBlobGas Uint64String `json:"excess_blob_gas"` // new in deneb + ExecutionPayload *structs.ExecutionPayloadDeneb `json:"execution_payload"` + BlobsBundle *BlobsBundle `json:"blobs_bundle"` } // BlobsBundle is a field in ExecutionPayloadDenebAndBlobsBundle. @@ -1209,7 +486,7 @@ func (r *ExecPayloadResponseDeneb) ToProto() (*v1.ExecutionPayloadDeneb, *v1.Blo if r.Data.BlobsBundle == nil { return nil, nil, errors.Wrap(consensusblocks.ErrNilObject, "nil blobs bundle") } - payload, err := r.Data.ExecutionPayload.ToProto() + payload, err := r.Data.ExecutionPayload.ToConsensus() if err != nil { return nil, nil, err } @@ -1224,7 +501,7 @@ func (r *ExecutionPayloadDenebAndBlobsBundle) PayloadProto() (proto.Message, err if r.ExecutionPayload == nil { return nil, errors.Wrap(consensusblocks.ErrNilObject, "nil execution payload in combined deneb payload") } - pb, err := r.ExecutionPayload.ToProto() + pb, err := r.ExecutionPayload.ToConsensus() return pb, err } @@ -1235,45 +512,6 @@ func (r *ExecutionPayloadDenebAndBlobsBundle) BundleProto() (*v1.BlobsBundle, er return r.BlobsBundle.ToProto() } -// ToProto returns the ExecutionPayloadDeneb Proto. -func (p *ExecutionPayloadDeneb) ToProto() (*v1.ExecutionPayloadDeneb, error) { - if p == nil { - return nil, errors.Wrap(consensusblocks.ErrNilObject, "nil execution payload") - } - txs := make([][]byte, len(p.Transactions)) - for i := range p.Transactions { - txs[i] = bytesutil.SafeCopyBytes(p.Transactions[i]) - } - withdrawals := make([]*v1.Withdrawal, len(p.Withdrawals)) - for i, w := range p.Withdrawals { - withdrawals[i] = &v1.Withdrawal{ - Index: w.Index.Uint64(), - ValidatorIndex: types.ValidatorIndex(w.ValidatorIndex.Uint64()), - Address: bytesutil.SafeCopyBytes(w.Address), - Amount: w.Amount.Uint64(), - } - } - return &v1.ExecutionPayloadDeneb{ - ParentHash: bytesutil.SafeCopyBytes(p.ParentHash), - FeeRecipient: bytesutil.SafeCopyBytes(p.FeeRecipient), - StateRoot: bytesutil.SafeCopyBytes(p.StateRoot), - ReceiptsRoot: bytesutil.SafeCopyBytes(p.ReceiptsRoot), - LogsBloom: bytesutil.SafeCopyBytes(p.LogsBloom), - PrevRandao: bytesutil.SafeCopyBytes(p.PrevRandao), - BlockNumber: uint64(p.BlockNumber), - GasLimit: uint64(p.GasLimit), - GasUsed: uint64(p.GasUsed), - Timestamp: uint64(p.Timestamp), - ExtraData: bytesutil.SafeCopyBytes(p.ExtraData), - BaseFeePerGas: bytesutil.SafeCopyBytes(p.BaseFeePerGas.SSZBytes()), - BlockHash: bytesutil.SafeCopyBytes(p.BlockHash), - Transactions: txs, - Withdrawals: withdrawals, - BlobGasUsed: uint64(p.BlobGasUsed), - ExcessBlobGas: uint64(p.ExcessBlobGas), - }, nil -} - // ExecHeaderResponseElectra is the header response for builder API /eth/v1/builder/header/{slot}/{parent_hash}/{pubkey}. type ExecHeaderResponseElectra struct { Version string `json:"version"` @@ -1297,7 +535,7 @@ func (ehr *ExecHeaderResponseElectra) ToProto(slot types.Slot) (*eth.SignedBuild // ToProto creates a BuilderBidElectra Proto from BuilderBidElectra. func (bb *BuilderBidElectra) ToProto(slot types.Slot) (*eth.BuilderBidElectra, error) { - header, err := bb.Header.ToProto() + header, err := bb.Header.ToConsensus() if err != nil { return nil, err } @@ -1316,7 +554,7 @@ func (bb *BuilderBidElectra) ToProto(slot types.Slot) (*eth.BuilderBidElectra, e if bb.ExecutionRequests == nil { return nil, errors.New("bid contains nil execution requests") } - executionRequests, err := bb.ExecutionRequests.ToProto() + executionRequests, err := bb.ExecutionRequests.ToConsensus() if err != nil { return nil, errors.Wrap(err, "failed to convert ExecutionRequests") } @@ -1331,150 +569,13 @@ func (bb *BuilderBidElectra) ToProto(slot types.Slot) (*eth.BuilderBidElectra, e }, nil } -// ExecutionRequestsV1 is a wrapper for different execution requests -type ExecutionRequestsV1 struct { - Deposits []*DepositRequestV1 `json:"deposits"` - Withdrawals []*WithdrawalRequestV1 `json:"withdrawals"` - Consolidations []*ConsolidationRequestV1 `json:"consolidations"` -} - -func (er *ExecutionRequestsV1) ToProto() (*v1.ExecutionRequests, error) { - if uint64(len(er.Deposits)) > params.BeaconConfig().MaxDepositRequestsPerPayload { - return nil, fmt.Errorf("deposit requests count %d exceeds the maximum %d", len(er.Deposits), params.BeaconConfig().MaxDepositRequestsPerPayload) - } - deposits := make([]*v1.DepositRequest, len(er.Deposits)) - for i, dep := range er.Deposits { - d, err := dep.ToProto() - if err != nil { - return nil, err - } - deposits[i] = d - } - if uint64(len(er.Withdrawals)) > params.BeaconConfig().MaxWithdrawalRequestsPerPayload { - return nil, fmt.Errorf("withdrawal requests count %d exceeds the maximum %d", len(er.Withdrawals), params.BeaconConfig().MaxWithdrawalRequestsPerPayload) - } - withdrawals := make([]*v1.WithdrawalRequest, len(er.Withdrawals)) - for i, wr := range er.Withdrawals { - w, err := wr.ToProto() - if err != nil { - return nil, err - } - withdrawals[i] = w - } - if uint64(len(er.Consolidations)) > params.BeaconConfig().MaxConsolidationsRequestsPerPayload { - return nil, fmt.Errorf("consolidation requests count %d exceeds the maximum %d", len(er.Consolidations), params.BeaconConfig().MaxConsolidationsRequestsPerPayload) - } - consolidations := make([]*v1.ConsolidationRequest, len(er.Consolidations)) - for i, con := range er.Consolidations { - c, err := con.ToProto() - if err != nil { - return nil, err - } - consolidations[i] = c - } - return &v1.ExecutionRequests{ - Deposits: deposits, - Withdrawals: withdrawals, - Consolidations: consolidations, - }, nil -} - // BuilderBidElectra is a field of ExecHeaderResponseElectra. type BuilderBidElectra struct { - Header *ExecutionPayloadHeaderDeneb `json:"header"` - BlobKzgCommitments []hexutil.Bytes `json:"blob_kzg_commitments"` - ExecutionRequests *ExecutionRequestsV1 `json:"execution_requests"` - Value Uint256 `json:"value"` - Pubkey hexutil.Bytes `json:"pubkey"` -} - -// WithdrawalRequestV1 is a field of ExecutionRequestsV1. -type WithdrawalRequestV1 struct { - SourceAddress hexutil.Bytes `json:"source_address"` - ValidatorPubkey hexutil.Bytes `json:"validator_pubkey"` - Amount Uint256 `json:"amount"` -} - -func (wr *WithdrawalRequestV1) ToProto() (*v1.WithdrawalRequest, error) { - srcAddress, err := bytesutil.DecodeHexWithLength(wr.SourceAddress.String(), common.AddressLength) - if err != nil { - return nil, server.NewDecodeError(err, "source_address") - } - pubkey, err := bytesutil.DecodeHexWithLength(wr.ValidatorPubkey.String(), fieldparams.BLSPubkeyLength) - if err != nil { - return nil, server.NewDecodeError(err, "validator_pubkey") - } - - return &v1.WithdrawalRequest{ - SourceAddress: srcAddress, - ValidatorPubkey: pubkey, - Amount: wr.Amount.Uint64(), - }, nil -} - -// DepositRequestV1 is a field of ExecutionRequestsV1. -type DepositRequestV1 struct { - PubKey hexutil.Bytes `json:"pubkey"` - // withdrawalCredentials: DATA, 32 Bytes - WithdrawalCredentials hexutil.Bytes `json:"withdrawal_credentials"` - // amount: QUANTITY, 64 Bits - Amount Uint256 `json:"amount"` - // signature: DATA, 96 Bytes - Signature hexutil.Bytes `json:"signature"` - // index: QUANTITY, 64 Bits - Index Uint256 `json:"index"` -} - -func (dr *DepositRequestV1) ToProto() (*v1.DepositRequest, error) { - pubkey, err := bytesutil.DecodeHexWithLength(dr.PubKey.String(), fieldparams.BLSPubkeyLength) - if err != nil { - return nil, server.NewDecodeError(err, "pubkey") - } - wc, err := bytesutil.DecodeHexWithLength(dr.WithdrawalCredentials.String(), fieldparams.RootLength) - if err != nil { - return nil, server.NewDecodeError(err, "withdrawal_credentials") - } - sig, err := bytesutil.DecodeHexWithLength(dr.Signature.String(), fieldparams.BLSSignatureLength) - if err != nil { - return nil, server.NewDecodeError(err, "signature") - } - return &v1.DepositRequest{ - Pubkey: pubkey, - WithdrawalCredentials: wc, - Amount: dr.Amount.Uint64(), - Signature: sig, - Index: dr.Index.Uint64(), - }, nil -} - -// ConsolidationRequestV1 is a field of ExecutionRequestsV1. -type ConsolidationRequestV1 struct { - // sourceAddress: DATA, 20 Bytes - SourceAddress hexutil.Bytes `json:"source_address"` - // sourcePubkey: DATA, 48 Bytes - SourcePubkey hexutil.Bytes `json:"source_pubkey"` - // targetPubkey: DATA, 48 Bytes - TargetPubkey hexutil.Bytes `json:"target_pubkey"` -} - -func (cr *ConsolidationRequestV1) ToProto() (*v1.ConsolidationRequest, error) { - srcAddress, err := bytesutil.DecodeHexWithLength(cr.SourceAddress.String(), common.AddressLength) - if err != nil { - return nil, server.NewDecodeError(err, "source_address") - } - sourcePubkey, err := bytesutil.DecodeHexWithLength(cr.SourcePubkey.String(), fieldparams.BLSPubkeyLength) - if err != nil { - return nil, server.NewDecodeError(err, "source_pubkey") - } - targetPubkey, err := bytesutil.DecodeHexWithLength(cr.TargetPubkey.String(), fieldparams.BLSPubkeyLength) - if err != nil { - return nil, server.NewDecodeError(err, "target_pubkey") - } - return &v1.ConsolidationRequest{ - SourceAddress: srcAddress, - SourcePubkey: sourcePubkey, - TargetPubkey: targetPubkey, - }, nil + Header *structs.ExecutionPayloadHeaderDeneb `json:"header"` + BlobKzgCommitments []hexutil.Bytes `json:"blob_kzg_commitments"` + ExecutionRequests *structs.ExecutionRequests `json:"execution_requests"` + Value Uint256 `json:"value"` + Pubkey hexutil.Bytes `json:"pubkey"` } // ErrorMessage is a JSON representation of the builder API's returned error message. diff --git a/api/client/builder/types_test.go b/api/client/builder/types_test.go index 16c5898474..ace6ee0999 100644 --- a/api/client/builder/types_test.go +++ b/api/client/builder/types_test.go @@ -328,72 +328,72 @@ func TestExecutionHeaderResponseUnmarshal(t *testing.T) { }, { expected: "0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2", - actual: hexutil.Encode(hr.Data.Message.Header.ParentHash), + actual: hr.Data.Message.Header.ParentHash, name: "ExecHeaderResponse.ExecutionPayloadHeader.ParentHash", }, { expected: "0xabcf8e0d4e9587369b2301d0790347320302cc09", - actual: hexutil.Encode(hr.Data.Message.Header.FeeRecipient), + actual: hr.Data.Message.Header.FeeRecipient, name: "ExecHeaderResponse.ExecutionPayloadHeader.FeeRecipient", }, { expected: "0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2", - actual: hexutil.Encode(hr.Data.Message.Header.StateRoot), + actual: hr.Data.Message.Header.StateRoot, name: "ExecHeaderResponse.ExecutionPayloadHeader.StateRoot", }, { expected: "0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2", - actual: hexutil.Encode(hr.Data.Message.Header.ReceiptsRoot), + actual: hr.Data.Message.Header.ReceiptsRoot, name: "ExecHeaderResponse.ExecutionPayloadHeader.ReceiptsRoot", }, { expected: "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - actual: hexutil.Encode(hr.Data.Message.Header.LogsBloom), + actual: hr.Data.Message.Header.LogsBloom, name: "ExecHeaderResponse.ExecutionPayloadHeader.LogsBloom", }, { expected: "0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2", - actual: hexutil.Encode(hr.Data.Message.Header.PrevRandao), + actual: hr.Data.Message.Header.PrevRandao, name: "ExecHeaderResponse.ExecutionPayloadHeader.PrevRandao", }, { expected: "1", - actual: fmt.Sprintf("%d", hr.Data.Message.Header.BlockNumber), + actual: hr.Data.Message.Header.BlockNumber, name: "ExecHeaderResponse.ExecutionPayloadHeader.BlockNumber", }, { expected: "1", - actual: fmt.Sprintf("%d", hr.Data.Message.Header.GasLimit), + actual: hr.Data.Message.Header.GasLimit, name: "ExecHeaderResponse.ExecutionPayloadHeader.GasLimit", }, { expected: "1", - actual: fmt.Sprintf("%d", hr.Data.Message.Header.GasUsed), + actual: hr.Data.Message.Header.GasUsed, name: "ExecHeaderResponse.ExecutionPayloadHeader.GasUsed", }, { expected: "1", - actual: fmt.Sprintf("%d", hr.Data.Message.Header.Timestamp), + actual: hr.Data.Message.Header.Timestamp, name: "ExecHeaderResponse.ExecutionPayloadHeader.Timestamp", }, { expected: "0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2", - actual: hexutil.Encode(hr.Data.Message.Header.ExtraData), + actual: hr.Data.Message.Header.ExtraData, name: "ExecHeaderResponse.ExecutionPayloadHeader.ExtraData", }, { expected: "452312848583266388373324160190187140051835877600158453279131187530910662656", - actual: fmt.Sprintf("%d", hr.Data.Message.Header.BaseFeePerGas), + actual: hr.Data.Message.Header.BaseFeePerGas, name: "ExecHeaderResponse.ExecutionPayloadHeader.BaseFeePerGas", }, { expected: "0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2", - actual: hexutil.Encode(hr.Data.Message.Header.BlockHash), + actual: hr.Data.Message.Header.BlockHash, name: "ExecHeaderResponse.ExecutionPayloadHeader.BlockHash", }, { expected: "0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2", - actual: hexutil.Encode(hr.Data.Message.Header.TransactionsRoot), + actual: hr.Data.Message.Header.TransactionsRoot, name: "ExecHeaderResponse.ExecutionPayloadHeader.TransactionsRoot", }, } @@ -427,77 +427,77 @@ func TestExecutionHeaderResponseCapellaUnmarshal(t *testing.T) { }, { expected: "0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2", - actual: hexutil.Encode(hr.Data.Message.Header.ParentHash), + actual: hr.Data.Message.Header.ParentHash, name: "ExecHeaderResponse.ExecutionPayloadHeader.ParentHash", }, { expected: "0xabcf8e0d4e9587369b2301d0790347320302cc09", - actual: hexutil.Encode(hr.Data.Message.Header.FeeRecipient), + actual: hr.Data.Message.Header.FeeRecipient, name: "ExecHeaderResponse.ExecutionPayloadHeader.FeeRecipient", }, { expected: "0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2", - actual: hexutil.Encode(hr.Data.Message.Header.StateRoot), + actual: hr.Data.Message.Header.StateRoot, name: "ExecHeaderResponse.ExecutionPayloadHeader.StateRoot", }, { expected: "0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2", - actual: hexutil.Encode(hr.Data.Message.Header.ReceiptsRoot), + actual: hr.Data.Message.Header.ReceiptsRoot, name: "ExecHeaderResponse.ExecutionPayloadHeader.ReceiptsRoot", }, { expected: "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - actual: hexutil.Encode(hr.Data.Message.Header.LogsBloom), + actual: hr.Data.Message.Header.LogsBloom, name: "ExecHeaderResponse.ExecutionPayloadHeader.LogsBloom", }, { expected: "0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2", - actual: hexutil.Encode(hr.Data.Message.Header.PrevRandao), + actual: hr.Data.Message.Header.PrevRandao, name: "ExecHeaderResponse.ExecutionPayloadHeader.PrevRandao", }, { expected: "1", - actual: fmt.Sprintf("%d", hr.Data.Message.Header.BlockNumber), + actual: hr.Data.Message.Header.BlockNumber, name: "ExecHeaderResponse.ExecutionPayloadHeader.BlockNumber", }, { expected: "1", - actual: fmt.Sprintf("%d", hr.Data.Message.Header.GasLimit), + actual: hr.Data.Message.Header.GasLimit, name: "ExecHeaderResponse.ExecutionPayloadHeader.GasLimit", }, { expected: "1", - actual: fmt.Sprintf("%d", hr.Data.Message.Header.GasUsed), + actual: hr.Data.Message.Header.GasUsed, name: "ExecHeaderResponse.ExecutionPayloadHeader.GasUsed", }, { expected: "1", - actual: fmt.Sprintf("%d", hr.Data.Message.Header.Timestamp), + actual: hr.Data.Message.Header.Timestamp, name: "ExecHeaderResponse.ExecutionPayloadHeader.Timestamp", }, { expected: "0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2", - actual: hexutil.Encode(hr.Data.Message.Header.ExtraData), + actual: hr.Data.Message.Header.ExtraData, name: "ExecHeaderResponse.ExecutionPayloadHeader.ExtraData", }, { expected: "452312848583266388373324160190187140051835877600158453279131187530910662656", - actual: fmt.Sprintf("%d", hr.Data.Message.Header.BaseFeePerGas), + actual: hr.Data.Message.Header.BaseFeePerGas, name: "ExecHeaderResponse.ExecutionPayloadHeader.BaseFeePerGas", }, { expected: "0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2", - actual: hexutil.Encode(hr.Data.Message.Header.BlockHash), + actual: hr.Data.Message.Header.BlockHash, name: "ExecHeaderResponse.ExecutionPayloadHeader.BlockHash", }, { expected: "0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2", - actual: hexutil.Encode(hr.Data.Message.Header.TransactionsRoot), + actual: hr.Data.Message.Header.TransactionsRoot, name: "ExecHeaderResponse.ExecutionPayloadHeader.TransactionsRoot", }, { expected: "0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2", - actual: hexutil.Encode(hr.Data.Message.Header.WithdrawalsRoot), + actual: hr.Data.Message.Header.WithdrawalsRoot, name: "ExecHeaderResponse.ExecutionPayloadHeader.WithdrawalsRoot", }, } @@ -867,88 +867,6 @@ var testExampleExecutionPayloadDenebDifferentProofCount = fmt.Sprintf(`{ } }`, hexutil.Encode(make([]byte, fieldparams.BlobLength))) -func TestExecutionPayloadResponseUnmarshal(t *testing.T) { - epr := &ExecPayloadResponse{} - require.NoError(t, json.Unmarshal([]byte(testExampleExecutionPayload), epr)) - cases := []struct { - expected string - actual string - name string - }{ - { - expected: "0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2", - actual: hexutil.Encode(epr.Data.ParentHash), - name: "ExecPayloadResponse.ExecutionPayload.ParentHash", - }, - { - expected: "0xabcf8e0d4e9587369b2301d0790347320302cc09", - actual: hexutil.Encode(epr.Data.FeeRecipient), - name: "ExecPayloadResponse.ExecutionPayload.FeeRecipient", - }, - { - expected: "0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2", - actual: hexutil.Encode(epr.Data.StateRoot), - name: "ExecPayloadResponse.ExecutionPayload.StateRoot", - }, - { - expected: "0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2", - actual: hexutil.Encode(epr.Data.ReceiptsRoot), - name: "ExecPayloadResponse.ExecutionPayload.ReceiptsRoot", - }, - { - expected: "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - actual: hexutil.Encode(epr.Data.LogsBloom), - name: "ExecPayloadResponse.ExecutionPayload.LogsBloom", - }, - { - expected: "0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2", - actual: hexutil.Encode(epr.Data.PrevRandao), - name: "ExecPayloadResponse.ExecutionPayload.PrevRandao", - }, - { - expected: "1", - actual: fmt.Sprintf("%d", epr.Data.BlockNumber), - name: "ExecPayloadResponse.ExecutionPayload.BlockNumber", - }, - { - expected: "1", - actual: fmt.Sprintf("%d", epr.Data.GasLimit), - name: "ExecPayloadResponse.ExecutionPayload.GasLimit", - }, - { - expected: "1", - actual: fmt.Sprintf("%d", epr.Data.GasUsed), - name: "ExecPayloadResponse.ExecutionPayload.GasUsed", - }, - { - expected: "1", - actual: fmt.Sprintf("%d", epr.Data.Timestamp), - name: "ExecPayloadResponse.ExecutionPayload.Timestamp", - }, - { - expected: "0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2", - actual: hexutil.Encode(epr.Data.ExtraData), - name: "ExecPayloadResponse.ExecutionPayload.ExtraData", - }, - { - expected: "452312848583266388373324160190187140051835877600158453279131187530910662656", - actual: fmt.Sprintf("%d", epr.Data.BaseFeePerGas), - name: "ExecPayloadResponse.ExecutionPayload.BaseFeePerGas", - }, - { - expected: "0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2", - actual: hexutil.Encode(epr.Data.BlockHash), - name: "ExecPayloadResponse.ExecutionPayload.BlockHash", - }, - } - for _, c := range cases { - require.Equal(t, c.expected, c.actual, fmt.Sprintf("unexpected value for field %s", c.name)) - } - require.Equal(t, 1, len(epr.Data.Transactions)) - txHash := "0x02f878831469668303f51d843b9ac9f9843b9aca0082520894c93269b73096998db66be0441e836d873535cb9c8894a19041886f000080c001a031cc29234036afbf9a1fb9476b463367cb1f957ac0b919b69bbc798436e604aaa018c4e9c3914eb27aadd0b91e10b18655739fcf8c1fc398763a9f1beecb8ddc86" - require.Equal(t, txHash, hexutil.Encode(epr.Data.Transactions[0])) -} - func TestExecutionPayloadResponseCapellaUnmarshal(t *testing.T) { epr := &ExecPayloadResponseCapella{} require.NoError(t, json.Unmarshal([]byte(testExampleExecutionPayloadCapella), epr)) @@ -959,67 +877,67 @@ func TestExecutionPayloadResponseCapellaUnmarshal(t *testing.T) { }{ { expected: "0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2", - actual: hexutil.Encode(epr.Data.ParentHash), + actual: epr.Data.ParentHash, name: "ExecPayloadResponse.ExecutionPayload.ParentHash", }, { expected: "0xabcf8e0d4e9587369b2301d0790347320302cc09", - actual: hexutil.Encode(epr.Data.FeeRecipient), + actual: epr.Data.FeeRecipient, name: "ExecPayloadResponse.ExecutionPayload.FeeRecipient", }, { expected: "0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2", - actual: hexutil.Encode(epr.Data.StateRoot), + actual: epr.Data.StateRoot, name: "ExecPayloadResponse.ExecutionPayload.StateRoot", }, { expected: "0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2", - actual: hexutil.Encode(epr.Data.ReceiptsRoot), + actual: epr.Data.ReceiptsRoot, name: "ExecPayloadResponse.ExecutionPayload.ReceiptsRoot", }, { expected: "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - actual: hexutil.Encode(epr.Data.LogsBloom), + actual: epr.Data.LogsBloom, name: "ExecPayloadResponse.ExecutionPayload.LogsBloom", }, { expected: "0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2", - actual: hexutil.Encode(epr.Data.PrevRandao), + actual: epr.Data.PrevRandao, name: "ExecPayloadResponse.ExecutionPayload.PrevRandao", }, { expected: "1", - actual: fmt.Sprintf("%d", epr.Data.BlockNumber), + actual: epr.Data.BlockNumber, name: "ExecPayloadResponse.ExecutionPayload.BlockNumber", }, { expected: "1", - actual: fmt.Sprintf("%d", epr.Data.GasLimit), + actual: epr.Data.GasLimit, name: "ExecPayloadResponse.ExecutionPayload.GasLimit", }, { expected: "1", - actual: fmt.Sprintf("%d", epr.Data.GasUsed), + actual: epr.Data.GasUsed, name: "ExecPayloadResponse.ExecutionPayload.GasUsed", }, { expected: "1", - actual: fmt.Sprintf("%d", epr.Data.Timestamp), + actual: epr.Data.Timestamp, name: "ExecPayloadResponse.ExecutionPayload.Timestamp", }, { expected: "0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2", - actual: hexutil.Encode(epr.Data.ExtraData), + actual: epr.Data.ExtraData, name: "ExecPayloadResponse.ExecutionPayload.ExtraData", }, { expected: "452312848583266388373324160190187140051835877600158453279131187530910662656", - actual: fmt.Sprintf("%d", epr.Data.BaseFeePerGas), + actual: epr.Data.BaseFeePerGas, name: "ExecPayloadResponse.ExecutionPayload.BaseFeePerGas", }, { expected: "0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2", - actual: hexutil.Encode(epr.Data.BlockHash), + actual: epr.Data.BlockHash, name: "ExecPayloadResponse.ExecutionPayload.BlockHash", }, } @@ -1028,14 +946,14 @@ func TestExecutionPayloadResponseCapellaUnmarshal(t *testing.T) { } require.Equal(t, 1, len(epr.Data.Transactions)) txHash := "0x02f878831469668303f51d843b9ac9f9843b9aca0082520894c93269b73096998db66be0441e836d873535cb9c8894a19041886f000080c001a031cc29234036afbf9a1fb9476b463367cb1f957ac0b919b69bbc798436e604aaa018c4e9c3914eb27aadd0b91e10b18655739fcf8c1fc398763a9f1beecb8ddc86" - require.Equal(t, txHash, hexutil.Encode(epr.Data.Transactions[0])) + require.Equal(t, txHash, epr.Data.Transactions[0]) require.Equal(t, 1, len(epr.Data.Withdrawals)) w := epr.Data.Withdrawals[0] - assert.Equal(t, uint64(1), w.Index.Uint64()) - assert.Equal(t, uint64(1), w.ValidatorIndex.Uint64()) - assert.DeepEqual(t, "0xcf8e0d4e9587369b2301d0790347320302cc0943", w.Address.String()) - assert.Equal(t, uint64(1), w.Amount.Uint64()) + assert.Equal(t, "1", w.WithdrawalIndex) + assert.Equal(t, "1", w.ValidatorIndex) + assert.DeepEqual(t, "0xcf8e0d4e9587369b2301d0790347320302cc0943", w.ExecutionAddress) + assert.Equal(t, "1", w.Amount) } func TestExecutionPayloadResponseDenebUnmarshal(t *testing.T) { @@ -1048,77 +966,77 @@ func TestExecutionPayloadResponseDenebUnmarshal(t *testing.T) { }{ { expected: "0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2", - actual: hexutil.Encode(epr.Data.ExecutionPayload.ParentHash), + actual: epr.Data.ExecutionPayload.ParentHash, name: "ExecPayloadResponse.ExecutionPayload.ParentHash", }, { expected: "0xabcf8e0d4e9587369b2301d0790347320302cc09", - actual: hexutil.Encode(epr.Data.ExecutionPayload.FeeRecipient), + actual: epr.Data.ExecutionPayload.FeeRecipient, name: "ExecPayloadResponse.ExecutionPayload.FeeRecipient", }, { expected: "0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2", - actual: hexutil.Encode(epr.Data.ExecutionPayload.StateRoot), + actual: epr.Data.ExecutionPayload.StateRoot, name: "ExecPayloadResponse.ExecutionPayload.StateRoot", }, { expected: "0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2", - actual: hexutil.Encode(epr.Data.ExecutionPayload.ReceiptsRoot), + actual: epr.Data.ExecutionPayload.ReceiptsRoot, name: "ExecPayloadResponse.ExecutionPayload.ReceiptsRoot", }, { expected: "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - actual: hexutil.Encode(epr.Data.ExecutionPayload.LogsBloom), + actual: epr.Data.ExecutionPayload.LogsBloom, name: "ExecPayloadResponse.ExecutionPayload.LogsBloom", }, { expected: "0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2", - actual: hexutil.Encode(epr.Data.ExecutionPayload.PrevRandao), + actual: epr.Data.ExecutionPayload.PrevRandao, name: "ExecPayloadResponse.ExecutionPayload.PrevRandao", }, { expected: "1", - actual: fmt.Sprintf("%d", epr.Data.ExecutionPayload.BlockNumber), + actual: epr.Data.ExecutionPayload.BlockNumber, name: "ExecPayloadResponse.ExecutionPayload.BlockNumber", }, { expected: "1", - actual: fmt.Sprintf("%d", epr.Data.ExecutionPayload.GasLimit), + actual: epr.Data.ExecutionPayload.GasLimit, name: "ExecPayloadResponse.ExecutionPayload.GasLimit", }, { expected: "1", - actual: fmt.Sprintf("%d", epr.Data.ExecutionPayload.GasUsed), + actual: epr.Data.ExecutionPayload.GasUsed, name: "ExecPayloadResponse.ExecutionPayload.GasUsed", }, { expected: "1", - actual: fmt.Sprintf("%d", epr.Data.ExecutionPayload.Timestamp), + actual: epr.Data.ExecutionPayload.Timestamp, name: "ExecPayloadResponse.ExecutionPayload.Timestamp", }, { expected: "0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2", - actual: hexutil.Encode(epr.Data.ExecutionPayload.ExtraData), + actual: epr.Data.ExecutionPayload.ExtraData, name: "ExecPayloadResponse.ExecutionPayload.ExtraData", }, { expected: "452312848583266388373324160190187140051835877600158453279131187530910662656", - actual: fmt.Sprintf("%d", epr.Data.ExecutionPayload.BaseFeePerGas), + actual: epr.Data.ExecutionPayload.BaseFeePerGas, name: "ExecPayloadResponse.ExecutionPayload.BaseFeePerGas", }, { expected: "0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2", - actual: hexutil.Encode(epr.Data.ExecutionPayload.BlockHash), + actual: epr.Data.ExecutionPayload.BlockHash, name: "ExecPayloadResponse.ExecutionPayload.BlockHash", }, { expected: "2", - actual: fmt.Sprintf("%d", epr.Data.ExecutionPayload.BlobGasUsed), + actual: epr.Data.ExecutionPayload.BlobGasUsed, name: "ExecPayloadResponse.ExecutionPayload.BlobGasUsed", }, { expected: "3", - actual: fmt.Sprintf("%d", epr.Data.ExecutionPayload.ExcessBlobGas), + actual: epr.Data.ExecutionPayload.ExcessBlobGas, name: "ExecPayloadResponse.ExecutionPayload.ExcessBlobGas", }, } @@ -1127,64 +1045,16 @@ func TestExecutionPayloadResponseDenebUnmarshal(t *testing.T) { } require.Equal(t, 1, len(epr.Data.ExecutionPayload.Transactions)) txHash := "0x02f878831469668303f51d843b9ac9f9843b9aca0082520894c93269b73096998db66be0441e836d873535cb9c8894a19041886f000080c001a031cc29234036afbf9a1fb9476b463367cb1f957ac0b919b69bbc798436e604aaa018c4e9c3914eb27aadd0b91e10b18655739fcf8c1fc398763a9f1beecb8ddc86" - require.Equal(t, txHash, hexutil.Encode(epr.Data.ExecutionPayload.Transactions[0])) + require.Equal(t, txHash, epr.Data.ExecutionPayload.Transactions[0]) require.Equal(t, 1, len(epr.Data.ExecutionPayload.Withdrawals)) w := epr.Data.ExecutionPayload.Withdrawals[0] - assert.Equal(t, uint64(1), w.Index.Uint64()) - assert.Equal(t, uint64(1), w.ValidatorIndex.Uint64()) - assert.DeepEqual(t, "0xcf8e0d4e9587369b2301d0790347320302cc0943", w.Address.String()) - assert.Equal(t, uint64(1), w.Amount.Uint64()) - assert.Equal(t, uint64(2), uint64(epr.Data.ExecutionPayload.BlobGasUsed)) - assert.Equal(t, uint64(3), uint64(epr.Data.ExecutionPayload.ExcessBlobGas)) -} - -func TestExecutionPayloadResponseToProto(t *testing.T) { - hr := &ExecPayloadResponse{} - require.NoError(t, json.Unmarshal([]byte(testExampleExecutionPayload), hr)) - p, err := hr.ToProto() - require.NoError(t, err) - - parentHash, err := hexutil.Decode("0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2") - require.NoError(t, err) - feeRecipient, err := hexutil.Decode("0xabcf8e0d4e9587369b2301d0790347320302cc09") - require.NoError(t, err) - stateRoot, err := hexutil.Decode("0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2") - require.NoError(t, err) - receiptsRoot, err := hexutil.Decode("0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2") - require.NoError(t, err) - logsBloom, err := hexutil.Decode("0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000") - require.NoError(t, err) - prevRandao, err := hexutil.Decode("0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2") - require.NoError(t, err) - extraData, err := hexutil.Decode("0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2") - require.NoError(t, err) - blockHash, err := hexutil.Decode("0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2") - require.NoError(t, err) - - tx, err := hexutil.Decode("0x02f878831469668303f51d843b9ac9f9843b9aca0082520894c93269b73096998db66be0441e836d873535cb9c8894a19041886f000080c001a031cc29234036afbf9a1fb9476b463367cb1f957ac0b919b69bbc798436e604aaa018c4e9c3914eb27aadd0b91e10b18655739fcf8c1fc398763a9f1beecb8ddc86") - require.NoError(t, err) - txList := [][]byte{tx} - - bfpg, err := stringToUint256("452312848583266388373324160190187140051835877600158453279131187530910662656") - require.NoError(t, err) - expected := &v1.ExecutionPayload{ - ParentHash: parentHash, - FeeRecipient: feeRecipient, - StateRoot: stateRoot, - ReceiptsRoot: receiptsRoot, - LogsBloom: logsBloom, - PrevRandao: prevRandao, - BlockNumber: 1, - GasLimit: 1, - GasUsed: 1, - Timestamp: 1, - ExtraData: extraData, - BaseFeePerGas: bfpg.SSZBytes(), - BlockHash: blockHash, - Transactions: txList, - } - require.DeepEqual(t, expected, p) + assert.Equal(t, "1", w.WithdrawalIndex) + assert.Equal(t, "1", w.ValidatorIndex) + assert.DeepEqual(t, "0xcf8e0d4e9587369b2301d0790347320302cc0943", w.ExecutionAddress) + assert.Equal(t, "1", w.Amount) + assert.Equal(t, "2", epr.Data.ExecutionPayload.BlobGasUsed) + assert.Equal(t, "3", epr.Data.ExecutionPayload.ExcessBlobGas) } func TestExecutionPayloadResponseCapellaToProto(t *testing.T) { @@ -1352,16 +1222,6 @@ func pbEth1Data() *eth.Eth1Data { } } -func TestEth1DataMarshal(t *testing.T) { - ed := &Eth1Data{ - Eth1Data: pbEth1Data(), - } - b, err := json.Marshal(ed) - require.NoError(t, err) - expected := `{"deposit_root":"0x0000000000000000000000000000000000000000000000000000000000000000","deposit_count":"23","block_hash":"0x0000000000000000000000000000000000000000000000000000000000000000"}` - require.Equal(t, expected, string(b)) -} - func pbSyncAggregate() *eth.SyncAggregate { return ð.SyncAggregate{ SyncCommitteeSignature: make([]byte, 48), @@ -1369,14 +1229,6 @@ func pbSyncAggregate() *eth.SyncAggregate { } } -func TestSyncAggregate_MarshalJSON(t *testing.T) { - sa := &SyncAggregate{pbSyncAggregate()} - b, err := json.Marshal(sa) - require.NoError(t, err) - expected := `{"sync_committee_bits":"0x01","sync_committee_signature":"0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"}` - require.Equal(t, expected, string(b)) -} - func pbDeposit(t *testing.T) *eth.Deposit { return ð.Deposit{ Proof: [][]byte{ezDecode(t, "0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2")}, @@ -1389,16 +1241,6 @@ func pbDeposit(t *testing.T) *eth.Deposit { } } -func TestDeposit_MarshalJSON(t *testing.T) { - d := &Deposit{ - Deposit: pbDeposit(t), - } - b, err := json.Marshal(d) - require.NoError(t, err) - expected := `{"proof":["0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2"],"data":{"pubkey":"0x93247f2209abcacf57b75a51dafae777f9dd38bc7053d1af526f220a7489a6d3a2753e5f3e8b1cfe39b56f43611df74a","withdrawal_credentials":"0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2","amount":"1","signature":"0x1b66ac1fb663c9bc59509846d6ec05345bd908eda73e670af888da41af171505cc411d61252fb6cb3fa0017b679f8bb2305b26a285fa2737f175668d0dff91cc1b66ac1fb663c9bc59509846d6ec05345bd908eda73e670af888da41af171505"}}` - require.Equal(t, expected, string(b)) -} - func pbSignedVoluntaryExit(t *testing.T) *eth.SignedVoluntaryExit { return ð.SignedVoluntaryExit{ Exit: ð.VoluntaryExit{ @@ -1409,16 +1251,6 @@ func pbSignedVoluntaryExit(t *testing.T) *eth.SignedVoluntaryExit { } } -func TestVoluntaryExit(t *testing.T) { - ve := &SignedVoluntaryExit{ - SignedVoluntaryExit: pbSignedVoluntaryExit(t), - } - b, err := json.Marshal(ve) - require.NoError(t, err) - expected := `{"message":{"epoch":"1","validator_index":"1"},"signature":"0x1b66ac1fb663c9bc59509846d6ec05345bd908eda73e670af888da41af171505cc411d61252fb6cb3fa0017b679f8bb2305b26a285fa2737f175668d0dff91cc1b66ac1fb663c9bc59509846d6ec05345bd908eda73e670af888da41af171505"}` - require.Equal(t, expected, string(b)) -} - func pbAttestation(t *testing.T) *eth.Attestation { return ð.Attestation{ AggregationBits: bitfield.Bitlist{0x01}, @@ -1439,16 +1271,6 @@ func pbAttestation(t *testing.T) *eth.Attestation { } } -func TestAttestationMarshal(t *testing.T) { - a := &Attestation{ - Attestation: pbAttestation(t), - } - b, err := json.Marshal(a) - require.NoError(t, err) - expected := `{"aggregation_bits":"0x01","data":{"slot":"1","index":"1","beacon_block_root":"0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2","source":{"epoch":"1","root":"0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2"},"target":{"epoch":"1","root":"0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2"}},"signature":"0x1b66ac1fb663c9bc59509846d6ec05345bd908eda73e670af888da41af171505cc411d61252fb6cb3fa0017b679f8bb2305b26a285fa2737f175668d0dff91cc1b66ac1fb663c9bc59509846d6ec05345bd908eda73e670af888da41af171505"}` - require.Equal(t, expected, string(b)) -} - func pbAttesterSlashing(t *testing.T) *eth.AttesterSlashing { return ð.AttesterSlashing{ Attestation_1: ð.IndexedAttestation{ @@ -1489,9 +1311,7 @@ func pbAttesterSlashing(t *testing.T) *eth.AttesterSlashing { } func TestAttesterSlashing_MarshalJSON(t *testing.T) { - as := &AttesterSlashing{ - AttesterSlashing: pbAttesterSlashing(t), - } + as := structs.AttesterSlashingFromConsensus(pbAttesterSlashing(t)) b, err := json.Marshal(as) require.NoError(t, err) expected := `{"attestation_1":{"attesting_indices":["1"],"data":{"slot":"1","index":"1","beacon_block_root":"0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2","source":{"epoch":"1","root":"0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2"},"target":{"epoch":"1","root":"0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2"}},"signature":"0x1b66ac1fb663c9bc59509846d6ec05345bd908eda73e670af888da41af171505cc411d61252fb6cb3fa0017b679f8bb2305b26a285fa2737f175668d0dff91cc1b66ac1fb663c9bc59509846d6ec05345bd908eda73e670af888da41af171505"},"attestation_2":{"attesting_indices":["1"],"data":{"slot":"1","index":"1","beacon_block_root":"0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2","source":{"epoch":"1","root":"0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2"},"target":{"epoch":"1","root":"0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2"}},"signature":"0x1b66ac1fb663c9bc59509846d6ec05345bd908eda73e670af888da41af171505cc411d61252fb6cb3fa0017b679f8bb2305b26a285fa2737f175668d0dff91cc1b66ac1fb663c9bc59509846d6ec05345bd908eda73e670af888da41af171505"}}` @@ -1599,9 +1419,8 @@ func pbExecutionPayloadHeaderDeneb(t *testing.T) *v1.ExecutionPayloadHeaderDeneb } func TestExecutionPayloadHeader_MarshalJSON(t *testing.T) { - h := &ExecutionPayloadHeader{ - ExecutionPayloadHeader: pbExecutionPayloadHeader(t), - } + h, err := structs.ExecutionPayloadHeaderFromConsensus(pbExecutionPayloadHeader(t)) + require.NoError(t, err) b, err := json.Marshal(h) require.NoError(t, err) expected := `{"parent_hash":"0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2","fee_recipient":"0xabcf8e0d4e9587369b2301d0790347320302cc09","state_root":"0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2","receipts_root":"0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2","logs_bloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","prev_randao":"0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2","block_number":"1","gas_limit":"1","gas_used":"1","timestamp":"1","extra_data":"0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2","base_fee_per_gas":"452312848583266388373324160190187140051835877600158453279131187530910662656","block_hash":"0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2","transactions_root":"0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2"}` @@ -1609,9 +1428,9 @@ func TestExecutionPayloadHeader_MarshalJSON(t *testing.T) { } func TestExecutionPayloadHeaderCapella_MarshalJSON(t *testing.T) { - h := &ExecutionPayloadHeaderCapella{ - ExecutionPayloadHeaderCapella: pbExecutionPayloadHeaderCapella(t), - } + h, err := structs.ExecutionPayloadHeaderCapellaFromConsensus(pbExecutionPayloadHeaderCapella(t)) + require.NoError(t, err) + require.NoError(t, err) b, err := json.Marshal(h) require.NoError(t, err) expected := `{"parent_hash":"0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2","fee_recipient":"0xabcf8e0d4e9587369b2301d0790347320302cc09","state_root":"0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2","receipts_root":"0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2","logs_bloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","prev_randao":"0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2","block_number":"1","gas_limit":"1","gas_used":"1","timestamp":"1","extra_data":"0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2","base_fee_per_gas":"452312848583266388373324160190187140051835877600158453279131187530910662656","block_hash":"0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2","transactions_root":"0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2","withdrawals_root":"0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2"}` @@ -1619,9 +1438,8 @@ func TestExecutionPayloadHeaderCapella_MarshalJSON(t *testing.T) { } func TestExecutionPayloadHeaderDeneb_MarshalJSON(t *testing.T) { - h := &ExecutionPayloadHeaderDeneb{ - ExecutionPayloadHeaderDeneb: pbExecutionPayloadHeaderDeneb(t), - } + h, err := structs.ExecutionPayloadHeaderDenebFromConsensus(pbExecutionPayloadHeaderDeneb(t)) + require.NoError(t, err) b, err := json.Marshal(h) require.NoError(t, err) expected := `{"parent_hash":"0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2","fee_recipient":"0xabcf8e0d4e9587369b2301d0790347320302cc09","state_root":"0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2","receipts_root":"0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2","logs_bloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","prev_randao":"0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2","block_number":"1","gas_limit":"1","gas_used":"1","timestamp":"1","extra_data":"0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2","base_fee_per_gas":"452312848583266388373324160190187140051835877600158453279131187530910662656","block_hash":"0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2","transactions_root":"0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2","withdrawals_root":"0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2","blob_gas_used":"1","excess_blob_gas":"2"}` @@ -1850,12 +1668,13 @@ func TestRoundTripUint256(t *testing.T) { func TestRoundTripProtoUint256(t *testing.T) { h := pbExecutionPayloadHeader(t) h.BaseFeePerGas = []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31} - hm := &ExecutionPayloadHeader{ExecutionPayloadHeader: h} + hm, err := structs.ExecutionPayloadHeaderFromConsensus(h) + require.NoError(t, err) m, err := json.Marshal(hm) require.NoError(t, err) - hu := &ExecutionPayloadHeader{} + hu := &structs.ExecutionPayloadHeader{} require.NoError(t, json.Unmarshal(m, hu)) - hp, err := hu.ToProto() + hp, err := hu.ToConsensus() require.NoError(t, err) require.DeepEqual(t, h.BaseFeePerGas, hp.BaseFeePerGas) } @@ -1863,7 +1682,7 @@ func TestRoundTripProtoUint256(t *testing.T) { func TestExecutionPayloadHeaderRoundtrip(t *testing.T) { expected, err := os.ReadFile("testdata/execution-payload.json") require.NoError(t, err) - hu := &ExecutionPayloadHeader{} + hu := &structs.ExecutionPayloadHeader{} require.NoError(t, json.Unmarshal(expected, hu)) m, err := json.Marshal(hu) require.NoError(t, err) @@ -1873,7 +1692,7 @@ func TestExecutionPayloadHeaderRoundtrip(t *testing.T) { func TestExecutionPayloadHeaderCapellaRoundtrip(t *testing.T) { expected, err := os.ReadFile("testdata/execution-payload-capella.json") require.NoError(t, err) - hu := &ExecutionPayloadHeaderCapella{} + hu := &structs.ExecutionPayloadHeaderCapella{} require.NoError(t, json.Unmarshal(expected, hu)) m, err := json.Marshal(hu) require.NoError(t, err) @@ -1994,11 +1813,9 @@ func TestEmptyResponseBody(t *testing.T) { epr := &ExecutionPayloadResponse{} require.NoError(t, json.Unmarshal(encoded, epr)) pp, err := epr.ParsePayload() - require.NoError(t, err) - pb, err := pp.PayloadProto() if err == nil { require.NoError(t, err) - require.Equal(t, false, pb == nil) + require.Equal(t, false, pp == nil) } else { require.ErrorIs(t, err, consensusblocks.ErrNilObject) } diff --git a/api/server/structs/BUILD.bazel b/api/server/structs/BUILD.bazel index 9367483349..7a33faeba3 100644 --- a/api/server/structs/BUILD.bazel +++ b/api/server/structs/BUILD.bazel @@ -31,6 +31,7 @@ go_library( "//beacon-chain/state:go_default_library", "//config/fieldparams:go_default_library", "//config/params:go_default_library", + "//consensus-types/blocks:go_default_library", "//consensus-types/interfaces:go_default_library", "//consensus-types/primitives:go_default_library", "//consensus-types/validator:go_default_library", @@ -44,6 +45,7 @@ go_library( "@com_github_ethereum_go_ethereum//common:go_default_library", "@com_github_ethereum_go_ethereum//common/hexutil:go_default_library", "@com_github_pkg_errors//:go_default_library", + "@org_golang_google_protobuf//proto:go_default_library", ], ) diff --git a/api/server/structs/conversions_block_execution.go b/api/server/structs/conversions_block_execution.go index 955ac43bd1..f2d5eda820 100644 --- a/api/server/structs/conversions_block_execution.go +++ b/api/server/structs/conversions_block_execution.go @@ -7,12 +7,15 @@ import ( "github.com/OffchainLabs/prysm/v6/api/server" fieldparams "github.com/OffchainLabs/prysm/v6/config/fieldparams" "github.com/OffchainLabs/prysm/v6/config/params" + consensusblocks "github.com/OffchainLabs/prysm/v6/consensus-types/blocks" "github.com/OffchainLabs/prysm/v6/consensus-types/primitives" "github.com/OffchainLabs/prysm/v6/container/slice" "github.com/OffchainLabs/prysm/v6/encoding/bytesutil" enginev1 "github.com/OffchainLabs/prysm/v6/proto/engine/v1" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" + "github.com/pkg/errors" + "google.golang.org/protobuf/proto" ) // ---------------------------------------------------------------------------- @@ -132,6 +135,13 @@ func (e *ExecutionPayload) ToConsensus() (*enginev1.ExecutionPayload, error) { }, nil } +func (r *ExecutionPayload) PayloadProto() (proto.Message, error) { + if r == nil { + return nil, errors.Wrap(consensusblocks.ErrNilObject, "nil execution payload") + } + return r.ToConsensus() +} + func ExecutionPayloadHeaderFromConsensus(payload *enginev1.ExecutionPayloadHeader) (*ExecutionPayloadHeader, error) { baseFeePerGas, err := sszBytesToUint256String(payload.BaseFeePerGas) if err != nil { @@ -383,6 +393,13 @@ func (e *ExecutionPayloadCapella) ToConsensus() (*enginev1.ExecutionPayloadCapel }, nil } +func (p *ExecutionPayloadCapella) PayloadProto() (proto.Message, error) { + if p == nil { + return nil, errors.Wrap(consensusblocks.ErrNilObject, "nil capella execution payload") + } + return p.ToConsensus() +} + func ExecutionPayloadHeaderCapellaFromConsensus(payload *enginev1.ExecutionPayloadHeaderCapella) (*ExecutionPayloadHeaderCapella, error) { baseFeePerGas, err := sszBytesToUint256String(payload.BaseFeePerGas) if err != nil { diff --git a/changelog/james-prysm_merge-payload-types.md b/changelog/james-prysm_merge-payload-types.md new file mode 100644 index 0000000000..1e8e282e1d --- /dev/null +++ b/changelog/james-prysm_merge-payload-types.md @@ -0,0 +1,3 @@ +### Ignored + +- merging the builder execution payload types with the ones defined in structs which should reduce mental load when adding new execution payload types \ No newline at end of file diff --git a/testing/middleware/builder/builder.go b/testing/middleware/builder/builder.go index b439f9105e..402fc79ae7 100644 --- a/testing/middleware/builder/builder.go +++ b/testing/middleware/builder/builder.go @@ -363,7 +363,13 @@ func (p *Builder) handleHeaderRequest(w http.ResponseWriter, req *http.Request) gEth := big.NewInt(int64(params.BeaconConfig().GweiPerEth)) weiEth := gEth.Mul(gEth, gEth) val := builderAPI.Uint256{Int: weiEth} - wrappedHdr := &builderAPI.ExecutionPayloadHeader{ExecutionPayloadHeader: hdr} + + wrappedHdr, err := structs.ExecutionPayloadHeaderFromConsensus(hdr) + if err != nil { + p.cfg.logger.WithError(err).Error("Could not convert wrapped header") + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } bid := &builderAPI.BuilderBid{ Header: wrappedHdr, Value: val, @@ -440,7 +446,12 @@ func (p *Builder) handleHeaderRequestCapella(w http.ResponseWriter) { return } val := builderAPI.Uint256{Int: v} - wrappedHdr := &builderAPI.ExecutionPayloadHeaderCapella{ExecutionPayloadHeaderCapella: hdr} + wrappedHdr, err := structs.ExecutionPayloadHeaderCapellaFromConsensus(hdr) + if err != nil { + p.cfg.logger.WithError(err).Error("Could not make execution payload") + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } bid := &builderAPI.BuilderBidCapella{ Header: wrappedHdr, Value: val, @@ -523,7 +534,12 @@ func (p *Builder) handleHeaderRequestDeneb(w http.ResponseWriter) { copiedC := c commitments = append(commitments, copiedC) } - wrappedHdr := &builderAPI.ExecutionPayloadHeaderDeneb{ExecutionPayloadHeaderDeneb: hdr} + wrappedHdr, err := structs.ExecutionPayloadHeaderDenebFromConsensus(hdr) + if err != nil { + p.cfg.logger.WithError(err).Error("Could not make execution payload") + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } bid := &builderAPI.BuilderBidDeneb{ Header: wrappedHdr, BlobKzgCommitments: commitments, @@ -609,50 +625,19 @@ func (p *Builder) handleHeaderRequestElectra(w http.ResponseWriter) { copiedC := c commitments = append(commitments, copiedC) } - wrappedHdr := &builderAPI.ExecutionPayloadHeaderDeneb{ExecutionPayloadHeaderDeneb: hdr} + wrappedHdr, err := structs.ExecutionPayloadHeaderDenebFromConsensus(hdr) + if err != nil { + p.cfg.logger.WithError(err).Error("Could not make execution payload") + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } requests, err := b.GetDecodedExecutionRequests() if err != nil { p.cfg.logger.WithError(err).Error("Could not get decoded execution requests") http.Error(w, err.Error(), http.StatusInternalServerError) return } - rv1 := &builderAPI.ExecutionRequestsV1{ - Deposits: make([]*builderAPI.DepositRequestV1, len(requests.Deposits)), - Withdrawals: make([]*builderAPI.WithdrawalRequestV1, len(requests.Withdrawals)), - Consolidations: make([]*builderAPI.ConsolidationRequestV1, len(requests.Consolidations)), - } - - for i, d := range requests.Deposits { - amount := new(big.Int).SetUint64(d.Amount) - index := new(big.Int).SetUint64(d.Index) - dr := &builderAPI.DepositRequestV1{ - PubKey: d.Pubkey, - WithdrawalCredentials: d.WithdrawalCredentials, - Amount: builderAPI.Uint256{Int: amount}, - Signature: d.Signature, - Index: builderAPI.Uint256{Int: index}, - } - rv1.Deposits[i] = dr - } - - for i, w := range requests.Withdrawals { - bi := new(big.Int).SetUint64(w.Amount) - wr := &builderAPI.WithdrawalRequestV1{ - SourceAddress: w.SourceAddress, - ValidatorPubkey: w.ValidatorPubkey, - Amount: builderAPI.Uint256{Int: bi}, - } - rv1.Withdrawals[i] = wr - } - - for i, c := range requests.Consolidations { - cr := &builderAPI.ConsolidationRequestV1{ - SourceAddress: c.SourceAddress, - SourcePubkey: c.SourcePubkey, - TargetPubkey: c.TargetPubkey, - } - rv1.Consolidations[i] = cr - } + rv1 := structs.ExecutionRequestsFromConsensus(requests) bid := &builderAPI.BuilderBidElectra{ Header: wrappedHdr, @@ -748,21 +733,21 @@ func ExecutionPayloadResponseFromData(v int, ed interfaces.ExecutionData, bundle ver := version.String(v) switch pbStruct := pb.(type) { case *v1.ExecutionPayloadDeneb: - payloadStruct, err := builderAPI.FromProtoDeneb(pbStruct) + payloadStruct, err := structs.ExecutionPayloadDenebFromConsensus(pbStruct) if err != nil { return nil, errors.Wrap(err, "failed to convert a Deneb ExecutionPayload to an API response") } data = &builderAPI.ExecutionPayloadDenebAndBlobsBundle{ - ExecutionPayload: &payloadStruct, + ExecutionPayload: payloadStruct, BlobsBundle: builderAPI.FromBundleProto(bundle), } case *v1.ExecutionPayloadCapella: - data, err = builderAPI.FromProtoCapella(pbStruct) + data, err = structs.ExecutionPayloadCapellaFromConsensus(pbStruct) if err != nil { return nil, errors.Wrap(err, "failed to convert a Capella ExecutionPayload to an API response") } case *v1.ExecutionPayload: - data, err = builderAPI.FromProto(pbStruct) + data, err = structs.ExecutionPayloadFromConsensus(pbStruct) if err != nil { return nil, errors.Wrap(err, "failed to convert a Bellatrix ExecutionPayload to an API response") }