Skip to content

Commit 61595f0

Browse files
committed
Only commit to saving payload once the relay has confirmed it is available
1 parent d8a0d7b commit 61595f0

File tree

1 file changed

+32
-33
lines changed

1 file changed

+32
-33
lines changed

services/api/service.go

+32-33
Original file line numberDiff line numberDiff line change
@@ -1361,6 +1361,38 @@ func (api *RelayAPI) handleGetPayload(w http.ResponseWriter, req *http.Request)
13611361
var getPayloadResp *builderApi.VersionedSubmitBlindedBlockResponse
13621362
var msNeededForPublishing uint64
13631363

1364+
// Get the response - from Redis, Memcache or DB
1365+
getPayloadResp, err = api.datastore.GetGetPayloadResponse(log, uint64(slot), proposerPubkey.String(), blockHash.String())
1366+
if err != nil || getPayloadResp == nil {
1367+
log.WithError(err).Warn("failed getting execution payload (1/2)")
1368+
time.Sleep(time.Duration(timeoutGetPayloadRetryMs) * time.Millisecond)
1369+
1370+
// Try again
1371+
getPayloadResp, err = api.datastore.GetGetPayloadResponse(log, uint64(slot), proposerPubkey.String(), blockHash.String())
1372+
if err != nil || getPayloadResp == nil {
1373+
// Still not found! Error out now.
1374+
if errors.Is(err, datastore.ErrExecutionPayloadNotFound) {
1375+
// Couldn't find the execution payload, maybe it never was submitted to our relay! Check that now
1376+
_, err := api.db.GetBlockSubmissionEntry(uint64(slot), proposerPubkey.String(), blockHash.String())
1377+
if errors.Is(err, sql.ErrNoRows) {
1378+
log.Warn("failed getting execution payload (2/2) - payload not found, block was never submitted to this relay")
1379+
api.RespondError(w, http.StatusBadRequest, "no execution payload for this request - block was never seen by this relay")
1380+
} else if err != nil {
1381+
log.WithError(err).Error("failed getting execution payload (2/2) - payload not found, and error on checking bids")
1382+
} else {
1383+
log.Error("failed getting execution payload (2/2) - payload not found, but found bid in database")
1384+
}
1385+
} else { // some other error
1386+
log.WithError(err).Error("failed getting execution payload (2/2) - error")
1387+
}
1388+
api.RespondError(w, http.StatusBadRequest, "no execution payload for this request")
1389+
return
1390+
}
1391+
}
1392+
1393+
// Now we know this relay also has the payload
1394+
log = log.WithField("timestampAfterLoadResponse", time.Now().UTC().UnixMilli())
1395+
13641396
// Save information about delivered payload
13651397
defer func() {
13661398
bidTrace, err := api.redis.GetBidTrace(uint64(slot), proposerPubkey.String(), blockHash.String())
@@ -1442,39 +1474,6 @@ func (api *RelayAPI) handleGetPayload(w http.ResponseWriter, req *http.Request)
14421474
}
14431475
}()
14441476

1445-
// Get the response - from Redis, Memcache or DB
1446-
// note that recent mev-boost versions only send getPayload to relays that provided the bid
1447-
getPayloadResp, err = api.datastore.GetGetPayloadResponse(log, uint64(slot), proposerPubkey.String(), blockHash.String())
1448-
if err != nil || getPayloadResp == nil {
1449-
log.WithError(err).Warn("failed getting execution payload (1/2)")
1450-
time.Sleep(time.Duration(timeoutGetPayloadRetryMs) * time.Millisecond)
1451-
1452-
// Try again
1453-
getPayloadResp, err = api.datastore.GetGetPayloadResponse(log, uint64(slot), proposerPubkey.String(), blockHash.String())
1454-
if err != nil || getPayloadResp == nil {
1455-
// Still not found! Error out now.
1456-
if errors.Is(err, datastore.ErrExecutionPayloadNotFound) {
1457-
// Couldn't find the execution payload, maybe it never was submitted to our relay! Check that now
1458-
_, err := api.db.GetBlockSubmissionEntry(uint64(slot), proposerPubkey.String(), blockHash.String())
1459-
if errors.Is(err, sql.ErrNoRows) {
1460-
log.Warn("failed getting execution payload (2/2) - payload not found, block was never submitted to this relay")
1461-
api.RespondError(w, http.StatusBadRequest, "no execution payload for this request - block was never seen by this relay")
1462-
} else if err != nil {
1463-
log.WithError(err).Error("failed getting execution payload (2/2) - payload not found, and error on checking bids")
1464-
} else {
1465-
log.Error("failed getting execution payload (2/2) - payload not found, but found bid in database")
1466-
}
1467-
} else { // some other error
1468-
log.WithError(err).Error("failed getting execution payload (2/2) - error")
1469-
}
1470-
api.RespondError(w, http.StatusBadRequest, "no execution payload for this request")
1471-
return
1472-
}
1473-
}
1474-
1475-
// Now we know this relay also has the payload
1476-
log = log.WithField("timestampAfterLoadResponse", time.Now().UTC().UnixMilli())
1477-
14781477
// Check whether getPayload has already been called -- TODO: do we need to allow multiple submissions of one blinded block?
14791478
err = api.redis.CheckAndSetLastSlotAndHashDelivered(uint64(slot), blockHash.String())
14801479
log = log.WithField("timestampAfterAlreadyDeliveredCheck", time.Now().UTC().UnixMilli())

0 commit comments

Comments
 (0)