Skip to content

Commit

Permalink
Initialized gas estimator regardless of TXM toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
amit-momin committed Dec 17, 2024
1 parent 7f58819 commit 604da4c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 13 deletions.
9 changes: 7 additions & 2 deletions core/chains/legacyevm/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,17 +244,22 @@ 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)}
} else if !cfg.EVM().TransactionManagerEnabled() {
txm = &txmgr.NullTxManager{ErrMsg: fmt.Sprintf("TXM disabled for chain %d", chainID)}
} else {
var err error

Check failure on line 261 in core/chains/legacyevm/chain.go

View workflow job for this annotation

GitHub Actions / lint

shadow: declaration of "err" shadows declaration at line 248 (govet)
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)
}
Expand Down
32 changes: 21 additions & 11 deletions core/chains/legacyevm/evm_txm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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,
Expand All @@ -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
}

0 comments on commit 604da4c

Please sign in to comment.