Skip to content

Commit

Permalink
server: removed lock, added second check to prevent multiple log outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
MariusVanDerWijden committed May 7, 2024
1 parent 82e238e commit fbcd1e9
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions server/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -662,17 +662,20 @@ func (m *BoostService) processDenebPayload(w http.ResponseWriter, req *http.Requ
headers := map[string]string{HeaderKeySlotUID: currentSlotUID}

// Prepare for requests
var wg sync.WaitGroup
resultCh := make(chan *builderApi.VersionedSubmitBlindedBlockResponse, len(m.relays))
var received atomic.Bool
go func() {
// Make sure we receive a response within the timeout
time.Sleep(m.httpClientGetPayload.Timeout)
resultCh <- nil
}()

// Prepare the request context, which will be cancelled after the first successful response from a relay
requestCtx, requestCtxCancel := context.WithCancel(context.Background())
defer requestCtxCancel()

for _, relay := range m.relays {
wg.Add(1)
go func(relay types.RelayEntry) {
defer wg.Done()
url := relay.GetURI(params.PathGetPayload)
log := log.WithField("url", url)
log.Debug("calling getPayload")
Expand Down Expand Up @@ -728,14 +731,16 @@ func (m *BoostService) processDenebPayload(w http.ResponseWriter, req *http.Requ
}

requestCtxCancel()
resultCh <- responsePayload
log.Info("received payload from relay")
if received.CompareAndSwap(true, true) {
log.Trace("Discarding response, already received a correct response")
} else {
resultCh <- responsePayload
log.Info("received payload from relay")
}
}(relay)
}

// Wait for all requests to complete...
wg.Wait()
close(resultCh)
// Wait for the first request to complete
result := <-resultCh

// If no payload has been received from relay, log loudly about withholding!
Expand Down

0 comments on commit fbcd1e9

Please sign in to comment.