Skip to content

Commit

Permalink
add caller func name in rpc error log (#529)
Browse files Browse the repository at this point in the history
Co-authored-by: Bowen Xue <[email protected]>
  • Loading branch information
bxue-l2 and Bowen Xue authored Apr 30, 2024
1 parent fbba806 commit 4d42744
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 47 deletions.
4 changes: 2 additions & 2 deletions common/geth/failover.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func NewFailoverController(logger logging.Logger, rpcUrls []string) (*FailoverCo

// ProcessError attributes the error and updates total number of fault for RPC
// It returns if RPC should immediately give up
func (f *FailoverController) ProcessError(err error, rpcIndex int) bool {
func (f *FailoverController) ProcessError(err error, rpcIndex int, funcName string) bool {
f.mu.Lock()
defer f.mu.Unlock()
if err == nil {
Expand All @@ -47,7 +47,7 @@ func (f *FailoverController) ProcessError(err error, rpcIndex int) bool {
urlDomain = f.UrlDomains[rpcIndex]
}

nextEndpoint, action := f.handleError(err, urlDomain)
nextEndpoint, action := f.handleError(err, urlDomain, funcName)

if nextEndpoint == NewRPC {
f.numberRpcFault += 1
Expand Down
12 changes: 6 additions & 6 deletions common/geth/handle_error.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ const (

// handleHttpError returns a boolean indicating if the current RPC should be rotated
// the second boolean indicating if should giveup immediately
func (f *FailoverController) handleHttpError(httpRespError rpc.HTTPError, urlDomain string) (NextEndpoint, ImmediateAction) {
func (f *FailoverController) handleHttpError(httpRespError rpc.HTTPError, urlDomain string, funcName string) (NextEndpoint, ImmediateAction) {
sc := httpRespError.StatusCode
// Default to rotation the current RPC, because it allows a higher chance to get the query completed.
f.Logger.Info("[HTTP Response Error]", "urlDomain", urlDomain, "statusCode", sc, "err", httpRespError)
f.Logger.Info("[HTTP Response Error]", "urlDomain", urlDomain, "statusCode", sc, "funcName", funcName, "err", httpRespError)

if sc >= 200 && sc < 300 {
// 2xx error, however it should not be reachable
Expand All @@ -51,28 +51,28 @@ func (f *FailoverController) handleHttpError(httpRespError rpc.HTTPError, urlDom
// If the error is http, non2xx error would generate HTTP error, https://github.com/ethereum/go-ethereum/blob/master/rpc/http.go#L233
// but a 2xx http response could contain JSON RPC error, https://github.com/ethereum/go-ethereum/blob/master/rpc/http.go#L181
// If the error is Websocket or IPC, we only look for JSON error, https://github.com/ethereum/go-ethereum/blob/master/rpc/json.go#L67
func (f *FailoverController) handleError(err error, urlDomain string) (NextEndpoint, ImmediateAction) {
func (f *FailoverController) handleError(err error, urlDomain string, funcName string) (NextEndpoint, ImmediateAction) {

var httpRespError rpc.HTTPError
if errors.As(err, &httpRespError) {
// if error is http error, i.e. non 2xx error, it is handled here
// if it is 2xx error, the error message is nil, https://github.com/ethereum/go-ethereum/blob/master/rpc/http.go,
// execution does not enter here.
return f.handleHttpError(httpRespError, urlDomain)
return f.handleHttpError(httpRespError, urlDomain, funcName)
} else {
// it might be http2xx error, websocket error or ipc error. Parse json error code
var rpcError rpc.Error
if errors.As(err, &rpcError) {
ec := rpcError.ErrorCode()
f.Logger.Warn("[JSON RPC Response Error]", "urlDomain", urlDomain, "errorCode", ec, "err", rpcError)
f.Logger.Warn("[JSON RPC Response Error]", "urlDomain", urlDomain, "errorCode", ec, "funcName", funcName, "err", rpcError)
// we always attribute JSON RPC error as receiver's fault, i.e new connection rotation
return NewRPC, Return
}

// If no http response or no rpc response is returned, it is a connection issue,
// since we can't accurately attribute the network issue to neither sender nor receiver
// side. Optimistically, switch rpc client
f.Logger.Warn("[Default Response Error]", "urlDomain", urlDomain, "err", err)
f.Logger.Warn("[Default Response Error]", "urlDomain", urlDomain, "funcName", funcName, "err", err)
return NewRPC, Retry
}
}
Loading

0 comments on commit 4d42744

Please sign in to comment.