Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
avalonche committed Jul 20, 2023
1 parent 2b7359f commit a4d5c54
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
4 changes: 2 additions & 2 deletions database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
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 @@ -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)
Expand Down
13 changes: 8 additions & 5 deletions services/api/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 4 additions & 2 deletions services/api/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a4d5c54

Please sign in to comment.