Skip to content

Commit 1127677

Browse files
authored
server: re-add bellatrix support (#725)
* server: re-add bellatrix support * Remove unnecessary type arguments
1 parent 1217436 commit 1127677

File tree

5 files changed

+264
-5
lines changed

5 files changed

+264
-5
lines changed

server/functionality.go

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
builderApi "github.com/attestantio/go-builder-client/api"
1313
denebApi "github.com/attestantio/go-builder-client/api/deneb"
1414
builderSpec "github.com/attestantio/go-builder-client/spec"
15+
eth2ApiV1Bellatrix "github.com/attestantio/go-eth2-client/api/v1/bellatrix"
1516
eth2ApiV1Capella "github.com/attestantio/go-eth2-client/api/v1/capella"
1617
eth2ApiV1Deneb "github.com/attestantio/go-eth2-client/api/v1/deneb"
1718
eth2ApiV1Electra "github.com/attestantio/go-eth2-client/api/v1/electra"
@@ -26,7 +27,8 @@ import (
2627
)
2728

2829
type Payload interface {
29-
*eth2ApiV1Capella.SignedBlindedBeaconBlock |
30+
*eth2ApiV1Bellatrix.SignedBlindedBeaconBlock |
31+
*eth2ApiV1Capella.SignedBlindedBeaconBlock |
3032
*eth2ApiV1Deneb.SignedBlindedBeaconBlock |
3133
*eth2ApiV1Electra.SignedBlindedBeaconBlock
3234
}
@@ -135,6 +137,13 @@ func processPayload[P Payload](m *BoostService, log *logrus.Entry, ua UserAgent,
135137
func verifyPayload[P Payload](payload P, log *logrus.Entry, response *builderApi.VersionedSubmitBlindedBlockResponse) error {
136138
// Step 1: verify version
137139
switch any(payload).(type) {
140+
case *eth2ApiV1Bellatrix.SignedBlindedBeaconBlock:
141+
if response.Version != spec.DataVersionBellatrix {
142+
log.WithFields(logrus.Fields{
143+
"version": response.Version,
144+
}).Error("response version was not bellatrix")
145+
return errInvalidVersion
146+
}
138147
case *eth2ApiV1Capella.SignedBlindedBeaconBlock:
139148
if response.Version != spec.DataVersionCapella {
140149
log.WithFields(logrus.Fields{
@@ -166,6 +175,10 @@ func verifyPayload[P Payload](payload P, log *logrus.Entry, response *builderApi
166175

167176
// Step 3: verify post-conditions
168177
switch block := any(payload).(type) {
178+
case *eth2ApiV1Bellatrix.SignedBlindedBeaconBlock:
179+
if err := verifyBlockhash(log, payload, response.Bellatrix.BlockHash); err != nil {
180+
return err
181+
}
169182
case *eth2ApiV1Capella.SignedBlindedBeaconBlock:
170183
if err := verifyBlockhash(log, payload, response.Capella.BlockHash); err != nil {
171184
return err
@@ -225,6 +238,14 @@ func verifyKZGCommitments(log *logrus.Entry, blobs *denebApi.BlobsBundle, commit
225238

226239
func prepareLogger[P Payload](log *logrus.Entry, payload P, userAgent UserAgent, slotUID string) *logrus.Entry {
227240
switch block := any(payload).(type) {
241+
case *eth2ApiV1Bellatrix.SignedBlindedBeaconBlock:
242+
return log.WithFields(logrus.Fields{
243+
"ua": userAgent,
244+
"slot": block.Message.Slot,
245+
"blockHash": block.Message.Body.ExecutionPayloadHeader.BlockHash.String(),
246+
"parentHash": block.Message.Body.ExecutionPayloadHeader.ParentHash.String(),
247+
"slotUID": slotUID,
248+
})
228249
case *eth2ApiV1Capella.SignedBlindedBeaconBlock:
229250
return log.WithFields(logrus.Fields{
230251
"ua": userAgent,
@@ -255,6 +276,8 @@ func prepareLogger[P Payload](log *logrus.Entry, payload P, userAgent UserAgent,
255276

256277
func slot[P Payload](payload P) uint64 {
257278
switch block := any(payload).(type) {
279+
case *eth2ApiV1Bellatrix.SignedBlindedBeaconBlock:
280+
return uint64(block.Message.Slot)
258281
case *eth2ApiV1Capella.SignedBlindedBeaconBlock:
259282
return uint64(block.Message.Slot)
260283
case *eth2ApiV1Deneb.SignedBlindedBeaconBlock:
@@ -267,6 +290,8 @@ func slot[P Payload](payload P) uint64 {
267290

268291
func blockHash[P Payload](payload P) phase0.Hash32 {
269292
switch block := any(payload).(type) {
293+
case *eth2ApiV1Bellatrix.SignedBlindedBeaconBlock:
294+
return block.Message.Body.ExecutionPayloadHeader.BlockHash
270295
case *eth2ApiV1Capella.SignedBlindedBeaconBlock:
271296
return block.Message.Body.ExecutionPayloadHeader.BlockHash
272297
case *eth2ApiV1Deneb.SignedBlindedBeaconBlock:

server/service.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717

1818
builderApi "github.com/attestantio/go-builder-client/api"
1919
builderApiV1 "github.com/attestantio/go-builder-client/api/v1"
20+
eth2ApiV1Bellatrix "github.com/attestantio/go-eth2-client/api/v1/bellatrix"
2021
eth2ApiV1Capella "github.com/attestantio/go-eth2-client/api/v1/capella"
2122
eth2ApiV1Deneb "github.com/attestantio/go-eth2-client/api/v1/deneb"
2223
eth2ApiV1Electra "github.com/attestantio/go-eth2-client/api/v1/electra"
@@ -382,21 +383,28 @@ func (m *BoostService) handleGetPayload(w http.ResponseWriter, req *http.Request
382383
fork: "Electra",
383384
payload: new(eth2ApiV1Electra.SignedBlindedBeaconBlock),
384385
processor: func(payload any) (*builderApi.VersionedSubmitBlindedBlockResponse, bidResp) {
385-
return processPayload[*eth2ApiV1Electra.SignedBlindedBeaconBlock](m, log, userAgent, payload.(*eth2ApiV1Electra.SignedBlindedBeaconBlock))
386+
return processPayload(m, log, userAgent, payload.(*eth2ApiV1Electra.SignedBlindedBeaconBlock))
386387
},
387388
},
388389
{
389390
fork: "Deneb",
390391
payload: new(eth2ApiV1Deneb.SignedBlindedBeaconBlock),
391392
processor: func(payload any) (*builderApi.VersionedSubmitBlindedBlockResponse, bidResp) {
392-
return processPayload[*eth2ApiV1Deneb.SignedBlindedBeaconBlock](m, log, userAgent, payload.(*eth2ApiV1Deneb.SignedBlindedBeaconBlock))
393+
return processPayload(m, log, userAgent, payload.(*eth2ApiV1Deneb.SignedBlindedBeaconBlock))
393394
},
394395
},
395396
{
396397
fork: "Capella",
397398
payload: new(eth2ApiV1Capella.SignedBlindedBeaconBlock),
398399
processor: func(payload any) (*builderApi.VersionedSubmitBlindedBlockResponse, bidResp) {
399-
return processPayload[*eth2ApiV1Capella.SignedBlindedBeaconBlock](m, log, userAgent, payload.(*eth2ApiV1Capella.SignedBlindedBeaconBlock))
400+
return processPayload(m, log, userAgent, payload.(*eth2ApiV1Capella.SignedBlindedBeaconBlock))
401+
},
402+
},
403+
{
404+
fork: "Bellatrix",
405+
payload: new(eth2ApiV1Bellatrix.SignedBlindedBeaconBlock),
406+
processor: func(payload any) (*builderApi.VersionedSubmitBlindedBlockResponse, bidResp) {
407+
return processPayload(m, log, userAgent, payload.(*eth2ApiV1Bellatrix.SignedBlindedBeaconBlock))
400408
},
401409
},
402410
}

server/service_test.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
builderApiDeneb "github.com/attestantio/go-builder-client/api/deneb"
1919
builderApiV1 "github.com/attestantio/go-builder-client/api/v1"
2020
builderSpec "github.com/attestantio/go-builder-client/spec"
21+
eth2ApiV1Bellatrix "github.com/attestantio/go-eth2-client/api/v1/bellatrix"
2122
eth2ApiV1Capella "github.com/attestantio/go-eth2-client/api/v1/capella"
2223
eth2ApiV1Deneb "github.com/attestantio/go-eth2-client/api/v1/deneb"
2324
eth2ApiV1Electra "github.com/attestantio/go-eth2-client/api/v1/electra"
@@ -92,6 +93,26 @@ func (be *testBackend) request(t *testing.T, method, path string, payload any) *
9293
return rr
9394
}
9495

96+
func blindedBlockToExecutionPayloadBellatrix(signedBlindedBeaconBlock *eth2ApiV1Bellatrix.SignedBlindedBeaconBlock) *bellatrix.ExecutionPayload {
97+
header := signedBlindedBeaconBlock.Message.Body.ExecutionPayloadHeader
98+
return &bellatrix.ExecutionPayload{
99+
ParentHash: header.ParentHash,
100+
FeeRecipient: header.FeeRecipient,
101+
StateRoot: header.StateRoot,
102+
ReceiptsRoot: header.ReceiptsRoot,
103+
LogsBloom: header.LogsBloom,
104+
PrevRandao: header.PrevRandao,
105+
BlockNumber: header.BlockNumber,
106+
GasLimit: header.GasLimit,
107+
GasUsed: header.GasUsed,
108+
Timestamp: header.Timestamp,
109+
ExtraData: header.ExtraData,
110+
BaseFeePerGas: header.BaseFeePerGas,
111+
BlockHash: header.BlockHash,
112+
Transactions: make([]bellatrix.Transaction, 0),
113+
}
114+
}
115+
95116
func blindedBlockToExecutionPayloadCapella(signedBlindedBeaconBlock *eth2ApiV1Capella.SignedBlindedBeaconBlock) *capella.ExecutionPayload {
96117
header := signedBlindedBeaconBlock.Message.Body.ExecutionPayloadHeader
97118
return &capella.ExecutionPayload{
@@ -849,6 +870,30 @@ func TestGetPayloadWithTestdata(t *testing.T) {
849870
}
850871
}
851872

873+
func TestGetPayloadBellatrix(t *testing.T) {
874+
// Load the signed blinded beacon block used for getPayload
875+
jsonFile, err := os.Open("../testdata/signed-blinded-beacon-block-bellatrix.json")
876+
require.NoError(t, err)
877+
defer jsonFile.Close()
878+
signedBlindedBeaconBlock := new(eth2ApiV1Bellatrix.SignedBlindedBeaconBlock)
879+
require.NoError(t, DecodeJSON(jsonFile, &signedBlindedBeaconBlock))
880+
backend := newTestBackend(t, 1, time.Second)
881+
// Prepare getPayload response
882+
backend.relays[0].GetPayloadResponse = &builderApi.VersionedSubmitBlindedBlockResponse{
883+
Version: spec.DataVersionBellatrix,
884+
Bellatrix: blindedBlockToExecutionPayloadBellatrix(signedBlindedBeaconBlock),
885+
}
886+
// call getPayload, ensure it's only called on relay 0 (origin of the bid)
887+
getPayloadPath := "/eth/v1/builder/blinded_blocks"
888+
rr := backend.request(t, http.MethodPost, getPayloadPath, signedBlindedBeaconBlock)
889+
require.Equal(t, http.StatusOK, rr.Code, rr.Body.String())
890+
require.Equal(t, 1, backend.relays[0].GetRequestCount(getPayloadPath))
891+
resp := new(builderApi.VersionedSubmitBlindedBlockResponse)
892+
err = json.Unmarshal(rr.Body.Bytes(), resp)
893+
require.NoError(t, err)
894+
require.Equal(t, signedBlindedBeaconBlock.Message.Body.ExecutionPayloadHeader.BlockHash, resp.Bellatrix.BlockHash)
895+
}
896+
852897
func TestGetPayloadCapella(t *testing.T) {
853898
// Load the signed blinded beacon block used for getPayload
854899
jsonFile, err := os.Open("../testdata/signed-blinded-beacon-block-capella.json")

server/utils.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,10 @@ func checkRelaySignature(bid *builderSpec.VersionedSignedBuilderBid, domain phas
242242

243243
func getPayloadResponseIsEmpty(payload *builderApi.VersionedSubmitBlindedBlockResponse) bool {
244244
switch payload.Version {
245+
case spec.DataVersionBellatrix:
246+
if payload.Bellatrix == nil || payload.Bellatrix.BlockHash == nilHash {
247+
return true
248+
}
245249
case spec.DataVersionCapella:
246250
if payload.Capella == nil || payload.Capella.BlockHash == nilHash {
247251
return true
@@ -258,7 +262,7 @@ func getPayloadResponseIsEmpty(payload *builderApi.VersionedSubmitBlindedBlockRe
258262
payload.Electra.BlobsBundle == nil {
259263
return true
260264
}
261-
case spec.DataVersionUnknown, spec.DataVersionPhase0, spec.DataVersionAltair, spec.DataVersionBellatrix:
265+
case spec.DataVersionUnknown, spec.DataVersionPhase0, spec.DataVersionAltair:
262266
return true
263267
}
264268
return false

0 commit comments

Comments
 (0)