nolint
()
| 48 | |
| 49 | // nolint |
| 50 | func (r *RPCRequestHandler) process() { |
| 51 | // r.logger = r.logger.With("uid", r.uid) |
| 52 | r.logger.Info("[process] POST request received") |
| 53 | |
| 54 | defer r.finishRequest() |
| 55 | r.requestRecord.requestEntry.ReceivedAt = r.timeStarted |
| 56 | r.requestRecord.requestEntry.ID = r.uid |
| 57 | r.requestRecord.UpdateRequestEntry(r.req, http.StatusOK, "") |
| 58 | |
| 59 | whitehatBundleID := r.req.URL.Query().Get("bundle") |
| 60 | isWhitehatBundleCollection := whitehatBundleID != "" |
| 61 | |
| 62 | origin := r.req.Header.Get("Origin") |
| 63 | referer := r.req.Header.Get("Referer") |
| 64 | |
| 65 | // If users specify a proxy url in their rpc endpoint they can have their requests proxied to that endpoint instead of Infura |
| 66 | // e.g. https://rpc.flashbots.net?url=http://RPC-ENDPOINT.COM |
| 67 | customProxyURL, ok := r.req.URL.Query()["url"] |
| 68 | if ok && len(customProxyURL[0]) > 1 { |
| 69 | r.defaultProxyURL = customProxyURL[0] |
| 70 | r.logger.Info("[process] Using custom url", zap.String("url", r.defaultProxyURL)) |
| 71 | } |
| 72 | |
| 73 | // Decode request JSON RPC |
| 74 | defer r.req.Body.Close() |
| 75 | body, err := io.ReadAll(r.req.Body) |
| 76 | if err != nil { |
| 77 | r.requestRecord.UpdateRequestEntry(r.req, http.StatusBadRequest, err.Error()) |
| 78 | r.logger.Error("[process] Failed to read request body", zap.Error(err)) |
| 79 | (*r.respw).WriteHeader(http.StatusBadRequest) |
| 80 | return |
| 81 | } |
| 82 | |
| 83 | if len(body) == 0 { |
| 84 | r.requestRecord.UpdateRequestEntry(r.req, http.StatusBadRequest, "empty request body") |
| 85 | (*r.respw).WriteHeader(http.StatusBadRequest) |
| 86 | return |
| 87 | } |
| 88 | |
| 89 | // create rpc proxy client for making proxy request |
| 90 | client := NewRPCProxyClient(r.logger, r.defaultProxyURL, r.proxyTimeoutSeconds) |
| 91 | |
| 92 | r.requestRecord.UpdateRequestEntry(r.req, http.StatusOK, "") // Data analytics |
| 93 | |
| 94 | // Parse JSON RPC payload |
| 95 | var jsonReq *types.JSONRPCRequest |
| 96 | if err = json.Unmarshal(body, &jsonReq); err != nil { |
| 97 | r.logger.Warn("[process] Parse payload", zap.Error(err)) |
| 98 | (*r.respw).WriteHeader(http.StatusBadRequest) |
| 99 | return |
| 100 | } |
| 101 | |
| 102 | // mev-share parameters |
| 103 | urlParams, err := ExtractParametersFromURL(r.req.URL, r.builderNames) |
| 104 | if err != nil { |
| 105 | r.logger.Warn("[process] Invalid auction preference", zap.Error(err)) |
| 106 | res := AuctionPreferenceErrorToJSONRPCResponse(jsonReq, err) |
| 107 | r._writeRPCResponse(res) |
no test coverage detected