diff --git a/common/geth/failover.go b/common/geth/failover.go index 08245bc08a..848c5360bb 100644 --- a/common/geth/failover.go +++ b/common/geth/failover.go @@ -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 { @@ -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 diff --git a/common/geth/handle_error.go b/common/geth/handle_error.go index 4041bfc41a..e686d1a1c2 100644 --- a/common/geth/handle_error.go +++ b/common/geth/handle_error.go @@ -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 @@ -51,20 +51,20 @@ 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 } @@ -72,7 +72,7 @@ func (f *FailoverController) handleError(err error, urlDomain string) (NextEndpo // 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 } } diff --git a/common/geth/multihoming_client.go b/common/geth/multihoming_client.go index 8481f7e47e..1ee7f51d92 100644 --- a/common/geth/multihoming_client.go +++ b/common/geth/multihoming_client.go @@ -85,7 +85,7 @@ func (m *MultiHomingClient) SuggestGasTipCap(ctx context.Context) (*big.Int, err return result, nil } errLast = err - if m.ProcessError(err, rpcIndex) { + if m.ProcessError(err, rpcIndex, "SuggestGasTipCap") { break } } @@ -103,7 +103,7 @@ func (m *MultiHomingClient) HeaderByNumber(ctx context.Context, number *big.Int) return result, nil } errLast = err - if m.ProcessError(err, rpcIndex) { + if m.ProcessError(err, rpcIndex, "HeaderByNumber") { break } } @@ -121,7 +121,7 @@ func (m *MultiHomingClient) EstimateGas(ctx context.Context, msg ethereum.CallMs return result, nil } errLast = err - if m.ProcessError(err, rpcIndex) { + if m.ProcessError(err, rpcIndex, "EstimateGas") { break } @@ -140,7 +140,7 @@ func (m *MultiHomingClient) SendTransaction(ctx context.Context, tx *types.Trans return nil } errLast = err - if m.ProcessError(err, rpcIndex) { + if m.ProcessError(err, rpcIndex, "SendTransaction") { break } @@ -159,7 +159,7 @@ func (m *MultiHomingClient) TransactionReceipt(ctx context.Context, txHash gethc return result, nil } errLast = err - if m.ProcessError(err, rpcIndex) { + if m.ProcessError(err, rpcIndex, "TransactionReceipt") { break } @@ -178,7 +178,7 @@ func (m *MultiHomingClient) BlockNumber(ctx context.Context) (uint64, error) { return result, nil } errLast = err - if m.ProcessError(err, rpcIndex) { + if m.ProcessError(err, rpcIndex, "BlockNumber") { break } @@ -198,7 +198,7 @@ func (m *MultiHomingClient) BalanceAt(ctx context.Context, account gethcommon.Ad return result, nil } errLast = err - if m.ProcessError(err, rpcIndex) { + if m.ProcessError(err, rpcIndex, "BalanceAt") { break } @@ -217,7 +217,7 @@ func (m *MultiHomingClient) BlockByHash(ctx context.Context, hash gethcommon.Has return result, nil } errLast = err - if m.ProcessError(err, rpcIndex) { + if m.ProcessError(err, rpcIndex, "BlockByHash") { break } @@ -236,7 +236,7 @@ func (m *MultiHomingClient) BlockByNumber(ctx context.Context, number *big.Int) return result, nil } errLast = err - if m.ProcessError(err, rpcIndex) { + if m.ProcessError(err, rpcIndex, "BlockByNumber") { break } @@ -259,7 +259,7 @@ func (m *MultiHomingClient) CallContract( return result, nil } errLast = err - if m.ProcessError(err, rpcIndex) { + if m.ProcessError(err, rpcIndex, "CallContract") { break } @@ -282,7 +282,7 @@ func (m *MultiHomingClient) CallContractAtHash( return result, nil } errLast = err - if m.ProcessError(err, rpcIndex) { + if m.ProcessError(err, rpcIndex, "CallContractAtHash") { break } @@ -305,7 +305,7 @@ func (m *MultiHomingClient) CodeAt( return result, nil } errLast = err - if m.ProcessError(err, rpcIndex) { + if m.ProcessError(err, rpcIndex, "CodeAt") { break } @@ -329,7 +329,7 @@ func (m *MultiHomingClient) FeeHistory( return result, nil } errLast = err - if m.ProcessError(err, rpcIndex) { + if m.ProcessError(err, rpcIndex, "FeeHistory") { break } @@ -348,7 +348,7 @@ func (m *MultiHomingClient) FilterLogs(ctx context.Context, q ethereum.FilterQue return result, nil } errLast = err - if m.ProcessError(err, rpcIndex) { + if m.ProcessError(err, rpcIndex, "FilterLogs") { break } @@ -367,7 +367,7 @@ func (m *MultiHomingClient) HeaderByHash(ctx context.Context, hash gethcommon.Ha return result, nil } errLast = err - if m.ProcessError(err, rpcIndex) { + if m.ProcessError(err, rpcIndex, "HeaderByHash") { break } @@ -386,7 +386,7 @@ func (m *MultiHomingClient) NetworkID(ctx context.Context) (*big.Int, error) { return result, nil } errLast = err - if m.ProcessError(err, rpcIndex) { + if m.ProcessError(err, rpcIndex, "NetworkID") { break } @@ -405,7 +405,7 @@ func (m *MultiHomingClient) NonceAt(ctx context.Context, account gethcommon.Addr return result, nil } errLast = err - if m.ProcessError(err, rpcIndex) { + if m.ProcessError(err, rpcIndex, "NonceAt") { break } @@ -424,7 +424,7 @@ func (m *MultiHomingClient) PeerCount(ctx context.Context) (uint64, error) { return result, nil } errLast = err - if m.ProcessError(err, rpcIndex) { + if m.ProcessError(err, rpcIndex, "PeerCount") { break } @@ -443,7 +443,7 @@ func (m *MultiHomingClient) PendingBalanceAt(ctx context.Context, account gethco return result, nil } errLast = err - if m.ProcessError(err, rpcIndex) { + if m.ProcessError(err, rpcIndex, "PendingBalanceAt") { break } @@ -462,7 +462,7 @@ func (m *MultiHomingClient) PendingCallContract(ctx context.Context, msg ethereu return result, nil } errLast = err - if m.ProcessError(err, rpcIndex) { + if m.ProcessError(err, rpcIndex, "PendingCallContract") { break } @@ -481,7 +481,7 @@ func (m *MultiHomingClient) PendingCodeAt(ctx context.Context, account gethcommo return result, nil } errLast = err - if m.ProcessError(err, rpcIndex) { + if m.ProcessError(err, rpcIndex, "PendingCodeAt") { break } @@ -500,7 +500,7 @@ func (m *MultiHomingClient) PendingNonceAt(ctx context.Context, account gethcomm return result, nil } errLast = err - if m.ProcessError(err, rpcIndex) { + if m.ProcessError(err, rpcIndex, "PendingNonceAt") { break } @@ -518,7 +518,7 @@ func (m *MultiHomingClient) PendingStorageAt(ctx context.Context, account gethco return result, nil } errLast = err - if m.ProcessError(err, rpcIndex) { + if m.ProcessError(err, rpcIndex, "PendingStorageAt") { break } @@ -536,7 +536,7 @@ func (m *MultiHomingClient) PendingTransactionCount(ctx context.Context) (uint, return result, nil } errLast = err - if m.ProcessError(err, rpcIndex) { + if m.ProcessError(err, rpcIndex, "PendingTransactionCount") { break } @@ -555,7 +555,7 @@ func (m *MultiHomingClient) StorageAt(ctx context.Context, account gethcommon.Ad return result, nil } errLast = err - if m.ProcessError(err, rpcIndex) { + if m.ProcessError(err, rpcIndex, "StorageAt") { break } @@ -575,7 +575,7 @@ func (m *MultiHomingClient) SubscribeFilterLogs(ctx context.Context, q ethereum. return result, nil } errLast = err - if m.ProcessError(err, rpcIndex) { + if m.ProcessError(err, rpcIndex, "SubscribeFilterLogs") { break } @@ -595,7 +595,7 @@ func (m *MultiHomingClient) SubscribeNewHead(ctx context.Context, ch chan<- *typ return result, nil } errLast = err - if m.ProcessError(err, rpcIndex) { + if m.ProcessError(err, rpcIndex, "SubscribeNewHead") { break } @@ -614,7 +614,7 @@ func (m *MultiHomingClient) SuggestGasPrice(ctx context.Context) (*big.Int, erro return result, nil } errLast = err - if m.ProcessError(err, rpcIndex) { + if m.ProcessError(err, rpcIndex, "SuggestGasPrice") { break } @@ -633,7 +633,7 @@ func (m *MultiHomingClient) SyncProgress(ctx context.Context) (*ethereum.SyncPro return result, nil } errLast = err - if m.ProcessError(err, rpcIndex) { + if m.ProcessError(err, rpcIndex, "SyncProgress") { break } @@ -652,7 +652,7 @@ func (m *MultiHomingClient) TransactionByHash(ctx context.Context, hash gethcomm return tx, isPending, nil } errLast = err - if m.ProcessError(err, rpcIndex) { + if m.ProcessError(err, rpcIndex, "TransactionByHash") { break } @@ -671,7 +671,7 @@ func (m *MultiHomingClient) TransactionCount(ctx context.Context, blockHash geth return result, nil } errLast = err - if m.ProcessError(err, rpcIndex) { + if m.ProcessError(err, rpcIndex, "TransactionCount") { break } @@ -690,7 +690,7 @@ func (m *MultiHomingClient) TransactionInBlock(ctx context.Context, blockHash ge return result, nil } errLast = err - if m.ProcessError(err, rpcIndex) { + if m.ProcessError(err, rpcIndex, "TransactionInBlock") { break } @@ -709,7 +709,7 @@ func (m *MultiHomingClient) TransactionSender(ctx context.Context, tx *types.Tra return result, nil } errLast = err - if m.ProcessError(err, rpcIndex) { + if m.ProcessError(err, rpcIndex, "TransactionSender") { break } @@ -728,7 +728,7 @@ func (m *MultiHomingClient) ChainID(ctx context.Context) (*big.Int, error) { return result, nil } errLast = err - if m.ProcessError(err, rpcIndex) { + if m.ProcessError(err, rpcIndex, "ChainID") { break } @@ -747,7 +747,7 @@ func (m *MultiHomingClient) GetLatestGasCaps(ctx context.Context) (*big.Int, *bi return gasTipCap, gasFeeCap, nil } errLast = err - if m.ProcessError(err, rpcIndex) { + if m.ProcessError(err, rpcIndex, "GetLatestGasCaps") { break } @@ -766,7 +766,7 @@ func (m *MultiHomingClient) EstimateGasPriceAndLimitAndSendTx(ctx context.Contex return result, nil } errLast = err - if m.ProcessError(err, rpcIndex) { + if m.ProcessError(err, rpcIndex, "EstimateGasPriceAndLimitAndSendTx") { break } @@ -785,7 +785,7 @@ func (m *MultiHomingClient) UpdateGas(ctx context.Context, tx *types.Transaction return result, nil } errLast = err - if m.ProcessError(err, rpcIndex) { + if m.ProcessError(err, rpcIndex, "UpdateGas") { break } @@ -803,7 +803,7 @@ func (m *MultiHomingClient) EnsureTransactionEvaled(ctx context.Context, tx *typ return result, nil } errLast = err - if m.ProcessError(err, rpcIndex) { + if m.ProcessError(err, rpcIndex, "EnsureTransactionEvaled") { break } @@ -822,7 +822,7 @@ func (m *MultiHomingClient) EnsureAnyTransactionEvaled(ctx context.Context, txs return result, nil } errLast = err - if m.ProcessError(err, rpcIndex) { + if m.ProcessError(err, rpcIndex, "EnsureAnyTransactionEvaled") { break }