Skip to content

Commit

Permalink
fix log and change rpc in response to json rpc error
Browse files Browse the repository at this point in the history
  • Loading branch information
Ubuntu committed Apr 11, 2024
1 parent 3170b6c commit 2a9590f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
13 changes: 7 additions & 6 deletions common/geth/handle_error.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const (
func (f *FailoverController) handleHttpError(httpRespError rpc.HTTPError) (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]", "Status Code", sc, "Error", httpRespError)
f.Logger.Info("[HTTP Response Error]", "Curr Rpc Fault", f.numberRpcFault, "Status Code", sc, "Error", httpRespError)

if sc >= 200 && sc < 300 {
// 2xx error, however it should not be reachable
Expand All @@ -51,7 +51,8 @@ func (f *FailoverController) handleHttpError(httpRespError rpc.HTTPError) (NextE
// 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

//
// This function is protected by mutex from the outside
func (f *FailoverController) handleError(err error) (NextEndpoint, ImmediateAction) {

var httpRespError rpc.HTTPError
Expand All @@ -65,15 +66,15 @@ func (f *FailoverController) handleError(err error) (NextEndpoint, ImmediateActi
var rpcError rpc.Error
if errors.As(err, &rpcError) {
ec := rpcError.ErrorCode()
f.Logger.Info("[JSON RPC Response Error]", "Error Code", ec, "Error", rpcError)
// we always attribute JSON RPC error as sender's fault, i.e no connection rotation
return CurrentRPC, Return
f.Logger.Warn("[JSON RPC Response Error]", "Curr Rpc Fault", f.numberRpcFault, "Error Code", ec, "Error", 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.Info("[Default Response Error]", err)
f.Logger.Warn("[Default Response Error]", "Curr Rpc Fault", f.numberRpcFault, "error", err)
return NewRPC, Retry
}

Expand Down
2 changes: 1 addition & 1 deletion common/geth/multihoming_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func TestMultihomingClientSenderFaultZeroRetry(t *testing.T) {

// given num retry is 0, when failure arises above, current rpc should becomes the next one
index, _ = client.GetRPCInstance()
require.Equal(t, index, 0)
require.Equal(t, index, 1)

}

Expand Down

0 comments on commit 2a9590f

Please sign in to comment.