From 06b61baab640063db26caedb496c56f4e776c1d6 Mon Sep 17 00:00:00 2001 From: Matt Yang Date: Thu, 14 Sep 2023 17:51:42 -0400 Subject: [PATCH] fix chaintype panic --- .../evm/gas/chainoracles/l1_gas_price_oracle.go | 7 +++++++ core/chains/evm/gas/models.go | 14 +++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/core/chains/evm/gas/chainoracles/l1_gas_price_oracle.go b/core/chains/evm/gas/chainoracles/l1_gas_price_oracle.go index 1ab2b582097..e031ed115be 100644 --- a/core/chains/evm/gas/chainoracles/l1_gas_price_oracle.go +++ b/core/chains/evm/gas/chainoracles/l1_gas_price_oracle.go @@ -10,6 +10,7 @@ import ( "github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum/common" + "golang.org/x/exp/slices" "github.com/smartcontractkit/chainlink/v2/core/assets" evmclient "github.com/smartcontractkit/chainlink/v2/core/chains/evm/client" @@ -59,6 +60,12 @@ const ( PollPeriod = 12 * time.Second ) +var supportedChainTypes = []config.ChainType{config.ChainArbitrum, config.ChainOptimismBedrock} + +func IsL1OracleChain(chainType config.ChainType) bool { + return slices.Contains(supportedChainTypes, chainType) +} + func NewL1GasPriceOracle(lggr logger.Logger, ethClient ethClient, chainType config.ChainType) L1Oracle { var address, callArgs string switch chainType { diff --git a/core/chains/evm/gas/models.go b/core/chains/evm/gas/models.go index f5d3ef934cf..b7f4377767f 100644 --- a/core/chains/evm/gas/models.go +++ b/core/chains/evm/gas/models.go @@ -66,20 +66,24 @@ func NewEstimator(lggr logger.Logger, ethClient evmclient.Client, cfg Config, ge "priceMin", geCfg.PriceMin(), ) df := geCfg.EIP1559DynamicFees() + + // create l1Oracle only if it is supported for the chain + var l1Oracle chainoracles.L1Oracle + if chainoracles.IsL1OracleChain(cfg.ChainType()) { + l1Oracle = chainoracles.NewL1GasPriceOracle(lggr, ethClient, cfg.ChainType()) + } switch s { case "Arbitrum": - l1Oracle := chainoracles.NewL1GasPriceOracle(lggr, ethClient, cfg.ChainType()) return NewWrappedEvmEstimator(NewArbitrumEstimator(lggr, geCfg, ethClient, ethClient), df, l1Oracle) case "BlockHistory": - l1Oracle := chainoracles.NewL1GasPriceOracle(lggr, ethClient, cfg.ChainType()) return NewWrappedEvmEstimator(NewBlockHistoryEstimator(lggr, ethClient, cfg, geCfg, bh, *ethClient.ConfiguredChainID()), df, l1Oracle) case "FixedPrice": - return NewWrappedEvmEstimator(NewFixedPriceEstimator(geCfg, bh, lggr), df, nil) + return NewWrappedEvmEstimator(NewFixedPriceEstimator(geCfg, bh, lggr), df, l1Oracle) case "Optimism2", "L2Suggested": - return NewWrappedEvmEstimator(NewL2SuggestedPriceEstimator(lggr, ethClient), df, nil) + return NewWrappedEvmEstimator(NewL2SuggestedPriceEstimator(lggr, ethClient), df, l1Oracle) default: lggr.Warnf("GasEstimator: unrecognised mode '%s', falling back to FixedPriceEstimator", s) - return NewWrappedEvmEstimator(NewFixedPriceEstimator(geCfg, bh, lggr), df, nil) + return NewWrappedEvmEstimator(NewFixedPriceEstimator(geCfg, bh, lggr), df, l1Oracle) } }