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

Update L1 gas price calculations for Optimism Ecotone and Fjord upgrades #13661

Merged

Conversation

amit-momin
Copy link
Contributor

@amit-momin amit-momin commented Jun 21, 2024

Description

Updates the L1 gas price calculations in our Optimism L1 oracle component for the Ecotone and Fjord upgrade. The Fjord upgrade deprecates the getL1GasUsed method that is currently being used. It was identified that the gas price can be calculated directly without relying on this method for both Ecotone and Fjord. It now uses the following formula:

(l1BaseFee * 16 * baseFeeScalar + blobBaseFee * blobBaseFeeScalar) / (16 * 10 ^ decimals)

Ticket

https://smartcontract-it.atlassian.net/browse/BCI-3516

@amit-momin amit-momin force-pushed the BCI-3516-Update-Optimism-L1-Oracle-for-Fjord-Hard-Fork branch from e4e8072 to 492c6f7 Compare June 21, 2024 21:18
@amit-momin amit-momin marked this pull request as ready for review June 21, 2024 21:42
@amit-momin amit-momin requested a review from a team as a code owner June 21, 2024 21:42
Copy link
Collaborator

Choose a reason for hiding this comment

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

We need to remove panics

Copy link
Collaborator

Choose a reason for hiding this comment

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

Moving the errors inside the constructor seems like an anti-pattern and perhaps it would be better if we did the initialization during Start. I guess for now we can leave it as it is, it's no big deal.

OPStackGasOracle_l1BaseFee = "l1BaseFee"
// OPStackGasOracle_getL1Fee fetches the l1 fee for given tx bytes
// OPStackGasOracle_getL1Fee is a hex encoded call to:
upgradePollingPeriod = 14400
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: perhaps we could change this to a more meaningful 4 * time.Hour type and use builtin time.Since method when checking for last update. Same goes for upgradeCheckTs. It's better if we change it to: upgradeCheckTs time.Time

Copy link
Contributor

@prashantkumar1982 prashantkumar1982 left a comment

Choose a reason for hiding this comment

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

Looks good, just 1 minor comment on an outdated comment

// OPStackGasOracle_getL1GasUsed fetches the l1 gas used for given tx bytes
OPStackGasOracle_getL1GasUsed = "getL1GasUsed"
// OPStackGasOracle_isEcotonePollingPeriod is the interval to poll if chain has upgraded to Ecotone
// isUpgradedPollingPeriod is the interval to poll if chain has been upgraded
Copy link
Contributor

Choose a reason for hiding this comment

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

nit outdated comment?

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've updated it in the latest commit

func (o *optimismL1Oracle) checkForUpgrade(ctx context.Context) error {
// if chain is already Fjord (the latest upgrade), NOOP
// need to continue to check if not on latest upgrade
if o.isFjord {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Don't we want to check for both?

Suggested change
if o.isFjord {
if o.isFjord || o.isEcotone {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we checked for both, we'd exit out early if the Ecotone upgrade is live. We wouldn't want to do this since we'd stop checking for the Fjord upgrade which is after. So we only want to exit early if the latest upgrade has already occurred.

Copy link
Collaborator

Choose a reason for hiding this comment

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

But Ecotone and Fjord have the same calculation formula, don't they?

Copy link
Contributor Author

@amit-momin amit-momin Jun 26, 2024

Choose a reason for hiding this comment

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

In that case, I don't think we'd even need the isFjord flag. We would never make the RPC call to update it with this change except during startup after the upgrade. My worry would be if we later need to add some Fjord specific logic this would not be as obvious for whoever makes the change if they trust checkForUpgrade to work as expected.


l1GasUsed := new(big.Int).SetBytes(l1GasUsedBytes)
l1Fee := new(big.Int).SetBytes(l1FeeBytes)
// Gas price = scaled gas price / (16 * 10 ^ decimals)
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: Can you add links for both Ecotone and Fjord that will verify this formula?

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've added the links and some context in the latest commit

@dimriou dimriou added this pull request to the merge queue Jun 28, 2024
Merged via the queue into develop with commit 363e829 Jun 28, 2024
113 checks passed
@dimriou dimriou deleted the BCI-3516-Update-Optimism-L1-Oracle-for-Fjord-Hard-Fork branch June 28, 2024 18:48
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.

3 participants