Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add config to toggle the TXM #15714

Conversation

amit-momin
Copy link
Contributor

@amit-momin amit-momin commented Dec 16, 2024

MERC-6516

Added the TransactionManagerEnabled config to enable or disable the TXM. This toggle was added so a product that only needs read-only access (i.e client, head tracker, log poller) can disable the unused component.

Copy link
Contributor

github-actions bot commented Dec 16, 2024

AER Report: CI Core ran successfully ✅

aer_workflow , commit

AER Report: Operator UI CI ran successfully ✅

aer_workflow , commit

@amit-momin amit-momin force-pushed the MERC-6516-Allow-disabling-TXM-completely-substitute-null-txm-for-mercury-where-it-isn-t-needed branch from 3b65ac2 to e29572f Compare December 16, 2024 20:29
@smartcontractkit smartcontractkit deleted a comment from github-actions bot Dec 16, 2024
@amit-momin amit-momin marked this pull request as ready for review December 16, 2024 21:42
@amit-momin amit-momin requested review from a team as code owners December 16, 2024 21:42
if err != nil {
return nil, fmt.Errorf("failed to instantiate EvmTxm for chain with ID %s: %w", chainID.String(), err)
var txm txmgr.TxManager
var gasEstimator gas.EvmFeeEstimator
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we consider creating a gas estimator even if TXM is disabled? Are there any paths in the code that might call it apart from the TXM. If they do, we might panic.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could for sanity. Otherwise, the existing code also returned nil for the gas estimator if EVMRPCEnabled=false.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the code to initialize the gas estimator regardless of the TXM toggle. I looked around and don't think there was any reference to gas estimator that would cause a panic but made the change anyways in case I missed something or if that changes in the future.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is an issue with the BlockHistory estimator though. Currently, TXM subscribes to HT and implements OnNewLongestChain, providing BHE with a new head. If TXM is nil, BHE won't be getting updates at all.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would only be an issue if the gas estimator gets started though right? I only separated out the initialization of the gas estimator from the TXM but it still relies on the TXM to start/stop it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assumed that since it gets initialized we would also want to start it, but I guess we don't. My only issue was that because it's initialized someone might try to fetch prices causing issues, but I noticed BHE has an IfStarted method for both GetLegacyGas and GetDynamicFee so we're ok.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could separate out the gas estimator lifecycle from the TXM and truly make it a standalone service but that's probably a separate ticket. For now, I'll still keep the initialization separate just to make sure we don't hit a panic anywhere in case this is called outside of the TXM.

Comment on lines 248 to 251
var gasEstimator gas.EvmFeeEstimator
if gasEstimator, err = newGasEstimator(cfg.EVM(), client, l, opts, clientsByChainID); err != nil {
return nil, fmt.Errorf("failed to instantiate gas estimator for chain with ID %s: %w", chainID, err)
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you're returning, there is no point in splitting the declaration from the initialization

Suggested change
var gasEstimator gas.EvmFeeEstimator
if gasEstimator, err = newGasEstimator(cfg.EVM(), client, l, opts, clientsByChainID); err != nil {
return nil, fmt.Errorf("failed to instantiate gas estimator for chain with ID %s: %w", chainID, err)
}
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)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weird... I was getting a shadow declaration on err which is why I did this but maybe my other changes fixed it. Fixed in the latest commit

// note: gas estimator is started as a part of the txm
txm, gasEstimator, err := newEvmTxm(opts.DS, cfg.EVM(), opts.AppConfig.EVMRPCEnabled(), opts.AppConfig.Database(), opts.AppConfig.Database().Listener(), client, l, logPoller, opts, headTracker, clientsByChainID)
// initialize gas estimator
gasEstimator, err := newGasEstimator(cfg.EVM(), client, l, opts, clientsByChainID)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We always initialize a gas estimator even if its never going to be used?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I can tell it isn't used as of now but we don't have a NullGasEstimator to use instead. It didn't seem like an issue to just initialize an actual instance of it though since it wouldn't be started if the TXM was disabled. But at least initializing it would prevent panic if anyone were to refer to it with the TXM disabled. They'd just get a gas estimator not started error instead.

samsondav
samsondav previously approved these changes Dec 19, 2024
@samsondav samsondav added this pull request to the merge queue Dec 19, 2024
Merged via the queue into develop with commit e706d72 Dec 19, 2024
170 checks passed
@samsondav samsondav deleted the MERC-6516-Allow-disabling-TXM-completely-substitute-null-txm-for-mercury-where-it-isn-t-needed branch December 19, 2024 20:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants