|
9 | 9 | "io" |
10 | 10 | "mime" |
11 | 11 | "net/http" |
| 12 | + "slices" |
12 | 13 | "sync/atomic" |
13 | 14 | "time" |
14 | 15 |
|
@@ -128,41 +129,42 @@ func (m *BoostService) getPayload(log *logrus.Entry, signedBlindedBeaconBlockByt |
128 | 129 | requestCtx, requestCtxCancel := context.WithTimeout(context.Background(), m.httpClientGetPayload.Timeout) |
129 | 130 | defer requestCtxCancel() |
130 | 131 |
|
131 | | - // Make a list of relays without SSZ support |
132 | | - var relaysWithoutSSZ []string |
133 | | - for _, relay := range originalBid.relays { |
134 | | - if !relay.SupportsSSZ { |
135 | | - relaysWithoutSSZ = append(relaysWithoutSSZ, relay.URL.Hostname()) |
136 | | - } |
137 | | - } |
138 | | - |
139 | | - // Convert the blinded block to JSON if there's a relay that doesn't support SSZ yet |
140 | | - var signedBlindedBeaconBlockBytesJSON []byte |
141 | | - if proposerContentType == MediaTypeOctetStream && len(relaysWithoutSSZ) > 0 { |
142 | | - log.WithField("relaysWithoutSSZ", relaysWithoutSSZ).Info("Converting request from SSZ to JSON for relay(s)") |
143 | | - signedBlindedBeaconBlockBytesJSON, err = convertSSZToJSON(proposerEthConsensusVersion, signedBlindedBeaconBlockBytes) |
144 | | - if err != nil { |
145 | | - log.WithError(errFailedToConvert).Error("failed to convert SSZ to JSON") |
146 | | - return nil, bidResp{} |
147 | | - } |
148 | | - } |
149 | | - |
150 | | - // Only request payloads from relays which provided the bid. This is |
151 | | - // necessary now because we use the bid to track relay encoding preferences. |
152 | | - for _, relay := range originalBid.relays { |
| 132 | + for _, relay := range m.relays { |
153 | 133 | go func(relay types.RelayEntry) { |
154 | 134 | url := relay.GetURI(params.PathGetPayload) |
155 | 135 | log := log.WithField("url", url) |
156 | 136 | log.Debug("calling getPayload") |
157 | 137 |
|
158 | 138 | // If the request fails, try again a few times with 100ms between tries |
159 | 139 | resp, err := retry(requestCtx, m.requestMaxRetries, 100*time.Millisecond, func() (*http.Response, error) { |
160 | | - // If necessary, use the JSON encoded version and the JSON Content-Type header |
| 140 | + // Default to the content from the proposer |
161 | 141 | requestContentType := parsedProposerContentType |
162 | 142 | requestBytes := signedBlindedBeaconBlockBytes |
163 | | - if parsedProposerContentType == MediaTypeOctetStream && !relay.SupportsSSZ { |
164 | | - requestBytes = signedBlindedBeaconBlockBytesJSON |
| 143 | + |
| 144 | + // Check if the relay supports SSZ |
| 145 | + relaySupportsSSZ := false |
| 146 | + for _, originalBidRelay := range originalBid.relays { |
| 147 | + if relay.URL == originalBidRelay.URL { |
| 148 | + relaySupportsSSZ = originalBidRelay.SupportsSSZ |
| 149 | + break |
| 150 | + } |
| 151 | + } |
| 152 | + log.WithField("relaySupportsSSZ", relaySupportsSSZ).Debug("encoding preference") |
| 153 | + |
| 154 | + // If the relay provided the bid in JSON or did not provide a bid for this payload, |
| 155 | + // we must convert the signed blinded beacon block from SSZ to JSON for this relay |
| 156 | + if parsedProposerContentType == MediaTypeOctetStream && !relaySupportsSSZ { |
165 | 157 | requestContentType = MediaTypeJSON |
| 158 | + startTime := time.Now() |
| 159 | + requestBytes, err = convertSSZToJSON(proposerEthConsensusVersion, signedBlindedBeaconBlockBytes) |
| 160 | + if err != nil { |
| 161 | + log.WithError(errFailedToConvert).Error("failed to convert SSZ to JSON") |
| 162 | + return nil, err |
| 163 | + } |
| 164 | + log.WithFields(logrus.Fields{ |
| 165 | + "relayProvidedBid": slices.Contains(originalBid.relays, relay), |
| 166 | + "conversionTime": time.Since(startTime), |
| 167 | + }).Info("Converted request from SSZ to JSON for relay") |
166 | 168 | } |
167 | 169 |
|
168 | 170 | // Make a new request |
|
0 commit comments