Skip to content

Commit

Permalink
Remove submit block request wrapper (#485)
Browse files Browse the repository at this point in the history
* remove submit block request wrapper types

* fix tests

* fix lint
  • Loading branch information
avalonche authored Jul 26, 2023
1 parent bf14103 commit f923651
Show file tree
Hide file tree
Showing 18 changed files with 362 additions and 318 deletions.
1 change: 1 addition & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ linters-settings:
gomoddirectives:
replace-allow-list:
- github.com/attestantio/go-eth2-client
- github.com/attestantio/go-builder-client

maintidx:
under: 5
Expand Down
7 changes: 5 additions & 2 deletions common/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"testing"

"github.com/attestantio/go-builder-client/api/capella"
"github.com/attestantio/go-builder-client/spec"
consensusspec "github.com/attestantio/go-eth2-client/spec"
"github.com/attestantio/go-eth2-client/spec/bellatrix"
consensuscapella "github.com/attestantio/go-eth2-client/spec/capella"
"github.com/flashbots/go-boost-utils/bls"
Expand Down Expand Up @@ -64,10 +66,11 @@ var ValidPayloadRegisterValidator = boostTypes.SignedValidatorRegistration{
"0xaf12df007a0c78abb5575067e5f8b089cfcc6227e4a91db7dd8cf517fe86fb944ead859f0781277d9b78c672e4a18c5d06368b603374673cf2007966cece9540f3a1b3f6f9e1bf421d779c4e8010368e6aac134649c7a009210780d401a778a5"),
}

