Skip to content

Commit

Permalink
Add deneb to versioned signed builder bids
Browse files Browse the repository at this point in the history
  • Loading branch information
avalonche committed Jul 31, 2023
1 parent 1c6bea5 commit f7738a5
Show file tree
Hide file tree
Showing 5 changed files with 684 additions and 0 deletions.
29 changes: 29 additions & 0 deletions api/versionedexecutionpayload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ func TestVersionedExecutionPayloadEmpty(t *testing.T) {
}
require.True(t, mismatch2.IsEmpty())

mismatch3 := &api.VersionedExecutionPayload{
Version: consensusspec.DataVersionDeneb,
Capella: &capella.ExecutionPayload{},
}
require.True(t, mismatch3.IsEmpty())

incorrectVersion := &api.VersionedExecutionPayload{
Version: consensusspec.DataVersionDeneb,
Bellatrix: &bellatrix.ExecutionPayload{},
Expand Down Expand Up @@ -223,6 +229,29 @@ func TestVersionedExecutionPayloadTransactions(t *testing.T) {
{0x01},
},
},
{
name: "DenebNoData",
bid: &api.VersionedExecutionPayload{
Version: consensusspec.DataVersionDeneb,
},
err: "no data",
},
{
name: "DenebGood",
bid: &api.VersionedExecutionPayload{
Version: consensusspec.DataVersionDeneb,
Deneb: &deneb.ExecutionPayload{
Transactions: []bellatrix.Transaction{
{0x00},
{0x01},
},
},
},
res: []bellatrix.Transaction{
{0x00},
{0x01},
},
},
}

