diff --git a/database/database.go b/database/database.go index 47d31794..555da5f7 100644 --- a/database/database.go +++ b/database/database.go @@ -545,7 +545,7 @@ func (s *DatabaseService) DeleteExecutionPayloads(idFirst, idLast uint64) error } func (s *DatabaseService) InsertBuilderDemotion(submitBlockRequest *spec.VersionedSubmitBlockRequest, simError error) error { - _submitBlockRequest, err := json.Marshal(submitBlockRequest) + _submitBlockRequest, err := json.Marshal(submitBlockRequest.Capella) if err != nil { return err } @@ -578,7 +578,7 @@ func (s *DatabaseService) InsertBuilderDemotion(submitBlockRequest *spec.Version } func (s *DatabaseService) UpdateBuilderDemotion(trace *common.BidTraceV2, signedBlock *consensusspec.VersionedSignedBeaconBlock, signedRegistration *types.SignedValidatorRegistration) error { - _signedBeaconBlock, err := json.Marshal(signedBlock) + _signedBeaconBlock, err := json.Marshal(signedBlock.Capella) if err != nil { return err } diff --git a/services/api/optimistic_test.go b/services/api/optimistic_test.go index 9ff1e5c2..6cdcc489 100644 --- a/services/api/optimistic_test.go +++ b/services/api/optimistic_test.go @@ -144,7 +144,7 @@ func runOptimisticBlockSubmission(t *testing.T, opts blockRequestOpts, simErr er } req := common.TestBuilderSubmitBlockRequest(opts.secretkey, getTestBidTrace(opts.pubkey, opts.blockValue)) - rr := backend.request(http.MethodPost, pathSubmitNewBlock, &req) + rr := backend.request(http.MethodPost, pathSubmitNewBlock, req.Capella) // Let updates happen async. time.Sleep(100 * time.Millisecond) diff --git a/services/api/service.go b/services/api/service.go index 717d5551..27d559ca 100644 --- a/services/api/service.go +++ b/services/api/service.go @@ -19,7 +19,7 @@ import ( "strings" "sync" "time" - + consensusspec "github.com/attestantio/go-eth2-client/spec" "github.com/NYTimes/gziphandler" builderCapella "github.com/attestantio/go-builder-client/api/capella" "github.com/attestantio/go-builder-client/spec" @@ -1590,18 +1590,20 @@ func (api *RelayAPI) handleSubmitNewBlock(w http.ResponseWriter, req *http.Reque return } - payload := new(spec.VersionedSubmitBlockRequest) + payload := &spec.VersionedSubmitBlockRequest{ + Version: consensusspec.DataVersionCapella, + } + payload.Capella = new(builderCapella.SubmitBlockRequest) // Check for SSZ encoding contentType := req.Header.Get("Content-Type") if contentType == "application/octet-stream" { log = log.WithField("reqContentType", "ssz") - payload.Capella = new(builderCapella.SubmitBlockRequest) if err = payload.Capella.UnmarshalSSZ(requestPayloadBytes); err != nil { log.WithError(err).Warn("could not decode payload - SSZ") // SSZ decoding failed. try JSON as fallback (some builders used octet-stream for json before) - if err2 := json.Unmarshal(requestPayloadBytes, payload); err2 != nil { + if err2 := json.Unmarshal(requestPayloadBytes, payload.Capella); err2 != nil { log.WithError(fmt.Errorf("%w / %w", err, err2)).Warn("could not decode payload - SSZ or JSON") api.RespondError(w, http.StatusBadRequest, err.Error()) return @@ -1612,7 +1614,7 @@ func (api *RelayAPI) handleSubmitNewBlock(w http.ResponseWriter, req *http.Reque } } else { log = log.WithField("reqContentType", "json") - if err := json.Unmarshal(requestPayloadBytes, payload); err != nil { + if err := json.Unmarshal(requestPayloadBytes, payload.Capella); err != nil { log.WithError(err).Warn("could not decode payload - JSON") api.RespondError(w, http.StatusBadRequest, err.Error()) return @@ -1766,6 +1768,7 @@ func (api *RelayAPI) handleSubmitNewBlock(w http.ResponseWriter, req *http.Reque // Verify the signature log = log.WithField("timestampBeforeSignatureCheck", time.Now().UTC().UnixMilli()) signature := submission.Signature + fmt.Println(submission.BidTrace.String()) ok, err = boostTypes.VerifySignature(submission.BidTrace, api.opts.EthNetDetails.DomainBuilder, builderPubkey[:], signature[:]) log = log.WithField("timestampAfterSignatureCheck", time.Now().UTC().UnixMilli()) if err != nil { diff --git a/services/api/service_test.go b/services/api/service_test.go index 370d31a3..f55ed5e7 100644 --- a/services/api/service_test.go +++ b/services/api/service_test.go @@ -382,7 +382,8 @@ func TestBuilderSubmitBlockSSZ(t *testing.T) { requestPayloadJSONBytes := common.LoadGzippedBytes(t, "../../testdata/submitBlockPayloadCapella_Goerli.json.gz") req := new(spec.VersionedSubmitBlockRequest) - err := json.Unmarshal(requestPayloadJSONBytes, &req) + req.Capella = new(builderCapella.SubmitBlockRequest) + err := json.Unmarshal(requestPayloadJSONBytes, req.Capella) require.NoError(t, err) reqSSZ, err := req.Capella.MarshalSSZ() @@ -436,9 +437,10 @@ func TestBuilderSubmitBlock(t *testing.T) { // Prepare the request payload req := new(spec.VersionedSubmitBlockRequest) + req.Capella = new(builderCapella.SubmitBlockRequest) requestPayloadJSONBytes := common.LoadGzippedBytes(t, payloadJSONFilename) require.NoError(t, err) - err = json.Unmarshal(requestPayloadJSONBytes, &req) + err = json.Unmarshal(requestPayloadJSONBytes, req.Capella) require.NoError(t, err) // Update