Skip to content

Commit

Permalink
marshalling block validation request
Browse files Browse the repository at this point in the history
  • Loading branch information
avalonche committed Jan 30, 2024
1 parent 4ec3e77 commit de1c5e7
Showing 1 changed file with 38 additions and 18 deletions.
56 changes: 38 additions & 18 deletions common/types_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit de1c5e7

Please sign in to comment.