for _, test := range tests {
Expand Down
121 changes: 121 additions & 0 deletions spec/versionedsignedbuilderbid.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

"github.com/attestantio/go-builder-client/api/bellatrix"
"github.com/attestantio/go-builder-client/api/capella"
"github.com/attestantio/go-builder-client/api/deneb"
consensusspec "github.com/attestantio/go-eth2-client/spec"
consensusbellatrix "github.com/attestantio/go-eth2-client/spec/bellatrix"
"github.com/attestantio/go-eth2-client/spec/phase0"
Expand All @@ -31,6 +32,7 @@ type VersionedSignedBuilderBid struct {
Version consensusspec.DataVersion
Bellatrix *bellatrix.SignedBuilderBid
Capella *capella.SignedBuilderBid
Deneb *deneb.SignedBuilderBid
}

// IsEmpty returns true if there is no bid.
Expand All @@ -40,6 +42,8 @@ func (v *VersionedSignedBuilderBid) IsEmpty() bool {
return v.Bellatrix == nil
case consensusspec.DataVersionCapella:
return v.Capella == nil
case consensusspec.DataVersionDeneb:
return v.Deneb == nil
default:
return true
}
Expand Down Expand Up @@ -67,6 +71,14 @@ func (v *VersionedSignedBuilderBid) Builder() (phase0.BLSPubKey, error) {
return phase0.BLSPubKey{}, errors.New("no data message")
}
return v.Capella.Message.Pubkey, nil
case consensusspec.DataVersionDeneb:
if v.Deneb == nil {
return phase0.BLSPubKey{}, errors.New("no data")
}
if v.Deneb.Message == nil {
return phase0.BLSPubKey{}, errors.New("no data message")
}
return v.Deneb.Message.Pubkey, nil
default:
return phase0.BLSPubKey{}, errors.New("unsupported version")
}
Expand Down Expand Up @@ -94,6 +106,14 @@ func (v *VersionedSignedBuilderBid) Value() (*uint256.Int, error) {
return nil, errors.New("no data message")
}
return v.Capella.Message.Value, nil
case consensusspec.DataVersionDeneb:
if v.Deneb == nil {
return nil, errors.New("no data")
}
if v.Deneb.Message == nil {
return nil, errors.New("no data message")
}
return v.Deneb.Message.Value, nil
default:
return nil, errors.New("unsupported version")
}
Expand Down Expand Up @@ -127,6 +147,17 @@ func (v *VersionedSignedBuilderBid) BlockNumber() (uint64, error) {
return 0, errors.New("no data message header")
}
return v.Capella.Message.Header.BlockNumber, nil
case consensusspec.DataVersionDeneb:
if v.Deneb == nil {
return 0, errors.New("no data")
}
if v.Deneb.Message == nil {
return 0, errors.New("no data message")
}
if v.Deneb.Message.Header == nil {
return 0, errors.New("no data message header")
}
return v.Deneb.Message.Header.BlockNumber, nil
default:
return 0, errors.New("unsupported version")
}
Expand Down Expand Up @@ -160,6 +191,17 @@ func (v *VersionedSignedBuilderBid) BlockHash() (phase0.Hash32, error) {
return phase0.Hash32{}, errors.New("no data message header")
}
return v.Capella.Message.Header.BlockHash, nil
case consensusspec.DataVersionDeneb:
if v.Deneb == nil {
return phase0.Hash32{}, errors.New("no data")
}
if v.Deneb.Message == nil {
return phase0.Hash32{}, errors.New("no data message")
}
if v.Deneb.Message.Header == nil {
return phase0.Hash32{}, errors.New("no data message header")
}
return v.Deneb.Message.Header.BlockHash, nil
default:
return phase0.Hash32{}, errors.New("unsupported version")
}
Expand Down Expand Up @@ -193,6 +235,17 @@ func (v *VersionedSignedBuilderBid) ParentHash() (phase0.Hash32, error) {
return phase0.Hash32{}, errors.New("no data message header")
}
return v.Capella.Message.Header.ParentHash, nil
case consensusspec.DataVersionDeneb:
if v.Deneb == nil {
return phase0.Hash32{}, errors.New("no data")
}
if v.Deneb.Message == nil {
return phase0.Hash32{}, errors.New("no data message")
}
if v.Deneb.Message.Header == nil {
return phase0.Hash32{}, errors.New("no data message header")
}
return v.Deneb.Message.Header.ParentHash, nil
default:
return phase0.Hash32{}, errors.New("unsupported version")
}
Expand Down Expand Up @@ -226,6 +279,17 @@ func (v *VersionedSignedBuilderBid) StateRoot() (phase0.Root, error) {
return phase0.Root{}, errors.New("no data message header")
}
return v.Capella.Message.Header.StateRoot, nil
case consensusspec.DataVersionDeneb:
if v.Deneb == nil {
return phase0.Root{}, errors.New("no data")
}
if v.Deneb.Message == nil {
return phase0.Root{}, errors.New("no data message")
}
if v.Deneb.Message.Header == nil {
return phase0.Root{}, errors.New("no data message header")
}
return v.Deneb.Message.Header.StateRoot, nil
default:
return phase0.Root{}, errors.New("unsupported version")
}
Expand Down Expand Up @@ -259,6 +323,17 @@ func (v *VersionedSignedBuilderBid) FeeRecipient() (consensusbellatrix.Execution
return consensusbellatrix.ExecutionAddress{}, errors.New("no data message header")
}
return v.Capella.Message.Header.FeeRecipient, nil
case consensusspec.DataVersionDeneb:
if v.Deneb == nil {
return consensusbellatrix.ExecutionAddress{}, errors.New("no data")
}
if v.Deneb.Message == nil {
return consensusbellatrix.ExecutionAddress{}, errors.New("no data message")
}
if v.Deneb.Message.Header == nil {
return consensusbellatrix.ExecutionAddress{}, errors.New("no data message header")
}
return v.Deneb.Message.Header.FeeRecipient, nil
default:
return consensusbellatrix.ExecutionAddress{}, errors.New("unsupported version")
}
Expand Down Expand Up @@ -292,6 +367,17 @@ func (v *VersionedSignedBuilderBid) Timestamp() (uint64, error) {
return 0, errors.New("no data message header")
}
return v.Capella.Message.Header.Timestamp, nil
case consensusspec.DataVersionDeneb:
if v.Deneb == nil {
return 0, errors.New("no data")
}
if v.Deneb.Message == nil {
return 0, errors.New("no data message")
}
if v.Deneb.Message.Header == nil {
return 0, errors.New("no data message header")
}
return v.Deneb.Message.Header.Timestamp, nil
default:
return 0, errors.New("unsupported version")
}
Expand Down Expand Up @@ -325,6 +411,17 @@ func (v *VersionedSignedBuilderBid) TransactionsRoot() (phase0.Root, error) {
return phase0.Root{}, errors.New("no data message header")
}
return v.Capella.Message.Header.TransactionsRoot, nil
case consensusspec.DataVersionDeneb:
if v.Deneb == nil {
return phase0.Root{}, errors.New("no data")
}
if v.Deneb.Message == nil {
return phase0.Root{}, errors.New("no data message")
}
if v.Deneb.Message.Header == nil {
return phase0.Root{}, errors.New("no data message header")
}
return v.Deneb.Message.Header.TransactionsRoot, nil
default:
return phase0.Root{}, errors.New("unsupported version")
}
Expand Down Expand Up @@ -352,6 +449,14 @@ func (v *VersionedSignedBuilderBid) MessageHashTreeRoot() (phase0.Root, error) {
return phase0.Root{}, errors.New("no data message")
}
return v.Capella.Message.HashTreeRoot()
case consensusspec.DataVersionDeneb:
if v.Deneb == nil {
return phase0.Root{}, errors.New("no data")
}
if v.Deneb.Message == nil {
return phase0.Root{}, errors.New("no data message")
}
return v.Deneb.Message.HashTreeRoot()
default:
return phase0.Root{}, errors.New("unsupported version")
}
Expand Down Expand Up @@ -385,6 +490,17 @@ func (v *VersionedSignedBuilderBid) HeaderHashTreeRoot() (phase0.Root, error) {
return phase0.Root{}, errors.New("no data message header")
}
return v.Capella.Message.Header.HashTreeRoot()
case consensusspec.DataVersionDeneb:
if v.Deneb == nil {
return phase0.Root{}, errors.New("no data")
}
if v.Deneb.Message == nil {
return phase0.Root{}, errors.New("no data message")
}
if v.Deneb.Message.Header == nil {
return phase0.Root{}, errors.New("no data message header")
}
return v.Deneb.Message.Header.HashTreeRoot()
default:
return phase0.Root{}, errors.New("unsupported version")
}
Expand All @@ -406,6 +522,11 @@ func (v *VersionedSignedBuilderBid) Signature() (phase0.BLSSignature, error) {
return phase0.BLSSignature{}, errors.New("no data")
}
return v.Capella.Signature, nil
case consensusspec.DataVersionDeneb:
if v.Deneb == nil {
return phase0.BLSSignature{}, errors.New("no data")
}
return v.Deneb.Signature, nil
default:
return phase0.BLSSignature{}, errors.New("unsupported version")
}
Expand Down
23 changes: 23 additions & 0 deletions spec/versionedsignedbuilderbid_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (

"github.com/attestantio/go-builder-client/api/bellatrix"
"github.com/attestantio/go-builder-client/api/capella"
"github.com/attestantio/go-builder-client/api/deneb"
"github.com/attestantio/go-eth2-client/spec"
"github.com/pkg/errors"
)
Expand All @@ -34,6 +35,10 @@ type capellaVersionedSignedBuilderBidJSON struct {
Data *capella.SignedBuilderBid `json:"data"`
}

