Skip to content

Commit

Permalink
Add request start time metrics to request header field (#647)
Browse files Browse the repository at this point in the history
* add start time msinto slot to http header

* add start time unixms to http header

* make linter happy

* remove empty line instead of comments to make linter happy

* remove start time unix milliseconds

* use start time unixms header field across all the request
  • Loading branch information
bhakiyakalimuthu authored May 10, 2024
1 parent 74a8ecb commit 7a6469e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
19 changes: 12 additions & 7 deletions server/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,14 +257,19 @@ func (m *BoostService) handleRegisterValidator(w http.ResponseWriter, req *http.
"ua": ua,
})

// Add request headers
headers := map[string]string{
HeaderStartTimeUnixMS: fmt.Sprintf("%d", time.Now().UTC().UnixMilli()),
}

relayRespCh := make(chan error, len(m.relays))

for _, relay := range m.relays {
go func(relay types.RelayEntry) {
url := relay.GetURI(params.PathRegisterValidator)
log := log.WithField("url", url)

_, err := SendHTTPRequest(context.Background(), m.httpClientRegVal, http.MethodPost, url, ua, nil, payload, nil)
_, err := SendHTTPRequest(context.Background(), m.httpClientRegVal, http.MethodPost, url, ua, headers, payload, nil)
relayRespCh <- err
if err != nil {
log.WithError(err).Warn("error calling registerValidator on relay")
Expand Down Expand Up @@ -337,16 +342,14 @@ func (m *BoostService) handleGetHeader(w http.ResponseWriter, req *http.Request)
"slotTimeSec": config.SlotTimeSec,
"msIntoSlot": msIntoSlot,
}).Infof("getHeader request start - %d milliseconds into slot %d", msIntoSlot, _slot)

// Add request headers
headers := map[string]string{
HeaderKeySlotUID: slotUID.String(),
HeaderKeySlotUID: slotUID.String(),
HeaderStartTimeUnixMS: fmt.Sprintf("%d", time.Now().UTC().UnixMilli()),
}

// Prepare relay responses
result := bidResp{} // the final response, containing the highest bid (if any)
relays := make(map[BlockHashHex][]types.RelayEntry) // relays that sent the bid for a specific blockHash

// Call the relays
var mu sync.Mutex
var wg sync.WaitGroup
Expand Down Expand Up @@ -461,7 +464,6 @@ func (m *BoostService) handleGetHeader(w http.ResponseWriter, req *http.Request)
result.t = time.Now()
}(relay)
}

// Wait for all requests to complete...
wg.Wait()

Expand Down Expand Up @@ -668,7 +670,10 @@ func (m *BoostService) processDenebPayload(w http.ResponseWriter, req *http.Requ
}

// Add request headers
headers := map[string]string{HeaderKeySlotUID: currentSlotUID}
headers := map[string]string{
HeaderKeySlotUID: currentSlotUID,
HeaderStartTimeUnixMS: fmt.Sprintf("%d", time.Now().UTC().UnixMilli()),
}

// Prepare for requests
var wg sync.WaitGroup
Expand Down
5 changes: 3 additions & 2 deletions server/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ import (
)

const (
HeaderKeySlotUID = "X-MEVBoost-SlotID"
HeaderKeyVersion = "X-MEVBoost-Version"
HeaderKeySlotUID = "X-MEVBoost-SlotID"
HeaderKeyVersion = "X-MEVBoost-Version"
HeaderStartTimeUnixMS = "X-MEVBoost-StartTimeUnixMS"
)

var (
Expand Down

0 comments on commit 7a6469e

Please sign in to comment.