Skip to content

Commit 7cfb628

Browse files
authored
chore: Tag logs with the relay URLs in getPayload (#859)
* create new log instance for each relay invocation in getPayload * update innerlog in retry loop
1 parent 943bac8 commit 7cfb628

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

server/get_payload.go

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,11 @@ func (m *BoostService) innerGetPayload(log *logrus.Entry, signedBlindedBeaconBlo
163163
} else {
164164
url = relay.GetURI(params.PathGetPayloadV2)
165165
}
166+
innerLog := log.WithField("url", url)
166167

167168
// If the request fails, try again a few times with 100ms between tries
168169
resp, err := retry(requestCtx, m.requestMaxRetries, 100*time.Millisecond, func() (*http.Response, error) {
169-
log = log.WithField("url", url)
170-
170+
innerLog = innerLog.WithField("url", url)
171171
// Default to the content from the proposer
172172
requestContentType := parsedProposerContentType
173173
requestBytes := signedBlindedBeaconBlockBytes
@@ -180,7 +180,7 @@ func (m *BoostService) innerGetPayload(log *logrus.Entry, signedBlindedBeaconBlo
180180
break
181181
}
182182
}
183-
log.WithField("relaySupportsSSZ", relaySupportsSSZ).Debug("encoding preference")
183+
innerLog.WithField("relaySupportsSSZ", relaySupportsSSZ).Debug("encoding preference")
184184

185185
// If the relay provided the bid in JSON or did not provide a bid for this payload,
186186
// we must convert the signed blinded beacon block from SSZ to JSON for this relay
@@ -189,23 +189,23 @@ func (m *BoostService) innerGetPayload(log *logrus.Entry, signedBlindedBeaconBlo
189189
startTime := time.Now()
190190
requestBytes, err = convertSSZToJSON(proposerEthConsensusVersion, signedBlindedBeaconBlockBytes)
191191
if err != nil {
192-
log.WithError(errFailedToConvert).Error("failed to convert SSZ to JSON")
192+
innerLog.WithError(errFailedToConvert).Error("failed to convert SSZ to JSON")
193193
return nil, err
194194
}
195-
log.WithFields(logrus.Fields{
195+
innerLog.WithFields(logrus.Fields{
196196
"relayProvidedBid": slices.Contains(originalBid.relays, relay),
197197
"conversionTime": time.Since(startTime),
198198
}).Info("Converted request from SSZ to JSON for relay")
199199
}
200200

201-
log.WithFields(logrus.Fields{
201+
innerLog.WithFields(logrus.Fields{
202202
"version": versionToUse,
203203
}).Info("calling getPayload")
204204

205205
// Make a new request
206206
req, err := http.NewRequestWithContext(requestCtx, http.MethodPost, url, bytes.NewReader(requestBytes))
207207
if err != nil {
208-
log.WithError(err).Warn("error creating new request")
208+
innerLog.WithError(err).Warn("error creating new request")
209209
return nil, err
210210
}
211211

@@ -224,12 +224,12 @@ func (m *BoostService) innerGetPayload(log *logrus.Entry, signedBlindedBeaconBlo
224224
endpoint = params.PathGetPayloadV2
225225
}
226226
// Send the request and record latency
227-
log.Debug("submitting signed blinded block")
227+
innerLog.Debug("submitting signed blinded block")
228228
start := time.Now()
229229
resp, err := m.httpClientGetPayload.Do(req)
230230
RecordRelayLatency(endpoint, relay.String(), float64(time.Since(start).Microseconds()))
231231
if err != nil {
232-
log.WithError(err).Warnf("error calling getPayload%s on relay", versionToUse)
232+
innerLog.WithError(err).Warnf("error calling getPayload%s on relay", versionToUse)
233233
return nil, err
234234
}
235235

@@ -240,18 +240,18 @@ func (m *BoostService) innerGetPayload(log *logrus.Entry, signedBlindedBeaconBlo
240240
if resp.StatusCode != statusCode {
241241
errorBody, err := io.ReadAll(resp.Body)
242242
if err != nil {
243-
log.WithError(err).Warn("error reading error body")
243+
innerLog.WithError(err).Warn("error reading error body")
244244
return nil, err
245245
}
246246
errorBodyStr := string(errorBody)
247-
log.WithField("errorBody", errorBodyStr).Warnf("unexpected status code %d", resp.StatusCode)
247+
innerLog.WithField("errorBody", errorBodyStr).Warnf("unexpected status code %d", resp.StatusCode)
248248

249249
// If the relay does not support V2 API, retry with V1 API
250250
// we can fallback to V1 API if the status code returned >= 400. There is no harm
251251
// falling back to the V1 API, falling back to the V1 API in the case of any error
252252
// can be beneficial to the proposer to avoid a missed slot.
253253
if resp.StatusCode >= http.StatusBadRequest && url == relay.GetURI(params.PathGetPayloadV2) {
254-
log.Warn("relay may not support getPayloadV2 endpoint, retrying with getPayloadV1 endpoint")
254+
innerLog.Warn("relay may not support getPayloadV2 endpoint, retrying with getPayloadV1 endpoint")
255255
// retry with v1 api
256256
url = relay.GetURI(params.PathGetPayload)
257257
versionToUse = GetPayloadV1
@@ -265,7 +265,7 @@ func (m *BoostService) innerGetPayload(log *logrus.Entry, signedBlindedBeaconBlo
265265
return resp, nil
266266
})
267267
if err != nil {
268-
log.WithError(err).Warn("failed to submit signed blinded block after retries")
268+
innerLog.WithError(err).Warn("failed to submit signed blinded block after retries")
269269
return
270270
}
271271
defer resp.Body.Close()
@@ -277,34 +277,34 @@ func (m *BoostService) innerGetPayload(log *logrus.Entry, signedBlindedBeaconBlo
277277
// Get the resp body content
278278
respBytes, err := io.ReadAll(resp.Body)
279279
if err != nil {
280-
log.WithError(err).Warn("error reading response body")
280+
innerLog.WithError(err).Warn("error reading response body")
281281
return
282282
}
283283

284284
// Get the response's content type
285285
respContentType, _, err := mime.ParseMediaType(resp.Header.Get(HeaderContentType))
286286
if err != nil {
287-
log.WithError(err).Warn("error parsing response content type")
287+
innerLog.WithError(err).Warn("error parsing response content type")
288288
respContentType = MediaTypeJSON
289289
}
290-
log = log.WithField("respContentType", respContentType)
290+
innerLog = innerLog.WithField("respContentType", respContentType)
291291

292292
// Get the response's eth consensus version
293293
respEthConsensusVersion := resp.Header.Get(HeaderEthConsensusVersion)
294-
log = log.WithField("respEthConsensusVersion", respEthConsensusVersion)
294+
innerLog = innerLog.WithField("respEthConsensusVersion", respEthConsensusVersion)
295295

296296
// Decode response
297297
response := new(builderApi.VersionedSubmitBlindedBlockResponse)
298298
err = decodeSubmitBlindedBlockResponse(respBytes, respContentType, respEthConsensusVersion, response)
299299
if err != nil {
300-
log.WithError(err).Warn("error decoding bid")
300+
innerLog.WithError(err).Warn("error decoding bid")
301301
return
302302
}
303303

304304
// Check that the payload matches our request
305-
err = verifyPayload(log, request, response)
305+
err = verifyPayload(innerLog, request, response)
306306
if err != nil {
307-
log.WithError(err).Warn("error verifying payload")
307+
innerLog.WithError(err).Warn("error verifying payload")
308308
return
309309
}
310310

0 commit comments

Comments
 (0)