Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion server/functionality.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
builderApi "github.com/attestantio/go-builder-client/api"
denebApi "github.com/attestantio/go-builder-client/api/deneb"
builderSpec "github.com/attestantio/go-builder-client/spec"
eth2ApiV1Bellatrix "github.com/attestantio/go-eth2-client/api/v1/bellatrix"
eth2ApiV1Capella "github.com/attestantio/go-eth2-client/api/v1/capella"
eth2ApiV1Deneb "github.com/attestantio/go-eth2-client/api/v1/deneb"
eth2ApiV1Electra "github.com/attestantio/go-eth2-client/api/v1/electra"
Expand All @@ -26,7 +27,8 @@ import (
)

type Payload interface {
*eth2ApiV1Capella.SignedBlindedBeaconBlock |
*eth2ApiV1Bellatrix.SignedBlindedBeaconBlock |
*eth2ApiV1Capella.SignedBlindedBeaconBlock |
*eth2ApiV1Deneb.SignedBlindedBeaconBlock |
*eth2ApiV1Electra.SignedBlindedBeaconBlock
}
Expand Down Expand Up @@ -135,6 +137,13 @@ func processPayload[P Payload](m *BoostService, log *logrus.Entry, ua UserAgent,
func verifyPayload[P Payload](payload P, log *logrus.Entry, response *builderApi.VersionedSubmitBlindedBlockResponse) error {
// Step 1: verify version
switch any(payload).(type) {
case *eth2ApiV1Bellatrix.SignedBlindedBeaconBlock:
if response.Version != spec.DataVersionBellatrix {
log.WithFields(logrus.Fields{
"version": response.Version,
}).Error("response version was not bellatrix")
return errInvalidVersion
}
case *eth2ApiV1Capella.SignedBlindedBeaconBlock:
if response.Version != spec.DataVersionCapella {
log.WithFields(logrus.Fields{
Expand Down Expand Up @@ -166,6 +175,10 @@ func verifyPayload[P Payload](payload P, log *logrus.Entry, response *builderApi

// Step 3: verify post-conditions
switch block := any(payload).(type) {
case *eth2ApiV1Bellatrix.SignedBlindedBeaconBlock:
if err := verifyBlockhash(log, payload, response.Bellatrix.BlockHash); err != nil {
return err
}
case *eth2ApiV1Capella.SignedBlindedBeaconBlock:
if err := verifyBlockhash(log, payload, response.Capella.BlockHash); err != nil {
return err
Expand Down Expand Up @@ -225,6 +238,14 @@ func verifyKZGCommitments(log *logrus.Entry, blobs *denebApi.BlobsBundle, commit

func prepareLogger[P Payload](log *logrus.Entry, payload P, userAgent UserAgent, slotUID string) *logrus.Entry {
switch block := any(payload).(type) {
case *eth2ApiV1Bellatrix.SignedBlindedBeaconBlock:
return log.WithFields(logrus.Fields{
"ua": userAgent,
"slot": block.Message.Slot,
"blockHash": block.Message.Body.ExecutionPayloadHeader.BlockHash.String(),
"parentHash": block.Message.Body.ExecutionPayloadHeader.ParentHash.String(),
"slotUID": slotUID,
})
case *eth2ApiV1Capella.SignedBlindedBeaconBlock:
return log.WithFields(logrus.Fields{
"ua": userAgent,
Expand Down Expand Up @@ -255,6 +276,8 @@ func prepareLogger[P Payload](log *logrus.Entry, payload P, userAgent UserAgent,

func slot[P Payload](payload P) uint64 {
switch block := any(payload).(type) {
case *eth2ApiV1Bellatrix.SignedBlindedBeaconBlock:
return uint64(block.Message.Slot)
case *eth2ApiV1Capella.SignedBlindedBeaconBlock:
return uint64(block.Message.Slot)
case *eth2ApiV1Deneb.SignedBlindedBeaconBlock:
Expand All @@ -267,6 +290,8 @@ func slot[P Payload](payload P) uint64 {

func blockHash[P Payload](payload P) phase0.Hash32 {
switch block := any(payload).(type) {
case *eth2ApiV1Bellatrix.SignedBlindedBeaconBlock:
return block.Message.Body.ExecutionPayloadHeader.BlockHash
case *eth2ApiV1Capella.SignedBlindedBeaconBlock:
return block.Message.Body.ExecutionPayloadHeader.BlockHash
case *eth2ApiV1Deneb.SignedBlindedBeaconBlock:
Expand Down
14 changes: 11 additions & 3 deletions server/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (

builderApi "github.com/attestantio/go-builder-client/api"
builderApiV1 "github.com/attestantio/go-builder-client/api/v1"
eth2ApiV1Bellatrix "github.com/attestantio/go-eth2-client/api/v1/bellatrix"
eth2ApiV1Capella "github.com/attestantio/go-eth2-client/api/v1/capella"
eth2ApiV1Deneb "github.com/attestantio/go-eth2-client/api/v1/deneb"
eth2ApiV1Electra "github.com/attestantio/go-eth2-client/api/v1/electra"
Expand Down Expand Up @@ -382,21 +383,28 @@ func (m *BoostService) handleGetPayload(w http.ResponseWriter, req *http.Request
fork: "Electra",
payload: new(eth2ApiV1Electra.SignedBlindedBeaconBlock),
processor: func(payload any) (*builderApi.VersionedSubmitBlindedBlockResponse, bidResp) {
return processPayload[*eth2ApiV1Electra.SignedBlindedBeaconBlock](m, log, userAgent, payload.(*eth2ApiV1Electra.SignedBlindedBeaconBlock))
return processPayload(m, log, userAgent, payload.(*eth2ApiV1Electra.SignedBlindedBeaconBlock))
},
},
{
fork: "Deneb",
payload: new(eth2ApiV1Deneb.SignedBlindedBeaconBlock),
processor: func(payload any) (*builderApi.VersionedSubmitBlindedBlockResponse, bidResp) {
return processPayload[*eth2ApiV1Deneb.SignedBlindedBeaconBlock](m, log, userAgent, payload.(*eth2ApiV1Deneb.SignedBlindedBeaconBlock))
return processPayload(m, log, userAgent, payload.(*eth2ApiV1Deneb.SignedBlindedBeaconBlock))
},
},
{
fork: "Capella",
payload: new(eth2ApiV1Capella.SignedBlindedBeaconBlock),
processor: func(payload any) (*builderApi.VersionedSubmitBlindedBlockResponse, bidResp) {
return processPayload[*eth2ApiV1Capella.SignedBlindedBeaconBlock](m, log, userAgent, payload.(*eth2ApiV1Capella.SignedBlindedBeaconBlock))
return processPayload(m, log, userAgent, payload.(*eth2ApiV1Capella.SignedBlindedBeaconBlock))
},
},
{
fork: "Bellatrix",
payload: new(eth2ApiV1Bellatrix.SignedBlindedBeaconBlock),
processor: func(payload any) (*builderApi.VersionedSubmitBlindedBlockResponse, bidResp) {
return processPayload(m, log, userAgent, payload.(*eth2ApiV1Bellatrix.SignedBlindedBeaconBlock))
},
},
}
Expand Down
45 changes: 45 additions & 0 deletions server/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
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"
eth2ApiV1Bellatrix "github.com/attestantio/go-eth2-client/api/v1/bellatrix"
eth2ApiV1Capella "github.com/attestantio/go-eth2-client/api/v1/capella"
eth2ApiV1Deneb "github.com/attestantio/go-eth2-client/api/v1/deneb"
eth2ApiV1Electra "github.com/attestantio/go-eth2-client/api/v1/electra"
Expand Down Expand Up @@ -92,6 +93,26 @@ func (be *testBackend) request(t *testing.T, method, path string, payload any) *
return rr
}

func blindedBlockToExecutionPayloadBellatrix(signedBlindedBeaconBlock *eth2ApiV1Bellatrix.SignedBlindedBeaconBlock) *bellatrix.ExecutionPayload {
header := signedBlindedBeaconBlock.Message.Body.ExecutionPayloadHeader
return &bellatrix.ExecutionPayload{
ParentHash: header.ParentHash,
FeeRecipient: header.FeeRecipient,
StateRoot: header.StateRoot,
ReceiptsRoot: header.ReceiptsRoot,
LogsBloom: header.LogsBloom,
PrevRandao: header.PrevRandao,
BlockNumber: header.BlockNumber,
GasLimit: header.GasLimit,
GasUsed: header.GasUsed,
Timestamp: header.Timestamp,
ExtraData: header.ExtraData,
BaseFeePerGas: header.BaseFeePerGas,
BlockHash: header.BlockHash,
Transactions: make([]bellatrix.Transaction, 0),
}
}

func blindedBlockToExecutionPayloadCapella(signedBlindedBeaconBlock *eth2ApiV1Capella.SignedBlindedBeaconBlock) *capella.ExecutionPayload {
header := signedBlindedBeaconBlock.Message.Body.ExecutionPayloadHeader
return &capella.ExecutionPayload{
Expand Down Expand Up @@ -849,6 +870,30 @@ func TestGetPayloadWithTestdata(t *testing.T) {
}
}

func TestGetPayloadBellatrix(t *testing.T) {
// Load the signed blinded beacon block used for getPayload
jsonFile, err := os.Open("../testdata/signed-blinded-beacon-block-bellatrix.json")
require.NoError(t, err)
defer jsonFile.Close()
signedBlindedBeaconBlock := new(eth2ApiV1Bellatrix.SignedBlindedBeaconBlock)
require.NoError(t, DecodeJSON(jsonFile, &signedBlindedBeaconBlock))
backend := newTestBackend(t, 1, time.Second)
// Prepare getPayload response
backend.relays[0].GetPayloadResponse = &builderApi.VersionedSubmitBlindedBlockResponse{
Version: spec.DataVersionBellatrix,
Bellatrix: blindedBlockToExecutionPayloadBellatrix(signedBlindedBeaconBlock),
}
// call getPayload, ensure it's only called on relay 0 (origin of the bid)
getPayloadPath := "/eth/v1/builder/blinded_blocks"
rr := backend.request(t, http.MethodPost, getPayloadPath, signedBlindedBeaconBlock)
require.Equal(t, http.StatusOK, rr.Code, rr.Body.String())
require.Equal(t, 1, backend.relays[0].GetRequestCount(getPayloadPath))
resp := new(builderApi.VersionedSubmitBlindedBlockResponse)
err = json.Unmarshal(rr.Body.Bytes(), resp)
require.NoError(t, err)
require.Equal(t, signedBlindedBeaconBlock.Message.Body.ExecutionPayloadHeader.BlockHash, resp.Bellatrix.BlockHash)
}

func TestGetPayloadCapella(t *testing.T) {
// Load the signed blinded beacon block used for getPayload
jsonFile, err := os.Open("../testdata/signed-blinded-beacon-block-capella.json")
Expand Down
6 changes: 5 additions & 1 deletion server/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,10 @@ func checkRelaySignature(bid *builderSpec.VersionedSignedBuilderBid, domain phas

func getPayloadResponseIsEmpty(payload *builderApi.VersionedSubmitBlindedBlockResponse) bool {
switch payload.Version {
case spec.DataVersionBellatrix:
if payload.Bellatrix == nil || payload.Bellatrix.BlockHash == nilHash {
return true
}
case spec.DataVersionCapella:
if payload.Capella == nil || payload.Capella.BlockHash == nilHash {
return true
Expand All @@ -258,7 +262,7 @@ func getPayloadResponseIsEmpty(payload *builderApi.VersionedSubmitBlindedBlockRe
payload.Electra.BlobsBundle == nil {
return true
}
case spec.DataVersionUnknown, spec.DataVersionPhase0, spec.DataVersionAltair, spec.DataVersionBellatrix:
case spec.DataVersionUnknown, spec.DataVersionPhase0, spec.DataVersionAltair:
return true
}
return false
Expand Down
Loading
Loading