From 4a640904814603e9a66af4876c5f8c448acfbc23 Mon Sep 17 00:00:00 2001 From: avalonche Date: Sat, 3 Aug 2024 10:15:27 +1000 Subject: [PATCH 1/2] Update electra types for devnet-1 --- api/versionedsubmitblindedblockresponse.go | 8 +++--- ...ersionedsubmitblindedblockresponse_test.go | 6 ++-- go.mod | 2 +- go.sum | 4 +-- http/unblindproposal.go | 1 - spec/versionedsubmitblockrequest.go | 28 ++++++++++++++++--- 6 files changed, 34 insertions(+), 15 deletions(-) diff --git a/api/versionedsubmitblindedblockresponse.go b/api/versionedsubmitblindedblockresponse.go index 1cfc776..2e3ac03 100644 --- a/api/versionedsubmitblindedblockresponse.go +++ b/api/versionedsubmitblindedblockresponse.go @@ -219,8 +219,8 @@ func (v *VersionedSubmitBlindedBlockResponse) ExcessBlobGas() (uint64, error) { } } -// DepositReceipts returns the deposit receipts of the execution payload. -func (v *VersionedSubmitBlindedBlockResponse) DepositReceipts() ([]*consensuselectra.DepositReceipt, error) { +// DepositRequests returns the deposit receipts of the execution payload. +func (v *VersionedSubmitBlindedBlockResponse) DepositRequests() ([]*consensuselectra.DepositRequest, error) { if v == nil { return nil, errors.New("nil struct") } @@ -233,14 +233,14 @@ func (v *VersionedSubmitBlindedBlockResponse) DepositReceipts() ([]*consensusele return nil, errors.New("no data execution payload") } - return v.Electra.ExecutionPayload.DepositReceipts, nil + return v.Electra.ExecutionPayload.DepositRequests, nil default: return nil, errors.New("unsupported version") } } // WithdrawalRequests returns the execution layer withdrawal requests of the execution payload. -func (v *VersionedSubmitBlindedBlockResponse) WithdrawalRequests() ([]*consensuselectra.ExecutionLayerWithdrawalRequest, error) { +func (v *VersionedSubmitBlindedBlockResponse) WithdrawalRequests() ([]*consensuselectra.WithdrawalRequest, error) { if v == nil { return nil, errors.New("nil struct") } diff --git a/api/versionedsubmitblindedblockresponse_test.go b/api/versionedsubmitblindedblockresponse_test.go index a30303d..ff65a84 100644 --- a/api/versionedsubmitblindedblockresponse_test.go +++ b/api/versionedsubmitblindedblockresponse_test.go @@ -139,7 +139,7 @@ func TestVersionedSubmitBlindedBlockResponseBlockHash(t *testing.T) { name: "DenebNoExecutionPayload", payload: &api.VersionedSubmitBlindedBlockResponse{ Version: consensusspec.DataVersionDeneb, - Deneb: &denebapi.ExecutionPayloadAndBlobsBundle{}, + Deneb: &denebapi.ExecutionPayloadAndBlobsBundle{}, }, err: "no execution payload", }, @@ -248,11 +248,11 @@ func TestVersionedSubmitBlindedBlockResponseTransactions(t *testing.T) { }, err: "no data", }, - { + { name: "DenebNoExecutionPayload", bid: &api.VersionedSubmitBlindedBlockResponse{ Version: consensusspec.DataVersionDeneb, - Deneb: &denebapi.ExecutionPayloadAndBlobsBundle{}, + Deneb: &denebapi.ExecutionPayloadAndBlobsBundle{}, }, err: "no execution payload", }, diff --git a/go.mod b/go.mod index 82c7a79..3bcc6e1 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/attestantio/go-builder-client go 1.20 require ( - github.com/attestantio/go-eth2-client v0.21.4-0.20240508201227-6fd8b5ef4447 + github.com/attestantio/go-eth2-client v0.21.7-0.20240701211822-0a60485fce68 github.com/ferranbt/fastssz v0.1.3 // go-yaml after 1.9.2 has memory issues due to https://github.com/goccy/go-yaml/issues/325; avoid. github.com/goccy/go-yaml v1.9.2 diff --git a/go.sum b/go.sum index fd4da60..ac8a6de 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,5 @@ -github.com/attestantio/go-eth2-client v0.21.4-0.20240508201227-6fd8b5ef4447 h1:k0SJ1kAoijCKsRLG+D8kzicwAwpkCWsa/9KRQS5EjFg= -github.com/attestantio/go-eth2-client v0.21.4-0.20240508201227-6fd8b5ef4447/go.mod h1:yzMl6JKut8ngKCRyv+6H9j2nNjS/+SMm3N+duf8iix8= +github.com/attestantio/go-eth2-client v0.21.7-0.20240701211822-0a60485fce68 h1:+sc+OAeTcWjQ5BwK6aajh9xnu8KYtIJNVqwbWx+KvQ4= +github.com/attestantio/go-eth2-client v0.21.7-0.20240701211822-0a60485fce68/go.mod h1:vy5jU/uDZ2+RcVzq5BfnG+bQ3/6uu9DGwCrGsPtjJ1A= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= diff --git a/http/unblindproposal.go b/http/unblindproposal.go index af0cec0..2de3c64 100644 --- a/http/unblindproposal.go +++ b/http/unblindproposal.go @@ -398,7 +398,6 @@ func (s *Service) unblindElectraProposal(ctx context.Context, SyncAggregate: proposal.Message.Body.SyncAggregate, BLSToExecutionChanges: proposal.Message.Body.BLSToExecutionChanges, BlobKZGCommitments: proposal.Message.Body.BlobKZGCommitments, - Consolidations: proposal.Message.Body.Consolidations, }, }, Signature: proposal.Signature, diff --git a/spec/versionedsubmitblockrequest.go b/spec/versionedsubmitblockrequest.go index 897c684..50690e4 100644 --- a/spec/versionedsubmitblockrequest.go +++ b/spec/versionedsubmitblockrequest.go @@ -969,8 +969,8 @@ func (v *VersionedSubmitBlockRequest) ExcessBlobGas() (uint64, error) { } } -// DepositReceipts returns the deposit receipts of the execution payload. -func (v *VersionedSubmitBlockRequest) DepositReceipts() ([]*consensuselectra.DepositReceipt, error) { +// DepositRequests returns the deposit receipts of the execution payload. +func (v *VersionedSubmitBlockRequest) DepositRequests() ([]*consensuselectra.DepositRequest, error) { if v == nil { return nil, errors.New("nil struct") } @@ -983,14 +983,14 @@ func (v *VersionedSubmitBlockRequest) DepositReceipts() ([]*consensuselectra.Dep return nil, errors.New("no data execution payload") } - return v.Electra.ExecutionPayload.DepositReceipts, nil + return v.Electra.ExecutionPayload.DepositRequests, nil default: return nil, errors.New("unsupported version") } } // WithdrawalRequests returns the execution layer withdrawal requests of the execution payload. -func (v *VersionedSubmitBlockRequest) WithdrawalRequests() ([]*consensuselectra.ExecutionLayerWithdrawalRequest, error) { +func (v *VersionedSubmitBlockRequest) WithdrawalRequests() ([]*consensuselectra.WithdrawalRequest, error) { if v == nil { return nil, errors.New("nil struct") } @@ -1009,6 +1009,26 @@ func (v *VersionedSubmitBlockRequest) WithdrawalRequests() ([]*consensuselectra. } } +// ConsolidationRequests returns the consolidation requests of the execution payload. +func (v *VersionedSubmitBlockRequest) ConsolidationRequests() ([]*consensuselectra.ConsolidationRequest, error) { + if v == nil { + return nil, errors.New("nil struct") + } + switch v.Version { + case consensusspec.DataVersionElectra: + if v.Electra == nil { + return nil, errors.New("no data") + } + if v.Electra.ExecutionPayload == nil { + return nil, errors.New("no data execution payload") + } + + return v.Electra.ExecutionPayload.ConsolidationRequests, nil + default: + return nil, errors.New("unsupported version") + } +} + // String returns a string version of the structure. func (v *VersionedSubmitBlockRequest) String() string { if v == nil { From 0c697db78138cd039a89550f0ec78944fb589c57 Mon Sep 17 00:00:00 2001 From: avalonche Date: Sun, 4 Aug 2024 12:20:52 +1000 Subject: [PATCH 2/2] fix linting --- api/electra/generate.go | 1 + api/electra/submitblockrequest.go | 4 ++-- api/electra/submitblockrequest_json.go | 4 ++-- api/electra/submitblockrequest_ssz.go | 8 ++++---- api/electra/submitblockrequest_yaml.go | 4 ++-- http/unblindproposal.go | 4 +++- 6 files changed, 14 insertions(+), 11 deletions(-) diff --git a/api/electra/generate.go b/api/electra/generate.go index 92b6005..165275c 100644 --- a/api/electra/generate.go +++ b/api/electra/generate.go @@ -15,5 +15,6 @@ package electra // Need to `go install github.com/ferranbt/fastssz/sszgen@latest` for this to work. //go:generate rm -f builderbid_ssz.go executionpayloadandblobsbundle_ssz.go signedbuilderbid_ssz.go submitblockrequest_ssz.go +//nolint:revive //go:generate sszgen --suffix ssz --include ../../../go-eth2-client/spec/phase0,../../../go-eth2-client/spec/bellatrix,../../../go-eth2-client/spec/capella,../../../go-eth2-client/spec/deneb,../../../go-eth2-client/spec/electra,../v1,../deneb --path . --objs BuilderBid,ExecutionPayloadAndBlobsBundle,SignedBuilderBid,SubmitBlockRequest //go:generate goimports -w builderbid_ssz.go executionpayloadandblobsbundle_ssz.go signedbuilderbid_ssz.go submitblockrequest_ssz.go diff --git a/api/electra/submitblockrequest.go b/api/electra/submitblockrequest.go index a67fcd1..775e5c5 100644 --- a/api/electra/submitblockrequest.go +++ b/api/electra/submitblockrequest.go @@ -17,7 +17,7 @@ import ( "fmt" "github.com/attestantio/go-builder-client/api/deneb" - v1 "github.com/attestantio/go-builder-client/api/v1" + apiv1 "github.com/attestantio/go-builder-client/api/v1" "github.com/attestantio/go-eth2-client/spec/electra" "github.com/attestantio/go-eth2-client/spec/phase0" "github.com/goccy/go-yaml" @@ -25,7 +25,7 @@ import ( // SubmitBlockRequest is the request from the builder to submit a block. type SubmitBlockRequest struct { - Message *v1.BidTrace + Message *apiv1.BidTrace ExecutionPayload *electra.ExecutionPayload BlobsBundle *deneb.BlobsBundle Signature phase0.BLSSignature `ssz-size:"96"` diff --git a/api/electra/submitblockrequest_json.go b/api/electra/submitblockrequest_json.go index f994e34..72ee998 100644 --- a/api/electra/submitblockrequest_json.go +++ b/api/electra/submitblockrequest_json.go @@ -20,7 +20,7 @@ import ( "strings" "github.com/attestantio/go-builder-client/api/deneb" - v1 "github.com/attestantio/go-builder-client/api/v1" + apiv1 "github.com/attestantio/go-builder-client/api/v1" "github.com/attestantio/go-eth2-client/spec/electra" "github.com/attestantio/go-eth2-client/spec/phase0" "github.com/pkg/errors" @@ -28,7 +28,7 @@ import ( // submitBlockRequestJSON is the spec representation of the struct. type submitBlockRequestJSON struct { - Message *v1.BidTrace `json:"message"` + Message *apiv1.BidTrace `json:"message"` ExecutionPayload *electra.ExecutionPayload `json:"execution_payload"` BlobsBundle *deneb.BlobsBundle `json:"blobs_bundle"` Signature string `json:"signature"` diff --git a/api/electra/submitblockrequest_ssz.go b/api/electra/submitblockrequest_ssz.go index 1dd7d68..8dfe9b8 100644 --- a/api/electra/submitblockrequest_ssz.go +++ b/api/electra/submitblockrequest_ssz.go @@ -5,7 +5,7 @@ package electra import ( "github.com/attestantio/go-builder-client/api/deneb" - v1 "github.com/attestantio/go-builder-client/api/v1" + apiv1 "github.com/attestantio/go-builder-client/api/v1" "github.com/attestantio/go-eth2-client/spec/electra" ssz "github.com/ferranbt/fastssz" ) @@ -22,7 +22,7 @@ func (s *SubmitBlockRequest) MarshalSSZTo(buf []byte) (dst []byte, err error) { // Field (0) 'Message' if s.Message == nil { - s.Message = new(v1.BidTrace) + s.Message = new(apiv1.BidTrace) } if dst, err = s.Message.MarshalSSZTo(dst); err != nil { return @@ -71,7 +71,7 @@ func (s *SubmitBlockRequest) UnmarshalSSZ(buf []byte) error { // Field (0) 'Message' if s.Message == nil { - s.Message = new(v1.BidTrace) + s.Message = new(apiv1.BidTrace) } if err = s.Message.UnmarshalSSZ(buf[0:236]); err != nil { return err @@ -148,7 +148,7 @@ func (s *SubmitBlockRequest) HashTreeRootWith(hh ssz.HashWalker) (err error) { // Field (0) 'Message' if s.Message == nil { - s.Message = new(v1.BidTrace) + s.Message = new(apiv1.BidTrace) } if err = s.Message.HashTreeRootWith(hh); err != nil { return diff --git a/api/electra/submitblockrequest_yaml.go b/api/electra/submitblockrequest_yaml.go index 2c31dc6..02b794a 100644 --- a/api/electra/submitblockrequest_yaml.go +++ b/api/electra/submitblockrequest_yaml.go @@ -18,14 +18,14 @@ import ( "fmt" "github.com/attestantio/go-builder-client/api/deneb" - v1 "github.com/attestantio/go-builder-client/api/v1" + apiv1 "github.com/attestantio/go-builder-client/api/v1" "github.com/attestantio/go-eth2-client/spec/electra" "github.com/goccy/go-yaml" ) // submitBlockRequestYAML is the spec representation of the struct. type submitBlockRequestYAML struct { - Message *v1.BidTrace `yaml:"message"` + Message *apiv1.BidTrace `yaml:"message"` ExecutionPayload *electra.ExecutionPayload `yaml:"execution_payload"` BlobsBundle *deneb.BlobsBundle `yaml:"blobs_bundle"` Signature string `yaml:"signature"` diff --git a/http/unblindproposal.go b/http/unblindproposal.go index 2de3c64..637b4e5 100644 --- a/http/unblindproposal.go +++ b/http/unblindproposal.go @@ -421,7 +421,9 @@ func (s *Service) unblindElectraProposal(ctx context.Context, return nil, errors.Join(errors.New("failed to generate hash tree root for the received execution payload header"), err) } if !bytes.Equal(ourExecutionPayloadHash[:], receivedExecutionPayloadHash[:]) { - return nil, fmt.Errorf("execution payload hash mismatch: %#x != %#x", receivedExecutionPayloadHash[:], ourExecutionPayloadHash[:]) + return nil, fmt.Errorf("execution payload hash mismatch: %#x != %#x", receivedExecutionPayloadHash[:], + ourExecutionPayloadHash[:], + ) } res.Electra.SignedBlock.Message.Body.ExecutionPayload = bundle.ExecutionPayload