diff --git a/core/chains/legacyevm/chain.go b/core/chains/legacyevm/chain.go index 9d5dc3fbd6b..64fcdf10950 100644 --- a/core/chains/legacyevm/chain.go +++ b/core/chains/legacyevm/chain.go @@ -244,9 +244,14 @@ func newChain(ctx context.Context, cfg *evmconfig.ChainScoped, nodes []*toml.Nod } } + // initialize gas estimator + gasEstimator, err := newGasEstimator(cfg.EVM(), client, l, opts, clientsByChainID) + if err != nil { + return nil, fmt.Errorf("failed to instantiate gas estimator for chain with ID %s: %w", chainID, err) + } + // note: gas estimator is started as a part of the txm var txm txmgr.TxManager - var gasEstimator gas.EvmFeeEstimator //nolint:gocritic // ignoring suggestion to convert to switch statement if !opts.AppConfig.EVMRPCEnabled() { txm = &txmgr.NullTxManager{ErrMsg: fmt.Sprintf("Ethereum is disabled for chain %d", chainID)} @@ -254,7 +259,7 @@ func newChain(ctx context.Context, cfg *evmconfig.ChainScoped, nodes []*toml.Nod txm = &txmgr.NullTxManager{ErrMsg: fmt.Sprintf("TXM disabled for chain %d", chainID)} } else { var err error - txm, gasEstimator, err = newEvmTxm(opts.DS, cfg.EVM(), opts.AppConfig.Database(), opts.AppConfig.Database().Listener(), client, l, logPoller, opts, headTracker, clientsByChainID) + txm, err = newEvmTxm(opts.DS, cfg.EVM(), opts.AppConfig.Database(), opts.AppConfig.Database().Listener(), client, l, logPoller, opts, headTracker, gasEstimator) if err != nil { return nil, fmt.Errorf("failed to instantiate EvmTxm for chain with ID %s: %w", chainID, err) } diff --git a/core/chains/legacyevm/evm_txm.go b/core/chains/legacyevm/evm_txm.go index 83a82511677..419ab7718f2 100644 --- a/core/chains/legacyevm/evm_txm.go +++ b/core/chains/legacyevm/evm_txm.go @@ -24,9 +24,8 @@ func newEvmTxm( logPoller logpoller.LogPoller, opts ChainRelayOpts, headTracker httypes.HeadTracker, - clientsByChainID map[string]rollups.DAClient, -) (txm txmgr.TxManager, estimator gas.EvmFeeEstimator, +) (txm txmgr.TxManager, err error, ) { chainID := cfg.ChainID() @@ -40,15 +39,6 @@ func newEvmTxm( "limitDefault", cfg.GasEstimator().LimitDefault(), ) - // build estimator from factory - if opts.GenGasEstimator == nil { - if estimator, err = gas.NewEstimator(lggr, client, cfg.ChainType(), chainID, cfg.GasEstimator(), clientsByChainID); err != nil { - return nil, nil, fmt.Errorf("failed to initialize estimator: %w", err) - } - } else { - estimator = opts.GenGasEstimator(chainID) - } - if opts.GenTxManager == nil { txm, err = txmgr.NewTxm( ds, @@ -69,3 +59,23 @@ func newEvmTxm( } return } + +func newGasEstimator( + cfg evmconfig.EVM, + client evmclient.Client, + lggr logger.Logger, + opts ChainRelayOpts, + clientsByChainID map[string]rollups.DAClient, +) (estimator gas.EvmFeeEstimator, err error) { + lggr = lggr.Named("GasEstimator") + chainID := cfg.ChainID() + // build estimator from factory + if opts.GenGasEstimator == nil { + if estimator, err = gas.NewEstimator(lggr, client, cfg.ChainType(), chainID, cfg.GasEstimator(), clientsByChainID); err != nil { + return nil, fmt.Errorf("failed to initialize estimator: %w", err) + } + } else { + estimator = opts.GenGasEstimator(chainID) + } + return +}