Skip to content

Commit

Permalink
add deneb to submit block request
Browse files Browse the repository at this point in the history
  • Loading branch information
avalonche committed Jul 31, 2023
1 parent f7738a5 commit c49675d
Show file tree
Hide file tree
Showing 5 changed files with 796 additions and 5 deletions.
8 changes: 5 additions & 3 deletions api/deneb/submitblockrequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@ import (
"fmt"

v1 "github.com/attestantio/go-builder-client/api/v1"
"github.com/attestantio/go-eth2-client/spec/deneb"
"github.com/attestantio/go-eth2-client/spec/phase0"
"github.com/goccy/go-yaml"
)

// SubmitBlockRequest is the request from the builder to submit a block.
type SubmitBlockRequest struct {
Message *v1.BidTrace
ExecutionPayloadAndBlobsBundle
Signature phase0.BLSSignature `ssz-size:"96"`
Message *v1.BidTrace
ExecutionPayload *deneb.ExecutionPayload
BlobsBundle *BlobsBundle
Signature phase0.BLSSignature `ssz-size:"96"`
}

// String returns a string version of the structure.
Expand Down
4 changes: 2 additions & 2 deletions spec/versionedsignedbuilderbid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1557,8 +1557,8 @@ func TestVersionedSignedBuilderBidMessageHashTreeRoot(t *testing.T) {
},
},
res: phase0.Root{
0x31, 0x5d, 0x00, 0x52, 0x98, 0x8b, 0x3f, 0x54, 0xc3, 0x74, 0xa1, 0x87, 0x94, 0x30, 0xc8, 0x18,
0x00, 0x0f, 0x60, 0x50, 0x4a, 0xaa, 0xcf, 0x5b, 0xa5, 0xa9, 0x73, 0xc8, 0xa0, 0xb1, 0x4f, 0xa1,
0xfb, 0x3a, 0xe3, 0xdc, 0x57, 0xe4, 0x16, 0x8c, 0x65, 0xc6, 0x43, 0x3f, 0x56, 0xb6, 0x99, 0x67,
0x33, 0x36, 0x52, 0x8e, 0x4a, 0xae, 0x4f, 0x79, 0xe7, 0x82, 0x66, 0x03, 0x9f, 0xe4, 0xe8, 0x25,
},
},
}
Expand Down
145 changes: 145 additions & 0 deletions spec/versionedsubmitblockrequest.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"
v1 "github.com/attestantio/go-builder-client/api/v1"
consensusspec "github.com/attestantio/go-eth2-client/spec"
consensusbellatrix "github.com/attestantio/go-eth2-client/spec/bellatrix"
Expand All @@ -33,6 +34,7 @@ type VersionedSubmitBlockRequest struct {
Version consensusspec.DataVersion
Bellatrix *bellatrix.SubmitBlockRequest
Capella *capella.SubmitBlockRequest
Deneb *deneb.SubmitBlockRequest
}