type denebVersionedSignedBuilderBidJSON struct {
Data *deneb.SignedBuilderBid `json:"data"`
}

// MarshalJSON implements json.Marshaler.
func (v *VersionedSignedBuilderBid) MarshalJSON() ([]byte, error) {
version := &versionJSON{
Expand Down Expand Up @@ -65,6 +70,18 @@ func (v *VersionedSignedBuilderBid) MarshalJSON() ([]byte, error) {
*capellaVersionedSignedBuilderBidJSON
}{version, data}
return json.Marshal(payload)
case spec.DataVersionDeneb:
if v.Deneb == nil {
return nil, errors.New("no deneb data")
}
data := &denebVersionedSignedBuilderBidJSON{
Data: v.Deneb,
}
payload := struct {
*versionJSON
*denebVersionedSignedBuilderBidJSON
}{version, data}
return json.Marshal(payload)
default:
return nil, fmt.Errorf("unsupported data version %v", v.Version)
}
Expand All @@ -90,6 +107,12 @@ func (v *VersionedSignedBuilderBid) UnmarshalJSON(input []byte) error {
return errors.Wrap(err, "invalid JSON")
}
v.Capella = data.Data
case spec.DataVersionDeneb:
var data denebVersionedSignedBuilderBidJSON
if err := json.Unmarshal(input, &data); err != nil {
return errors.Wrap(err, "invalid JSON")
}
v.Deneb = data.Data
default:
return fmt.Errorf("unsupported data version %v", metadata.Version)
}
Expand Down
9 changes: 9 additions & 0 deletions spec/versionedsignedbuilderbid_json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@ func TestVersionedSignedBuilderBidJSON(t *testing.T) {
name: "GoodCapella",
input: []byte(`{"version":"capella","data":{"message":{"header":{"parent_hash":"0x17f4eeae822cc81533016678413443b95e34517e67f12b4a3a92ff6b66f972ef","fee_recipient":"0x58E809C71e4885cB7B3f1D5c793AB04eD239d779","state_root":"0x3d6e230e6eceb8f3db582777b1500b8b31b9d268339e7b32bba8d6f1311b211d","receipts_root":"0xea760203509bdde017a506b12c825976d12b04db7bce9eca9e1ed007056a3f36","logs_bloom":"0x0c803a8d3c6642adee3185bd914c599317d96487831dabda82461f65700b2528781bdadf785664f9d8b11c4ee1139dfeb056125d2abd67e379cabc6d58f1c3ea304b97cf17fcd8a4c53f4dedeaa041acce062fc8fbc88ffc111577db4a936378749f2fd82b4bfcb880821dd5cbefee984bc1ad116096a64a44a2aac8a1791a7ad3a53d91c584ac69a8973daed6daee4432a198c9935fa0e5c2a4a6ca78b821a5b046e571a5c0961f469d40e429066755fec611afe25b560db07f989933556ce0cea4070ca47677b007b4b9857fc092625f82c84526737dc98e173e34fe6e4d0f1a400fd994298b7c2fa8187331c333c415f0499836ff0eed5c762bf570e67b44","prev_randao":"0x76ff751467270668df463600d26dba58297a986e649bac84ea856712d4779c00","block_number":"2983837628677007840","gas_limit":"6738255228996962210","gas_used":"5573520557770513197","timestamp":"1744720080366521389","extra_data":"0xc648","base_fee_per_gas":"88770397543877639215846057887940126737648744594802753726778414602657613619599","block_hash":"0x42c294e902bfc9884c1ce5fef156d4661bb8f0ff488bface37f18c3e7be64b0f","transactions_root":"0x8457d0eb7611a621e7a094059f087415ffcfc91714fc184a1f3c48db06b4d08b","withdrawals_root":"0x5c1a7e3e0eab917a7c0d677c6b692ed55ce05f07d572e09b1c06d558f474ea7a"},"value":"12345","pubkey":"0x010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101"},"signature":"0x010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101"}}`),
},
{
name: "BadDeneb",
input: []byte(`{"version":"deneb","data":[]}`),
err: "invalid JSON: invalid JSON: json: cannot unmarshal array into Go value of type deneb.signedBuilderBidJSON",
},
{
name: "GoodDeneb",
input: []byte(`{"version":"deneb","data":{"message":{"header":{"parent_hash":"0x17f4eeae822cc81533016678413443b95e34517e67f12b4a3a92ff6b66f972ef","fee_recipient":"0x58E809C71e4885cB7B3f1D5c793AB04eD239d779","state_root":"0x3d6e230e6eceb8f3db582777b1500b8b31b9d268339e7b32bba8d6f1311b211d","receipts_root":"0xea760203509bdde017a506b12c825976d12b04db7bce9eca9e1ed007056a3f36","logs_bloom":"0x0c803a8d3c6642adee3185bd914c599317d96487831dabda82461f65700b2528781bdadf785664f9d8b11c4ee1139dfeb056125d2abd67e379cabc6d58f1c3ea304b97cf17fcd8a4c53f4dedeaa041acce062fc8fbc88ffc111577db4a936378749f2fd82b4bfcb880821dd5cbefee984bc1ad116096a64a44a2aac8a1791a7ad3a53d91c584ac69a8973daed6daee4432a198c9935fa0e5c2a4a6ca78b821a5b046e571a5c0961f469d40e429066755fec611afe25b560db07f989933556ce0cea4070ca47677b007b4b9857fc092625f82c84526737dc98e173e34fe6e4d0f1a400fd994298b7c2fa8187331c333c415f0499836ff0eed5c762bf570e67b44","prev_randao":"0x76ff751467270668df463600d26dba58297a986e649bac84ea856712d4779c00","block_number":"2983837628677007840","gas_limit":"6738255228996962210","gas_used":"5573520557770513197","timestamp":"1744720080366521389","extra_data":"0xc648","base_fee_per_gas":"88770397543877639215846057887940126737648744594802753726778414602657613619599","block_hash":"0x42c294e902bfc9884c1ce5fef156d4661bb8f0ff488bface37f18c3e7be64b0f","transactions_root":"0x8457d0eb7611a621e7a094059f087415ffcfc91714fc184a1f3c48db06b4d08b","withdrawals_root":"0x5c1a7e3e0eab917a7c0d677c6b692ed55ce05f07d572e09b1c06d558f474ea7a","data_gas_used":"4438756708366371443","excess_data_gas":"12504111653614393862"},"value":"12345","pubkey":"0x010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101","blinded_blobs_bundle":{"commitments":["0x95cc5099bbd8420d8ebade383c00a2346dace60a7604f768cd71501757b4d72eeb7d5474a6b615af10379d69aa9f478f","0xae9f2d2217013ef61f995f9074faead9ec24e8048440164ec3d6029b87d43686dd0c97c2df9554fc997d0d66c3a78929"],"proofs":["0xc6e27a3ae80243ba7ea88eab107a0675020e0745d75ab6a1553691007a50f7f99f597693ac33ae3cea63bf0b90a734ff","0xc6e27a3ae80243ba7ea88eab107a0675020e0745d75ab6a1553691007a50f7f99f597693ac33ae3cea63bf0b90a734ff"],"blob_roots":["0x3c1820c62034fc45c10abc983dbce08de28f303192dea32371a902b3e6a1fc29","0xba4d784293df28bab771a14df58cdbed9d8d64afd0ddf1c52dff3e25fcdd51df"]}},"signature":"0x010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101"}}`),
},
}

for _, test := range tests {
Expand Down
Loading

0 comments on commit f7738a5

Please sign in to comment.