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 L1 gas cost estimation feature to L1 gas oracle #11812

Merged
merged 8 commits into from
Jan 25, 2024

Conversation

amit-momin
Copy link
Contributor

Added the ability to retrieve L1 gas cost estimation from the L1 gas oracle for Arbitrum, Optimism, and Scroll

Copy link
Contributor

I see that you haven't updated any README files. Would it make sense to do so?

@amit-momin amit-momin marked this pull request as ready for review January 18, 2024 19:36
precompile := common.HexToAddress(o.l1GasPriceAddress)
callData, err = o.l1GasPriceMethodAbi.Pack(o.gasPriceMethod)
if err != nil {
o.logger.Errorf("failed to pack calldata for %s L1 gas price method: %w", o.chainType, err)
Copy link
Contributor

Choose a reason for hiding this comment

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

I know this behavior is same as previously.
But in these cases of errors, could we set them somewhere, and let it be reportable via HealthReport()?
Currently I see HealthReport always reports Healthy.

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 updated the code to append these errors to the SvcErrBuffer which should return all of the errors joined together when Healthy() is called.

PollPeriod = 12 * time.Second

// RPC call timeout
queryTimeout = 10 * time.Second
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure, but is it possible to use a configured RPC timeout like other components are doing?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ideally let's reuse something that already exists

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 tried to look through existing configs and didn't find one for RPC timeouts. Even in chains/evm/client, we have 10s hard coded which is used by ContextWithDefaultTimeout. It makes sense for this to be configurable but I think I'd have to add a new config for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually I see RequestTimeout for Starknet which I could maybe leverage. But it may be misleading if the rest of our code isn't using this config for RPC timeouts.

Copy link
Collaborator

@dimriou dimriou Jan 24, 2024

Choose a reason for hiding this comment

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

Yeah, QueryTimeout was the config I was thinking of. You can probably use evmclient.ContextWithDefaultTimeout() here instead of having a new config and let the client handle the timeout.

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 updated the code to use the client.QueryTimeout. I was avoiding using ContextWithDefaultTimeout since it just uses context.Background() under the hood and we have a ctx passed into the method we could use.

KromaGasOracle_l1BaseFee = "l1BaseFee"

// Interval at which to poll for L1BaseFee. A good starting point is the L1 block time.
PollPeriod = 12 * time.Second
Copy link
Contributor

Choose a reason for hiding this comment

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

I know this is same as previously.
But 12 seconds could sometimes mean our price estimates can be 11-12 seconds stale.
Could we make this a configurable setting, or if not, atleast change the default to 6 seconds?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks like we don't have an existing config for gas estimator poll periods so I just updated this to 6. It's hard coded in other places too like here and here. Maybe I can handle adding a configurable PollPeriod under [GasEstimator] configs in another ticket for all estimators.

}
}

func (o *l1Oracle) refresh() (t *time.Timer) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe for a future PR.
But we ought to have some logic to start giving errors to all methods from the l1Oracle, if we fail to fetch fresh prices for last 12-20 seconds.
Otherwise with current logic, we keep using stale prices, which may be worse behavior for applications.
Perhaps if we just report errors in such cases, it may be better.

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 added tracking for when the price was refreshed so we can validate for stale prices on read. Is this what you had in mind?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, perfect!

Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there a link where we can find these ABIs? It would be nice to add it here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea. I just got them from arbiscan and optimistic.etherscan but I can link those in the comments.

@cl-sonarqube-production
Copy link

@prashantkumar1982 prashantkumar1982 added this pull request to the merge queue Jan 25, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jan 25, 2024
@prashantkumar1982 prashantkumar1982 added this pull request to the merge queue Jan 25, 2024
Merged via the queue into develop with commit e20511d Jan 25, 2024
92 checks passed
@prashantkumar1982 prashantkumar1982 deleted the feature/l1-gas-cost-estimation branch January 25, 2024 21:14
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