From de1c5e7a686fe7599321526adc9e6881405a40c1 Mon Sep 17 00:00:00 2001 From: shana Date: Tue, 30 Jan 2024 16:09:09 +1100 Subject: [PATCH] marshalling block validation request --- common/types_spec.go | 56 ++++++++++++++++++++++++++++++-------------- 1 file changed, 38 insertions(+), 18 deletions(-) diff --git a/common/types_spec.go b/common/types_spec.go index 132970f4..edf263c4 100644 --- a/common/types_spec.go +++ b/common/types_spec.go @@ -7,6 +7,7 @@ import ( builderApi "github.com/attestantio/go-builder-client/api" builderApiCapella "github.com/attestantio/go-builder-client/api/capella" builderApiDeneb "github.com/attestantio/go-builder-client/api/deneb" + builderApiV1 "github.com/attestantio/go-builder-client/api/v1" builderSpec "github.com/attestantio/go-builder-client/spec" eth2Api "github.com/attestantio/go-eth2-client/api" eth2ApiV1Capella "github.com/attestantio/go-eth2-client/api/v1/capella" @@ -232,28 +233,47 @@ func DenebUnblindSignedBlock(blindedBlock *eth2ApiV1Deneb.SignedBlindedBeaconBlo type BuilderBlockValidationRequest struct { *VersionedSubmitBlockRequest - RegisteredGasLimit uint64 `json:"registered_gas_limit,string"` - ParentBeaconBlockRoot *phase0.Root `json:"parent_beacon_block_root,omitempty"` + RegisteredGasLimit uint64 + ParentBeaconBlockRoot *phase0.Root } -func (r *BuilderBlockValidationRequest) MarshalJSON() ([]byte, error) { - blockRequest, err := json.Marshal(r.VersionedSubmitBlockRequest) - if err != nil { - return nil, err - } +type capellaBuilderBlockValidationRequestJSON struct { + Message *builderApiV1.BidTrace `json:"message"` + ExecutionPayload *capella.ExecutionPayload `json:"execution_payload"` + Signature string `json:"signature"` + RegisteredGasLimit uint64 `json:"registered_gas_limit,string"` +} - attrs, err := json.Marshal(&struct { - RegisteredGasLimit uint64 `json:"registered_gas_limit,string"` - ParentBeaconBlockRoot *phase0.Root `json:"parent_beacon_block_root,omitempty"` - }{ - RegisteredGasLimit: r.RegisteredGasLimit, - ParentBeaconBlockRoot: r.ParentBeaconBlockRoot, - }) - if err != nil { - return nil, err +type denebBuilderBlockValidationRequestJSON struct { + Message *builderApiV1.BidTrace `json:"message"` + ExecutionPayload *deneb.ExecutionPayload `json:"execution_payload"` + BlobsBundle *builderApiDeneb.BlobsBundle `json:"blobs_bundle"` + Signature string `json:"signature"` + RegisteredGasLimit uint64 `json:"registered_gas_limit,string"` + ParentBeaconBlockRoot string `json:"parent_beacon_block_root"` +} + +func (r *BuilderBlockValidationRequest) MarshalJSON() ([]byte, error) { + switch r.Version { //nolint:exhaustive + case spec.DataVersionCapella: + return json.Marshal(&capellaBuilderBlockValidationRequestJSON{ + Message: r.Capella.Message, + ExecutionPayload: r.Capella.ExecutionPayload, + Signature: r.Capella.Signature.String(), + RegisteredGasLimit: r.RegisteredGasLimit, + }) + case spec.DataVersionDeneb: + return json.Marshal(&denebBuilderBlockValidationRequestJSON{ + Message: r.Deneb.Message, + ExecutionPayload: r.Deneb.ExecutionPayload, + BlobsBundle: r.Deneb.BlobsBundle, + Signature: r.Deneb.Signature.String(), + RegisteredGasLimit: r.RegisteredGasLimit, + ParentBeaconBlockRoot: r.ParentBeaconBlockRoot.String(), + }) + default: + return nil, errors.Wrap(ErrInvalidVersion, fmt.Sprintf("%s is not supported", r.Version)) } - attrs[0] = ',' - return append(blockRequest[:len(blockRequest)-1], attrs...), nil } type VersionedSubmitBlockRequest struct {