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

Set From address for gas limit estimation feature #14246

Merged
merged 4 commits into from
Aug 27, 2024

Conversation

amit-momin
Copy link
Contributor

Gas limit estimation can throw an error if the From address is not set and the call being estimated is privileged. eth_estimateGas would return an unauthorized error preventing proper gas limit estimation. In this case, we would still broadcast the tx but we would fallback to the provide gas limit which could be set very high compared to what is actually needed. This change passes the From address down to the gas estimator so it can be set in the callMsg.

@amit-momin amit-momin marked this pull request as ready for review August 27, 2024 15:50
@amit-momin amit-momin requested review from a team as code owners August 27, 2024 15:50
@amit-momin amit-momin requested review from jmank88 and removed request for a team August 27, 2024 15:50
@@ -191,7 +191,7 @@ func (w *chainWriter) GetFeeComponents(ctx context.Context) (*commontypes.ChainF
return nil, fmt.Errorf("gas estimator not available")
}

fee, _, err := w.ge.GetFee(ctx, nil, 0, w.maxGasPrice, nil)
fee, _, err := w.ge.GetFee(ctx, nil, 0, w.maxGasPrice, nil, nil)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible for this being nil to cause errors?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It shouldn't in this case. This parameter is only used for gas limit estimation and every parameter for thateth_estimateGas is optional. Since we're passing nil for calldata, from, and to, the gas estimation call would just return some default value. But that shouldn't matter here since the gas limit isn't being used.

@@ -36,11 +36,11 @@ type EvmFeeEstimator interface {

// L1Oracle returns the L1 gas price oracle only if the chain has one, e.g. OP stack L2s and Arbitrum.
L1Oracle() rollups.L1Oracle
GetFee(ctx context.Context, calldata []byte, feeLimit uint64, maxFeePrice *assets.Wei, toAddress *common.Address, opts ...feetypes.Opt) (fee EvmFee, estimatedFeeLimit uint64, err error)
GetFee(ctx context.Context, calldata []byte, feeLimit uint64, maxFeePrice *assets.Wei, fromAddress, toAddress *common.Address, opts ...feetypes.Opt) (fee EvmFee, estimatedFeeLimit uint64, err error)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not a big fan of adding more and more fields in the signature. At some point, it might make sense to just pass the transaction and access the fields internally, but I guess it's ok for now.

Copy link
Contributor Author

@amit-momin amit-momin Aug 27, 2024

Choose a reason for hiding this comment

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

Ya I agree. I even considered splitting gas price estimation from gas limit estimation and have a separate method for limits. Externally, it seems for the most part products and CW only care about the gas price so we could remove calldata, feeLimit, fromAddress, and toAddress. But think we're bound by Arbitrum's estimator for now so maybe it's something we can cleanup in the future

@@ -362,6 +362,9 @@ func (e *evmFeeEstimator) estimateFeeLimit(ctx context.Context, feeLimit uint64,
To: toAddress,
Data: calldata,
}
if fromAddress != nil {
Copy link
Collaborator

@dimriou dimriou Aug 27, 2024

Choose a reason for hiding this comment

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

Shouldn't fromAddress be treated the same way we treat toAddress ?

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 can't because of callMsg's typing

type CallMsg struct {
	From  common.Address
	To    *common.Address
}

@prashantkumar1982 prashantkumar1982 added this pull request to the merge queue Aug 27, 2024
Copy link
Contributor

@silaslenihan silaslenihan left a comment

Choose a reason for hiding this comment

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

LGTM

Merged via the queue into develop with commit f1bc2e7 Aug 27, 2024
150 checks passed
@prashantkumar1982 prashantkumar1982 deleted the fix/set-from-address-gas-limit-estimation branch August 27, 2024 17:13
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