Skip to content

Commit

Permalink
Update electra types for devnet-1
Browse files Browse the repository at this point in the history
  • Loading branch information
avalonche committed Aug 3, 2024
1 parent 1171c07 commit 259f2d7
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 34 deletions.
8 changes: 4 additions & 4 deletions api/versionedsubmitblindedblockresponse.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand All @@ -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")
}
Expand Down
6 changes: 3 additions & 3 deletions api/versionedsubmitblindedblockresponse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
Expand Down Expand Up @@ -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",
},
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
Expand Down
4 changes: 2 additions & 2 deletions http/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ func registerPrometheusMetrics(_ context.Context) error {
return prometheus.Register(requestsTimer)
}

func (s *Service) monitorGetComplete(_ context.Context, endpoint string, result string) {
func (s *Service) monitorGetComplete(_ context.Context, endpoint, result string) {
if requestsCounter == nil {
return
}

requestsCounter.WithLabelValues(s.address, "GET", reduceEndpoint(endpoint), result).Inc()
}

func (s *Service) monitorPostComplete(_ context.Context, endpoint string, result string) {
func (s *Service) monitorPostComplete(_ context.Context, endpoint, result string) {
if requestsCounter == nil {
return
}
Expand Down
43 changes: 26 additions & 17 deletions http/unblindproposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/attestantio/go-eth2-client/spec/bellatrix"
"github.com/attestantio/go-eth2-client/spec/capella"
"github.com/attestantio/go-eth2-client/spec/deneb"
"github.com/attestantio/go-eth2-client/spec/electra"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/trace"
Expand Down Expand Up @@ -349,24 +350,29 @@ func (s *Service) unblindDenebProposal(ctx context.Context,
}

func (s *Service) unblindElectraProposal(ctx context.Context,
started time.Time,
proposal *consensusapiv1electra.SignedBlindedBeaconBlock,
opts *api.UnblindProposalOpts,
) (
*consensusapi.VersionedSignedProposal,
*api.Response[*consensusapi.VersionedSignedProposal],
error,
) {
proposal := opts.Proposal.Electra

specJSON, err := json.Marshal(proposal)
if err != nil {
monitorOperation(s.Address(), "unblind proposal", "failed", time.Since(started))

return nil, errors.Wrap(err, "failed to marshal JSON")
return nil, errors.Join(errors.New("failed to marshal JSON"), err)
}

httpResponse, err := s.post(ctx, "/eth/v1/builder/blinded_blocks", "", bytes.NewBuffer(specJSON), ContentTypeJSON, map[string]string{})
httpResponse, err := s.post(ctx,
"/eth/v1/builder/blinded_blocks",
"",
&opts.Common,
bytes.NewBuffer(specJSON),
ContentTypeJSON,
map[string]string{},
false,
)
if err != nil {
monitorOperation(s.Address(), "unblind proposal", "failed", time.Since(started))

return nil, errors.Wrap(err, "failed to submit unblind proposal request")
return nil, errors.Join(errors.New("failed to submit unblind proposal request"), err)
}

// Reconstruct proposal.
Expand All @@ -391,7 +397,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,
Expand All @@ -403,19 +408,21 @@ func (s *Service) unblindElectraProposal(ctx context.Context,
case ContentTypeJSON:
bundle, _, err := decodeJSONResponse(bytes.NewReader(httpResponse.body), &apielectra.ExecutionPayloadAndBlobsBundle{})
if err != nil {
return nil, errors.Wrap(err, "failed to parse electra response")
return nil, errors.Join(errors.New("failed to parse electra response"), err)
}
// Ensure that the data returned is what we expect.
ourExecutionPayloadHash, err := proposal.Message.Body.ExecutionPayloadHeader.HashTreeRoot()
if err != nil {
return nil, errors.Wrap(err, "failed to generate hash tree root for our execution payload header")
return nil, errors.Join(errors.New("failed to generate hash tree root for our execution payload header"), err)
}
receivedExecutionPayloadHash, err := bundle.ExecutionPayload.HashTreeRoot()
if err != nil {
return nil, errors.Wrap(err, "failed to generate hash tree root for the received execution payload")
return nil, errors.Join(errors.New("failed to generate hash tree root for the received execution payload"), 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

Expand All @@ -433,7 +440,9 @@ func (s *Service) unblindElectraProposal(ctx context.Context,
default:
return nil, fmt.Errorf("unsupported content type %v", httpResponse.contentType)
}
monitorOperation(s.Address(), "unblind proposal", "succeeded", time.Since(started))

return res, nil
return &api.Response[*consensusapi.VersionedSignedProposal]{
Data: res,
Metadata: metadataFromHeaders(httpResponse.headers),
}, nil
}
30 changes: 25 additions & 5 deletions spec/versionedsubmitblockrequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ 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"
apiv1 "github.com/attestantio/go-builder-client/api/v1"
"github.com/attestantio/go-builder-client/api/electra"
apiv1 "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"
consensuscapella "github.com/attestantio/go-eth2-client/spec/capella"
Expand Down Expand Up @@ -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")
}
Expand All @@ -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")
}
Expand All @@ -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 {
Expand Down

0 comments on commit 259f2d7

Please sign in to comment.