// IsEmpty returns true if there is no request.
Expand All @@ -42,6 +44,8 @@ func (v *VersionedSubmitBlockRequest) 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 @@ -69,6 +73,14 @@ func (v *VersionedSubmitBlockRequest) Slot() (uint64, error) {
return 0, errors.New("no data message")
}
return v.Capella.Message.Slot, 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")
}
return v.Deneb.Message.Slot, nil
default:
return 0, errors.New("unsupported version")
}
Expand Down Expand Up @@ -96,6 +108,14 @@ func (v *VersionedSubmitBlockRequest) BlockHash() (phase0.Hash32, error) {
return phase0.Hash32{}, errors.New("no data message")
}
return v.Capella.Message.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")
}
return v.Deneb.Message.BlockHash, nil
default:
return phase0.Hash32{}, errors.New("unsupported version")
}
Expand Down Expand Up @@ -123,6 +143,14 @@ func (v *VersionedSubmitBlockRequest) Builder() (phase0.BLSPubKey, error) {
return phase0.BLSPubKey{}, errors.New("no data message")
}
return v.Capella.Message.BuilderPubkey, 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.BuilderPubkey, nil
default:
return phase0.BLSPubKey{}, errors.New("unsupported version")
}
Expand Down Expand Up @@ -150,6 +178,14 @@ func (v *VersionedSubmitBlockRequest) ProposerFeeRecipient() (consensusbellatrix
return consensusbellatrix.ExecutionAddress{}, errors.New("no data message")
}
return v.Capella.Message.ProposerFeeRecipient, 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")
}
return v.Deneb.Message.ProposerFeeRecipient, nil
default:
return consensusbellatrix.ExecutionAddress{}, errors.New("unsupported version")
}
Expand Down Expand Up @@ -177,6 +213,14 @@ func (v *VersionedSubmitBlockRequest) ProposerPubKey() (phase0.BLSPubKey, error)
return phase0.BLSPubKey{}, errors.New("no data message")
}
return v.Capella.Message.ProposerPubkey, 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.ProposerPubkey, nil
default:
return phase0.BLSPubKey{}, errors.New("unsupported version")
}
Expand Down Expand Up @@ -204,6 +248,14 @@ func (v *VersionedSubmitBlockRequest) ParentHash() (phase0.Hash32, error) {
return phase0.Hash32{}, errors.New("no data message")
}
return v.Capella.Message.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")
}
return v.Deneb.Message.ParentHash, nil
default:
return phase0.Hash32{}, errors.New("unsupported version")
}
Expand Down Expand Up @@ -231,6 +283,14 @@ func (v *VersionedSubmitBlockRequest) 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 @@ -258,6 +318,14 @@ func (v *VersionedSubmitBlockRequest) BidTrace() (*v1.BidTrace, error) {
return nil, errors.New("no data message")
}
return v.Capella.Message, 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, nil
default:
return nil, errors.New("unsupported version")
}
Expand All @@ -279,6 +347,11 @@ func (v *VersionedSubmitBlockRequest) 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 Expand Up @@ -306,6 +379,14 @@ func (v *VersionedSubmitBlockRequest) ExecutionPayloadBlockHash() (phase0.Hash32
return phase0.Hash32{}, errors.New("no data execution payload")
}
return v.Capella.ExecutionPayload.BlockHash, nil
case consensusspec.DataVersionDeneb:
if v.Deneb == nil {
return phase0.Hash32{}, errors.New("no data")
}
if v.Deneb.ExecutionPayload == nil {
return phase0.Hash32{}, errors.New("no data execution payload")
}
return v.Deneb.ExecutionPayload.BlockHash, nil
default:
return phase0.Hash32{}, errors.New("unsupported version")
}
Expand Down Expand Up @@ -333,6 +414,14 @@ func (v *VersionedSubmitBlockRequest) ExecutionPayloadParentHash() (phase0.Hash3
return phase0.Hash32{}, errors.New("no data execution payload")
}
return v.Capella.ExecutionPayload.ParentHash, nil
case consensusspec.DataVersionDeneb:
if v.Deneb == nil {
return phase0.Hash32{}, errors.New("no data")
}
if v.Deneb.ExecutionPayload == nil {
return phase0.Hash32{}, errors.New("no data execution payload")
}
return v.Deneb.ExecutionPayload.ParentHash, nil
default:
return phase0.Hash32{}, errors.New("unsupported version")
}
Expand Down Expand Up @@ -360,6 +449,14 @@ func (v *VersionedSubmitBlockRequest) PrevRandao() (phase0.Hash32, error) {
return phase0.Hash32{}, errors.New("no data execution payload")
}
return v.Capella.ExecutionPayload.PrevRandao, nil
case consensusspec.DataVersionDeneb:
if v.Deneb == nil {
return phase0.Hash32{}, errors.New("no data")
}
if v.Deneb.ExecutionPayload == nil {
return phase0.Hash32{}, errors.New("no data execution payload")
}
return v.Deneb.ExecutionPayload.PrevRandao, nil
default:
return phase0.Hash32{}, errors.New("unsupported version")
}
Expand Down Expand Up @@ -387,6 +484,14 @@ func (v *VersionedSubmitBlockRequest) GasLimit() (uint64, error) {
return 0, errors.New("no data execution payload")
}
return v.Capella.ExecutionPayload.GasLimit, nil
case consensusspec.DataVersionDeneb:
if v.Deneb == nil {
return 0, errors.New("no data")
}
if v.Deneb.ExecutionPayload == nil {
return 0, errors.New("no data execution payload")
}
return v.Deneb.ExecutionPayload.GasLimit, nil
default:
return 0, errors.New("unsupported version")
}
Expand Down Expand Up @@ -414,6 +519,14 @@ func (v *VersionedSubmitBlockRequest) GasUsed() (uint64, error) {
return 0, errors.New("no data execution payload")
}
return v.Capella.ExecutionPayload.GasUsed, nil
case consensusspec.DataVersionDeneb:
if v.Deneb == nil {
return 0, errors.New("no data")
}
if v.Deneb.ExecutionPayload == nil {
return 0, errors.New("no data execution payload")
}
return v.Deneb.ExecutionPayload.GasUsed, nil
default:
return 0, errors.New("unsupported version")
}
Expand Down Expand Up @@ -441,6 +554,14 @@ func (v *VersionedSubmitBlockRequest) BlockNumber() (uint64, error) {
return 0, errors.New("no data execution payload")
}
return v.Capella.ExecutionPayload.BlockNumber, nil
case consensusspec.DataVersionDeneb:
if v.Deneb == nil {
return 0, errors.New("no data")
}
if v.Deneb.ExecutionPayload == nil {
return 0, errors.New("no data execution payload")
}
return v.Deneb.ExecutionPayload.BlockNumber, nil
default:
return 0, errors.New("unsupported version")
}
Expand Down Expand Up @@ -468,6 +589,14 @@ func (v *VersionedSubmitBlockRequest) Timestamp() (uint64, error) {
return 0, errors.New("no data execution payload")
}
return v.Capella.ExecutionPayload.Timestamp, nil
case consensusspec.DataVersionDeneb:
if v.Deneb == nil {
return 0, errors.New("no data")
}
if v.Deneb.ExecutionPayload == nil {
return 0, errors.New("no data execution payload")
}
return v.Deneb.ExecutionPayload.Timestamp, nil
default:
return 0, errors.New("unsupported version")
}
Expand Down Expand Up @@ -495,6 +624,14 @@ func (v *VersionedSubmitBlockRequest) Transactions() ([]consensusbellatrix.Trans
return nil, errors.New("no data execution payload")
}
return v.Capella.ExecutionPayload.Transactions, nil
case consensusspec.DataVersionDeneb:
if v.Deneb == nil {
return nil, errors.New("no data")
}
if v.Deneb.ExecutionPayload == nil {
return nil, errors.New("no data execution payload")
}
return v.Deneb.ExecutionPayload.Transactions, nil
default:
return nil, errors.New("unsupported version")
}
Expand All @@ -514,6 +651,14 @@ func (v *VersionedSubmitBlockRequest) Withdrawals() ([]*consensuscapella.Withdra
return nil, errors.New("no data execution payload")
}
return v.Capella.ExecutionPayload.Withdrawals, nil
case consensusspec.DataVersionDeneb:
if v.Deneb == nil {
return nil, errors.New("no data")
}
if v.Deneb.ExecutionPayload == nil {
return nil, errors.New("no data execution payload")
}
return v.Deneb.ExecutionPayload.Withdrawals, nil
default:
return nil, errors.New("unsupported version")
}
Expand Down
23 changes: 23 additions & 0 deletions spec/versionedsubmitblockrequest_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 @@ -30,6 +31,10 @@ type capellaVersionedSubmitBlockRequestJSON struct {
Data *capella.SubmitBlockRequest `json:"data"`
}

