From 773331bebb509ef66f3a9aab51a8927432e11dc3 Mon Sep 17 00:00:00 2001 From: jeff <113397187+cyberhorsey@users.noreply.github.com> Date: Tue, 20 Jun 2023 15:35:41 -0700 Subject: [PATCH] feat(relayer): use gas tip cap if available (#14024) --- packages/relayer/message/errors.go | 28 +++++++++++++++++++++ packages/relayer/message/process_message.go | 19 ++++++++++---- packages/relayer/message/processor.go | 1 + packages/relayer/mock/eth_client.go | 4 +++ 4 files changed, 47 insertions(+), 5 deletions(-) create mode 100644 packages/relayer/message/errors.go diff --git a/packages/relayer/message/errors.go b/packages/relayer/message/errors.go new file mode 100644 index 00000000000..0bf2d406aeb --- /dev/null +++ b/packages/relayer/message/errors.go @@ -0,0 +1,28 @@ +package message + +import ( + "math/big" + "strings" + + "github.com/pkg/errors" +) + +var ( + //lint:ignore ST1005 allow `errMaxPriorityFeePerGasNotFound` to be capitalized. + errMaxPriorityFeePerGasNotFound = errors.New( + "Method eth_maxPriorityFeePerGas not found", + ) + + // FallbackGasTipCap is the default fallback gasTipCap used when we are + // unable to query an L1 backend for a suggested gasTipCap. + FallbackGasTipCap = big.NewInt(1500000000) +) + +// IsMaxPriorityFeePerGasNotFoundError returns true if the provided error +// signals that the backend does not support the eth_maxPrirorityFeePerGas +// method. In this case, the caller should fallback to using the constant above. +func IsMaxPriorityFeePerGasNotFoundError(err error) bool { + return strings.Contains( + err.Error(), errMaxPriorityFeePerGasNotFound.Error(), + ) +} diff --git a/packages/relayer/message/process_message.go b/packages/relayer/message/process_message.go index 84671a88930..b6b426fcb55 100644 --- a/packages/relayer/message/process_message.go +++ b/packages/relayer/message/process_message.go @@ -100,7 +100,7 @@ func (p *Processor) ProcessMessage( relayer.EventsProcessed.Inc() - ctx, cancel := context.WithTimeout(ctx, 3*time.Minute) + ctx, cancel := context.WithTimeout(ctx, 4*time.Minute) defer cancel() @@ -205,12 +205,21 @@ func (p *Processor) sendProcessMessageCall( } } - gasPrice, err := p.destEthClient.SuggestGasPrice(context.Background()) + gasTipCap, err := p.destEthClient.SuggestGasTipCap(ctx) if err != nil { - return nil, errors.Wrap(err, "p.destBridge.SuggestGasPrice") - } + if IsMaxPriorityFeePerGasNotFoundError(err) { + auth.GasTipCap = FallbackGasTipCap + } else { + gasPrice, err := p.destEthClient.SuggestGasPrice(context.Background()) + if err != nil { + return nil, errors.Wrap(err, "p.destBridge.SuggestGasPrice") + } - auth.GasPrice = gasPrice + auth.GasPrice = gasPrice + } + } else { + auth.GasTipCap = gasTipCap + } if bool(p.profitableOnly) { profitable, err := p.isProfitable(ctx, event.Message, cost) diff --git a/packages/relayer/message/processor.go b/packages/relayer/message/processor.go index 11a918bb06d..4eaddd7b5f6 100644 --- a/packages/relayer/message/processor.go +++ b/packages/relayer/message/processor.go @@ -19,6 +19,7 @@ type ethClient interface { BlockNumber(ctx context.Context) (uint64, error) HeaderByHash(ctx context.Context, hash common.Hash) (*types.Header, error) SuggestGasPrice(ctx context.Context) (*big.Int, error) + SuggestGasTipCap(ctx context.Context) (*big.Int, error) } type Processor struct { diff --git a/packages/relayer/mock/eth_client.go b/packages/relayer/mock/eth_client.go index 3e598886d20..774b36e8858 100644 --- a/packages/relayer/mock/eth_client.go +++ b/packages/relayer/mock/eth_client.go @@ -29,6 +29,10 @@ func (c *EthClient) SuggestGasPrice(ctx context.Context) (*big.Int, error) { return big.NewInt(100), nil } +func (c *EthClient) SuggestGasTipCap(ctx context.Context) (*big.Int, error) { + return big.NewInt(100), nil +} + func (c *EthClient) ChainID(ctx context.Context) (*big.Int, error) { return MockChainID, nil }