diff --git a/common/test_utils.go b/common/test_utils.go index ffe787a4..88172418 100644 --- a/common/test_utils.go +++ b/common/test_utils.go @@ -78,11 +78,11 @@ var ValidPayloadRegisterValidator = builderApiV1.SignedValidatorRegistration{ "0xaf12df007a0c78abb5575067e5f8b089cfcc6227e4a91db7dd8cf517fe86fb944ead859f0781277d9b78c672e4a18c5d06368b603374673cf2007966cece9540f3a1b3f6f9e1bf421d779c4e8010368e6aac134649c7a009210780d401a778a5"), } -func TestBuilderSubmitBlockRequest(sk *bls.SecretKey, bid *BidTraceV2, version spec.DataVersion) VersionedSubmitBlockRequest { +func TestBuilderSubmitBlockRequest(sk *bls.SecretKey, bid *BidTraceV2, version spec.DataVersion) *VersionedSubmitBlockRequest { signature, err := ssz.SignMessage(bid, ssz.DomainBuilder, sk) check(err, " SignMessage: ", bid, sk) if version == spec.DataVersionDeneb { - return VersionedSubmitBlockRequest{ + return &VersionedSubmitBlockRequest{ VersionedSubmitBlockRequest: builderSpec.VersionedSubmitBlockRequest{ //nolint:exhaustruct Version: spec.DataVersionDeneb, Deneb: &builderApiDeneb.SubmitBlockRequest{ @@ -104,7 +104,7 @@ func TestBuilderSubmitBlockRequest(sk *bls.SecretKey, bid *BidTraceV2, version s }, } } - return VersionedSubmitBlockRequest{ + return &VersionedSubmitBlockRequest{ VersionedSubmitBlockRequest: builderSpec.VersionedSubmitBlockRequest{ //nolint:exhaustruct Version: spec.DataVersionCapella, Capella: &builderApiCapella.SubmitBlockRequest{ diff --git a/common/types_spec.go b/common/types_spec.go index 4cb7068e..33e786f8 100644 --- a/common/types_spec.go +++ b/common/types_spec.go @@ -269,8 +269,9 @@ func DenebUnblindSignedBlock(blindedBlock *eth2builderApiV1Deneb.SignedBlindedBe } type BuilderBlockValidationRequest struct { - VersionedSubmitBlockRequest - RegisteredGasLimit uint64 `json:"registered_gas_limit,string"` + *VersionedSubmitBlockRequest + RegisteredGasLimit uint64 `json:"registered_gas_limit,string"` + ParentBeaconBlockRoot *phase0.Root `json:"parent_beacon_block_root,omitempty"` } func (r *BuilderBlockValidationRequest) MarshalJSON() ([]byte, error) { @@ -278,16 +279,19 @@ func (r *BuilderBlockValidationRequest) MarshalJSON() ([]byte, error) { if err != nil { return nil, err } - gasLimit, err := json.Marshal(&struct { - 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, + RegisteredGasLimit: r.RegisteredGasLimit, + ParentBeaconBlockRoot: r.ParentBeaconBlockRoot, }) if err != nil { return nil, err } - gasLimit[0] = ',' - return append(blockRequest[:len(blockRequest)-1], gasLimit...), nil + attrs[0] = ',' + return append(blockRequest[:len(blockRequest)-1], attrs...), nil } type VersionedSubmitBlockRequest struct { diff --git a/database/database_test.go b/database/database_test.go index dcff78d2..3aded611 100644 --- a/database/database_test.go +++ b/database/database_test.go @@ -87,7 +87,7 @@ func insertTestBuilder(t *testing.T, db IDatabaseService) string { Value: uint256.NewInt(collateral), }, }, spec.DataVersionDeneb) - entry, err := db.SaveBuilderBlockSubmission(&req, nil, nil, time.Now(), time.Now().Add(time.Second), true, true, profile, optimisticSubmission) + entry, err := db.SaveBuilderBlockSubmission(req, nil, nil, time.Now(), time.Now().Add(time.Second), true, true, profile, optimisticSubmission) require.NoError(t, err) err = db.UpsertBlockBuilderEntryAfterSubmission(entry, false) require.NoError(t, err) @@ -311,7 +311,7 @@ func TestInsertBuilderDemotion(t *testing.T) { cases := []struct { name string - req common.VersionedSubmitBlockRequest + req *common.VersionedSubmitBlockRequest }{ { name: "Capella", @@ -326,7 +326,7 @@ func TestInsertBuilderDemotion(t *testing.T) { t.Run(c.name, func(t *testing.T) { db := resetDatabase(t) - err = db.InsertBuilderDemotion(&c.req, errFoo) + err = db.InsertBuilderDemotion(c.req, errFoo) require.NoError(t, err) entry, err := db.GetBuilderDemotion(trace) @@ -356,13 +356,13 @@ func TestUpdateBuilderDemotion(t *testing.T) { cases := []struct { name string - req common.VersionedSubmitBlockRequest - beaconBlock common.VersionedSignedBlockRequest + req *common.VersionedSubmitBlockRequest + beaconBlock *common.VersionedSignedBlockRequest }{ { name: "Capella", req: common.TestBuilderSubmitBlockRequest(sk, bt, spec.DataVersionCapella), - beaconBlock: common.VersionedSignedBlockRequest{ + beaconBlock: &common.VersionedSignedBlockRequest{ VersionedBlockRequest: eth2Api.VersionedBlockRequest{ Version: spec.DataVersionCapella, Capella: &capella.SignedBeaconBlock{}, @@ -371,7 +371,7 @@ func TestUpdateBuilderDemotion(t *testing.T) { }, { name: "Deneb", req: common.TestBuilderSubmitBlockRequest(sk, bt, spec.DataVersionDeneb), - beaconBlock: common.VersionedSignedBlockRequest{ + beaconBlock: &common.VersionedSignedBlockRequest{ VersionedBlockRequest: eth2Api.VersionedBlockRequest{ Version: spec.DataVersionDeneb, Deneb: ð2builderApiV1Deneb.SignedBlockContents{}, @@ -389,7 +389,7 @@ func TestUpdateBuilderDemotion(t *testing.T) { require.Nil(t, demotion) // Insert demotion - err = db.InsertBuilderDemotion(&c.req, errFoo) + err = db.InsertBuilderDemotion(c.req, errFoo) require.NoError(t, err) // Now demotion should show up. @@ -403,7 +403,7 @@ func TestUpdateBuilderDemotion(t *testing.T) { require.Empty(t, demotion.SignedValidatorRegistration.String) // Update demotion with the signedBlock and signedRegistration. - err = db.UpdateBuilderDemotion(bt, &c.beaconBlock, &builderApiV1.SignedValidatorRegistration{}) + err = db.UpdateBuilderDemotion(bt, c.beaconBlock, &builderApiV1.SignedValidatorRegistration{}) require.NoError(t, err) // Signed block and validation should now be valid and non-empty. diff --git a/services/api/blocksim_ratelimiter.go b/services/api/blocksim_ratelimiter.go index 9c7ddc77..4fa34129 100644 --- a/services/api/blocksim_ratelimiter.go +++ b/services/api/blocksim_ratelimiter.go @@ -75,7 +75,7 @@ func (b *BlockSimulationRateLimiter) Send(context context.Context, payload *comm return ErrNoCapellaPayload, nil } - submission, err := common.GetBlockSubmissionInfo(&payload.VersionedSubmitBlockRequest) + submission, err := common.GetBlockSubmissionInfo(payload.VersionedSubmitBlockRequest) if err != nil { return err, nil } diff --git a/services/api/optimistic_test.go b/services/api/optimistic_test.go index 3de8e1f5..e7ba468c 100644 --- a/services/api/optimistic_test.go +++ b/services/api/optimistic_test.go @@ -337,7 +337,7 @@ func TestDemoteBuilder(t *testing.T) { pubkey, secretkey, backend := startTestBackend(t) pkStr := pubkey.String() req := common.TestBuilderSubmitBlockRequest(secretkey, getTestBidTrace(*pubkey, collateral, slot), tc.version) - backend.relay.demoteBuilder(pkStr, &req, errFake) + backend.relay.demoteBuilder(pkStr, req, errFake) // Check status in db. builder, err := backend.relay.db.GetBlockBuilderByPubkey(pkStr) diff --git a/services/api/service.go b/services/api/service.go index dc67b019..bab3020d 100644 --- a/services/api/service.go +++ b/services/api/service.go @@ -625,7 +625,7 @@ func (api *RelayAPI) processOptimisticBlock(opts blockSimOptions, simResultC cha defer api.optimisticBlocksWG.Done() ctx := context.Background() - submission, err := common.GetBlockSubmissionInfo(&opts.req.VersionedSubmitBlockRequest) + submission, err := common.GetBlockSubmissionInfo(opts.req.VersionedSubmitBlockRequest) if err != nil { opts.log.WithError(err).Error("error getting block submission info") return @@ -653,7 +653,7 @@ func (api *RelayAPI) processOptimisticBlock(opts blockSimOptions, simResultC cha } // Demote the builder. - api.demoteBuilder(builderPubkey, &opts.req.VersionedSubmitBlockRequest, demotionErr) + api.demoteBuilder(builderPubkey, opts.req.VersionedSubmitBlockRequest, demotionErr) } } @@ -1164,7 +1164,7 @@ func (api *RelayAPI) handleGetHeader(w http.ResponseWriter, req *http.Request) { return } - if bid.IsEmpty() { + if bid == nil || bid.IsEmpty() { w.WriteHeader(http.StatusNoContent) return } @@ -1608,6 +1608,8 @@ func (api *RelayAPI) checkSubmissionPayloadAttrs(w http.ResponseWriter, log *log attrs, ok := api.payloadAttributes[submission.ParentHash.String()] api.payloadAttributesLock.RUnlock() if !ok || submission.Slot != attrs.slot { + log.Info(ok) + log.Info("payload", submission.Slot, "attrs", attrs.slot) log.Warn("payload attributes not (yet) known") api.RespondError(w, http.StatusBadRequest, "payload attributes not (yet) known") return false @@ -2059,7 +2061,7 @@ func (api *RelayAPI) handleSubmitNewBlock(w http.ResponseWriter, req *http.Reque log: log, builder: builderEntry, req: &common.BuilderBlockValidationRequest{ - VersionedSubmitBlockRequest: *payload, + VersionedSubmitBlockRequest: payload, RegisteredGasLimit: gasLimit, }, }