func TestBuilderSubmitBlockRequest(sk *bls.SecretKey, bid *BidTraceV2) BuilderSubmitBlockRequest {
func TestBuilderSubmitBlockRequest(sk *bls.SecretKey, bid *BidTraceV2) spec.VersionedSubmitBlockRequest {
signature, err := boostTypes.SignMessage(bid, boostTypes.DomainBuilder, sk)
check(err, " SignMessage: ", bid, sk)
return BuilderSubmitBlockRequest{
return spec.VersionedSubmitBlockRequest{ //nolint:exhaustruct
Version: consensusspec.DataVersionCapella,
Capella: &capella.SubmitBlockRequest{
Message: &bid.BidTrace,
Signature: [96]byte(signature),
Expand Down
188 changes: 21 additions & 167 deletions common/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@ import (
"encoding/json"
"errors"
"fmt"
"math/big"
"os"

"github.com/attestantio/go-builder-client/api"
"github.com/attestantio/go-builder-client/api/capella"
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"
"github.com/attestantio/go-eth2-client/spec/phase0"
boostTypes "github.com/flashbots/go-boost-utils/types"
"github.com/holiman/uint256"
)

var (
Expand Down Expand Up @@ -271,167 +269,23 @@ func (b *BidTraceV2WithTimestampJSON) ToCSVRecord() []string {
}
}

type BuilderSubmitBlockRequest struct {
Capella *capella.SubmitBlockRequest
}

func (b *BuilderSubmitBlockRequest) MarshalJSON() ([]byte, error) {
if b.Capella != nil {
return json.Marshal(b.Capella)
}
return nil, ErrEmptyPayload
}

func (b *BuilderSubmitBlockRequest) UnmarshalJSON(data []byte) error {
capella := new(capella.SubmitBlockRequest)
err := json.Unmarshal(data, capella)
if err != nil {
return err
}
b.Capella = capella
return nil
}

func (b *BuilderSubmitBlockRequest) HasExecutionPayload() bool {
if b.Capella != nil {
return b.Capella.ExecutionPayload != nil
}
return false
}

func (b *BuilderSubmitBlockRequest) ExecutionPayloadResponse() (*api.VersionedExecutionPayload, error) {
if b.Capella != nil {
return &api.VersionedExecutionPayload{
Version: consensusspec.DataVersionCapella,
Capella: b.Capella.ExecutionPayload,
}, nil
}

return nil, ErrEmptyPayload
}

func (b *BuilderSubmitBlockRequest) Slot() uint64 {
if b.Capella != nil {
return b.Capella.Message.Slot
}
return 0
}

func (b *BuilderSubmitBlockRequest) BlockHash() string {
if b.Capella != nil {
return b.Capella.Message.BlockHash.String()
}
return ""
}

func (b *BuilderSubmitBlockRequest) ExecutionPayloadBlockHash() string {
if b.Capella != nil {
return b.Capella.ExecutionPayload.BlockHash.String()
}
return ""
}

func (b *BuilderSubmitBlockRequest) BuilderPubkey() phase0.BLSPubKey {
if b.Capella != nil {
return b.Capella.Message.BuilderPubkey
}
return phase0.BLSPubKey{}
}

func (b *BuilderSubmitBlockRequest) ProposerFeeRecipient() string {
if b.Capella != nil {
return b.Capella.Message.ProposerFeeRecipient.String()
}
return ""
}

func (b *BuilderSubmitBlockRequest) Timestamp() uint64 {
if b.Capella != nil {
return b.Capella.ExecutionPayload.Timestamp
}
return 0
}

func (b *BuilderSubmitBlockRequest) ProposerPubkey() string {
if b.Capella != nil {
return b.Capella.Message.ProposerPubkey.String()
}
return ""
}

func (b *BuilderSubmitBlockRequest) ParentHash() string {
if b.Capella != nil {
return b.Capella.Message.ParentHash.String()
}
return ""
}

func (b *BuilderSubmitBlockRequest) ExecutionPayloadParentHash() string {
if b.Capella != nil {
return b.Capella.ExecutionPayload.ParentHash.String()
}
return ""
}

func (b *BuilderSubmitBlockRequest) Value() *big.Int {
if b.Capella != nil {
return b.Capella.Message.Value.ToBig()
}
return nil
}

func (b *BuilderSubmitBlockRequest) NumTx() int {
if b.Capella != nil {
return len(b.Capella.ExecutionPayload.Transactions)
}
return 0
}

func (b *BuilderSubmitBlockRequest) BlockNumber() uint64 {
if b.Capella != nil {
return b.Capella.ExecutionPayload.BlockNumber
}
return 0
}

func (b *BuilderSubmitBlockRequest) GasUsed() uint64 {
if b.Capella != nil {
return b.Capella.ExecutionPayload.GasUsed
}
return 0
}

func (b *BuilderSubmitBlockRequest) GasLimit() uint64 {
if b.Capella != nil {
return b.Capella.ExecutionPayload.GasLimit
}
return 0
}

func (b *BuilderSubmitBlockRequest) Signature() phase0.BLSSignature {
if b.Capella != nil {
return b.Capella.Signature
}
return phase0.BLSSignature{}
}

func (b *BuilderSubmitBlockRequest) Random() string {
if b.Capella != nil {
return fmt.Sprintf("%#x", b.Capella.ExecutionPayload.PrevRandao)
}
return ""
}

func (b *BuilderSubmitBlockRequest) Message() *apiv1.BidTrace {
if b.Capella != nil {
return b.Capella.Message
}
return nil
}

func (b *BuilderSubmitBlockRequest) Withdrawals() []*consensuscapella.Withdrawal {
if b.Capella != nil {
return b.Capella.ExecutionPayload.Withdrawals
}
return nil
type BlockSubmissionInfo struct {
BidTrace *apiv1.BidTrace
Slot uint64
BlockHash phase0.Hash32
ParentHash phase0.Hash32
ExecutionPayloadBlockHash phase0.Hash32
ExecutionPayloadParentHash phase0.Hash32
Builder phase0.BLSPubKey
Proposer phase0.BLSPubKey
ProposerFeeRecipient consensusbellatrix.ExecutionAddress
GasUsed uint64
GasLimit uint64
Timestamp uint64
BlockNumber uint64
Value *uint256.Int
PrevRandao phase0.Hash32
Signature phase0.BLSSignature
Transactions []consensusbellatrix.Transaction
Withdrawals []*consensuscapella.Withdrawal
}
20 changes: 15 additions & 5 deletions common/types_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package common

import (
"encoding/json"
"errors"
"fmt"

"github.com/attestantio/go-builder-client/api"
"github.com/attestantio/go-builder-client/api/capella"
Expand All @@ -15,12 +15,14 @@ import (
utilcapella "github.com/attestantio/go-eth2-client/util/capella"
"github.com/flashbots/go-boost-utils/bls"
boostTypes "github.com/flashbots/go-boost-utils/types"
"github.com/pkg/errors"
)

var (
ErrMissingRequest = errors.New("req is nil")
ErrMissingSecretKey = errors.New("secret key is nil")
ErrInvalidTransaction = errors.New("invalid transaction")
ErrInvalidVersion = errors.New("invalid version")
)

type HTTPErrorResp struct {
Expand All @@ -32,7 +34,7 @@ var NilResponse = struct{}{}

var ZeroU256 = boostTypes.IntToU256(0)

func BuildGetHeaderResponse(payload *BuilderSubmitBlockRequest, sk *bls.SecretKey, pubkey *boostTypes.PublicKey, domain boostTypes.Domain) (*spec.VersionedSignedBuilderBid, error) {
func BuildGetHeaderResponse(payload *spec.VersionedSubmitBlockRequest, sk *bls.SecretKey, pubkey *boostTypes.PublicKey, domain boostTypes.Domain) (*spec.VersionedSignedBuilderBid, error) {
if payload == nil {
return nil, ErrMissingRequest
}
Expand All @@ -55,7 +57,7 @@ func BuildGetHeaderResponse(payload *BuilderSubmitBlockRequest, sk *bls.SecretKe
return nil, ErrEmptyPayload
}

func BuildGetPayloadResponse(payload *BuilderSubmitBlockRequest) (*api.VersionedExecutionPayload, error) {
func BuildGetPayloadResponse(payload *spec.VersionedSubmitBlockRequest) (*api.VersionedExecutionPayload, error) {
if payload.Capella != nil {
return &api.VersionedExecutionPayload{
Version: consensusspec.DataVersionCapella,
Expand Down Expand Up @@ -179,12 +181,20 @@ func SignedBlindedBeaconBlockToBeaconBlock(signedBlindedBeaconBlock *consensusap
}

type BuilderBlockValidationRequest struct {
BuilderSubmitBlockRequest
spec.VersionedSubmitBlockRequest
RegisteredGasLimit uint64 `json:"registered_gas_limit,string"`
}

func (r *BuilderBlockValidationRequest) MarshalJSON() ([]byte, error) {
blockRequest, err := r.BuilderSubmitBlockRequest.MarshalJSON()
var blockRequest []byte
var err error

switch r.VersionedSubmitBlockRequest.Version { //nolint:exhaustive
case consensusspec.DataVersionCapella:
blockRequest, err = r.VersionedSubmitBlockRequest.Capella.MarshalJSON()
default:
return nil, errors.Wrap(ErrInvalidVersion, fmt.Sprintf("%d is not supported", r.VersionedSubmitBlockRequest.Version))
}
if err != nil {
return nil, err
}
Expand Down
Loading

0 comments on commit f923651

Please sign in to comment.