From 12d4dd6356c8fcd3bedd5a8c555ea2885a6b5db9 Mon Sep 17 00:00:00 2001 From: Jim W Date: Tue, 20 Feb 2024 23:59:41 -0500 Subject: [PATCH] nethermind error change bug (#12109) * initial attempt to fix bug * add tests * Update core/chains/evm/client/errors.go Co-authored-by: Vyzaldy Sanchez * change last line to critical * fix 503 error message --------- Co-authored-by: Vyzaldy Sanchez Co-authored-by: Prashant Yadav <34992934+prashantkumar1982@users.noreply.github.com> --- core/chains/evm/client/errors.go | 17 ++++++++++++++--- core/chains/evm/client/errors_test.go | 13 +++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/core/chains/evm/client/errors.go b/core/chains/evm/client/errors.go index 67197b764a0..e966e088678 100644 --- a/core/chains/evm/client/errors.go +++ b/core/chains/evm/client/errors.go @@ -62,6 +62,7 @@ const ( L2Full TransactionAlreadyMined Fatal + ServiceUnavailable ) type ClientErrors = map[int]*regexp.Regexp @@ -196,8 +197,9 @@ var nethermind = ClientErrors{ TransactionAlreadyInMempool: regexp.MustCompile(`(: |^)(AlreadyKnown|OwnNonceAlreadyUsed)$`), // InsufficientFunds: Sender account has not enough balance to execute this transaction. - InsufficientEth: regexp.MustCompile(`(: |^)InsufficientFunds(, Account balance: \d+, cumulative cost: \d+)?$`), - Fatal: nethermindFatal, + InsufficientEth: regexp.MustCompile(`(: |^)InsufficientFunds(, Account balance: \d+, cumulative cost: \d+|, Balance is \d+ less than sending value \+ gas \d+)?$`), + ServiceUnavailable: regexp.MustCompile(`(: |^)503 Service Unavailable: [\s\S]*$`), + Fatal: nethermindFatal, } // Harmony @@ -301,6 +303,11 @@ func (s *SendError) IsL2Full() bool { return s.is(L2Full) } +// IsServiceUnavailable indicates if the error was caused by a service being unavailable +func (s *SendError) IsServiceUnavailable() bool { + return s.is(ServiceUnavailable) +} + // IsTimeout indicates if the error was caused by an exceeded context deadline func (s *SendError) IsTimeout() bool { if s == nil { @@ -483,6 +490,10 @@ func ClassifySendError(err error, lggr logger.SugaredLogger, tx *types.Transacti ), "err", sendError, "etx", tx) return commonclient.InsufficientFunds } + if sendError.IsServiceUnavailable() { + lggr.Errorw("service unavailable while sending transaction %x", tx.Hash(), "err", sendError, "etx", tx) + return commonclient.Retryable + } if sendError.IsTimeout() { lggr.Errorw("timeout while sending transaction %x", tx.Hash(), "err", sendError, "etx", tx) return commonclient.Retryable @@ -499,6 +510,6 @@ func ClassifySendError(err error, lggr logger.SugaredLogger, tx *types.Transacti ) return commonclient.ExceedsMaxFee } - lggr.Errorw("Unknown error encountered when sending transaction", "err", err, "etx", tx) + lggr.Criticalw("Unknown error encountered when sending transaction", "err", err, "etx", tx) return commonclient.Unknown } diff --git a/core/chains/evm/client/errors_test.go b/core/chains/evm/client/errors_test.go index ad8079824ab..f47b93c0400 100644 --- a/core/chains/evm/client/errors_test.go +++ b/core/chains/evm/client/errors_test.go @@ -195,6 +195,7 @@ func Test_Eth_Errors(t *testing.T) { {"insufficient funds for gas * price + value: address 0xb68D832c1241bc50db1CF09e96c0F4201D5539C9 have 9934612900000000 want 9936662900000000", true, "Arbitrum"}, {"call failed: InsufficientFunds", true, "Nethermind"}, {"call failed: InsufficientFunds, Account balance: 4740799397601480913, cumulative cost: 22019342038993800000", true, "Nethermind"}, + {"call failed: InsufficientFunds, Balance is 1092404690719251702 less than sending value + gas 7165512000464000000", true, "Nethermind"}, {"insufficient funds", true, "Klaytn"}, {"insufficient funds for gas * price + value + gatewayFee", true, "celo"}, {"insufficient balance for transfer", true, "zkSync"}, @@ -208,6 +209,18 @@ func Test_Eth_Errors(t *testing.T) { } }) + t.Run("IsServiceUnavailable", func(t *testing.T) { + tests := []errorCase{ + {"call failed: 503 Service Unavailable: \r\n503 Service Temporarily Unavailable\r\n\r\n

503 Service Temporarily Unavailable

\r\n\r\n\r\n", true, "Nethermind"}, + } + for _, test := range tests { + err = evmclient.NewSendErrorS(test.message) + assert.Equal(t, err.IsServiceUnavailable(), test.expect) + err = newSendErrorWrapped(test.message) + assert.Equal(t, err.IsServiceUnavailable(), test.expect) + } + }) + t.Run("IsTxFeeExceedsCap", func(t *testing.T) { tests := []errorCase{ {"tx fee (1.10 ether) exceeds the configured cap (1.00 ether)", true, "geth"},