Skip to content
This repository has been archived by the owner on Dec 4, 2024. It is now read-only.

Commit

Permalink
Expand fallback errors in tx relayer when dynamic fee tx sending fails (
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan-Ethernal authored Oct 23, 2023
1 parent 5515483 commit 38fa45b
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions txrelayer/txrelayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ const (
)

var (
errNoAccounts = errors.New("no accounts registered")
errNoAccounts = errors.New("no accounts registered")
errMethodNotFound = errors.New("method not found")

// dynamicFeeTxFallbackErrs represents known errors which are the reason to fallback
// from sending dynamic fee tx to legacy tx
dynamicFeeTxFallbackErrs = []error{types.ErrTxTypeNotSupported, errMethodNotFound}
)

type TxRelayer interface {
Expand Down Expand Up @@ -90,13 +95,18 @@ func (t *TxRelayerImpl) Call(from ethgo.Address, to ethgo.Address, input []byte)
func (t *TxRelayerImpl) SendTransaction(txn *ethgo.Transaction, key ethgo.Key) (*ethgo.Receipt, error) {
txnHash, err := t.sendTransactionLocked(txn, key)
if err != nil {
if txn.Type != ethgo.TransactionLegacy &&
strings.Contains(err.Error(), types.ErrTxTypeNotSupported.Error()) {
// downgrade transaction to legacy tx type and resend it
txn.Type = ethgo.TransactionLegacy
txn.GasPrice = 0

return t.SendTransaction(txn, key)
if txn.Type != ethgo.TransactionLegacy {
for _, fallbackErr := range dynamicFeeTxFallbackErrs {
if strings.Contains(
strings.ToLower(err.Error()),
strings.ToLower(fallbackErr.Error())) {
// "downgrade" transaction to the legacy tx type and resend it
txn.Type = ethgo.TransactionLegacy
txn.GasPrice = 0

return t.SendTransaction(txn, key)
}
}
}

return nil, err
Expand Down

0 comments on commit 38fa45b

Please sign in to comment.