Skip to content

Commit

Permalink
feat(relayer): use gas tip cap if available (#14024)
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberhorsey committed Jun 20, 2023
1 parent c9fcffe commit 773331b
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 5 deletions.
28 changes: 28 additions & 0 deletions packages/relayer/message/errors.go
Original file line number Diff line number Diff line change
@@ -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(),
)
}
19 changes: 14 additions & 5 deletions packages/relayer/message/process_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions packages/relayer/message/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions packages/relayer/mock/eth_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 773331b

Please sign in to comment.