Skip to content

Commit

Permalink
nethermind error change bug (#12109)
Browse files Browse the repository at this point in the history
* initial attempt to fix bug

* add tests

* Update core/chains/evm/client/errors.go

Co-authored-by: Vyzaldy Sanchez <[email protected]>

* change last line to critical

* fix 503 error message

---------

Co-authored-by: Vyzaldy Sanchez <[email protected]>
Co-authored-by: Prashant Yadav <[email protected]>
  • Loading branch information
3 people authored Feb 21, 2024
1 parent 8e14554 commit 12d4dd6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
17 changes: 14 additions & 3 deletions core/chains/evm/client/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ const (
L2Full
TransactionAlreadyMined
Fatal
ServiceUnavailable
)

type ClientErrors = map[int]*regexp.Regexp
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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
}
13 changes: 13 additions & 0 deletions core/chains/evm/client/errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand All @@ -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: <html>\r\n<head><title>503 Service Temporarily Unavailable</title></head>\r\n<body>\r\n<center><h1>503 Service Temporarily Unavailable</h1></center>\r\n</body>\r\n</html>\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"},
Expand Down

0 comments on commit 12d4dd6

Please sign in to comment.