type denebVersionedSubmitBlockRequestJSON struct {
Data *deneb.SubmitBlockRequest `json:"data"`
}

// MarshalJSON implements json.Marshaler.
func (v *VersionedSubmitBlockRequest) MarshalJSON() ([]byte, error) {
version := &versionJSON{
Expand Down Expand Up @@ -61,6 +66,18 @@ func (v *VersionedSubmitBlockRequest) MarshalJSON() ([]byte, error) {
*capellaVersionedSubmitBlockRequestJSON
}{version, data}
return json.Marshal(payload)
case spec.DataVersionDeneb:
if v.Deneb == nil {
return nil, errors.New("no deneb data")
}
data := &denebVersionedSubmitBlockRequestJSON{
Data: v.Deneb,
}
payload := struct {
*versionJSON
*denebVersionedSubmitBlockRequestJSON
}{version, data}
return json.Marshal(payload)
default:
return nil, fmt.Errorf("unsupported data version %v", v.Version)
}
Expand All @@ -86,6 +103,12 @@ func (v *VersionedSubmitBlockRequest) UnmarshalJSON(input []byte) error {
return errors.Wrap(err, "invalid JSON")
}
v.Capella = data.Data
case spec.DataVersionDeneb:
var data denebVersionedSubmitBlockRequestJSON
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
Loading

0 comments on commit c49675d

Please sign in to comment.