Skip to content

Commit

Permalink
update submit block request
Browse files Browse the repository at this point in the history
  • Loading branch information
avalonche committed Sep 29, 2023
1 parent 737c804 commit 7b2871c
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 25 deletions.
6 changes: 3 additions & 3 deletions common/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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{
Expand Down
18 changes: 11 additions & 7 deletions common/types_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,25 +269,29 @@ 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) {
blockRequest, err := json.Marshal(r.VersionedSubmitBlockRequest)
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 {
Expand Down
18 changes: 9 additions & 9 deletions database/database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -311,7 +311,7 @@ func TestInsertBuilderDemotion(t *testing.T) {

cases := []struct {
name string
req common.VersionedSubmitBlockRequest
req *common.VersionedSubmitBlockRequest
}{
{
name: "Capella",
Expand All @@ -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)
Expand Down Expand Up @@ -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{},
Expand All @@ -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: &eth2builderApiV1Deneb.SignedBlockContents{},
Expand All @@ -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.
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion services/api/blocksim_ratelimiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion services/api/optimistic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 6 additions & 4 deletions services/api/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
},
}
Expand Down

0 comments on commit 7b2871c

Please sign in to comment.