Skip to content

Commit

Permalink
receiver api fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dvush committed Nov 7, 2024
1 parent bb943ec commit e591cbc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion proxy/receiver_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ var (
errUUIDParse = errors.New("failed to parse UUID")

apiNow = time.Now

handleParsedRequestTimeout = time.Second * 1
)

func (prx *ReceiverProxy) PublicJSONRPCHandler(maxRequestBodySizeBytes int64) (*rpcserver.JSONRPCHandler, error) {
Expand Down Expand Up @@ -79,12 +81,15 @@ func (prx *ReceiverProxy) ValidateSigner(ctx context.Context, req *ParsedRequest
return nil
}

prx.Log.Debug("Received signed request on a public endpoint", slog.Any("signer", req.signer))

if req.signer == prx.FlashbotsSignerAddress {
req.peerName = FlashbotsPeerName
return nil
}

prx.peersMu.RLock()
defer prx.peersMu.RUnlock()
found := false
peerName := ""
for _, peer := range prx.lastFetchedPeers {
Expand All @@ -97,7 +102,6 @@ func (prx *ReceiverProxy) ValidateSigner(ctx context.Context, req *ParsedRequest
if !found {
return errUnknownPeer
}
prx.peersMu.RUnlock()
req.peerName = peerName
return nil
}
Expand Down Expand Up @@ -304,6 +308,9 @@ type ParsedRequest struct {
}

func (prx *ReceiverProxy) HandleParsedRequest(ctx context.Context, parsedRequest ParsedRequest) error {
ctx, cancel := context.WithTimeout(ctx, handleParsedRequestTimeout)
defer cancel()

parsedRequest.receivedAt = apiNow()
prx.Log.Debug("Received request", slog.Bool("isPublicEndpoint", parsedRequest.publicEndpoint), slog.String("method", parsedRequest.method))
if parsedRequest.publicEndpoint {
Expand All @@ -325,11 +332,13 @@ func (prx *ReceiverProxy) HandleParsedRequest(ctx context.Context, parsedRequest
}
select {
case <-ctx.Done():
prx.Log.Error("Shared queue is stalling")
case prx.shareQueue <- &parsedRequest:
}
if !parsedRequest.publicEndpoint {
select {
case <-ctx.Done():
prx.Log.Error("Archive queue is stalling")
case prx.archiveQueue <- &parsedRequest:
}
}
Expand Down
File renamed without changes.

0 comments on commit e591cbc

Please sign in to comment.