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

op-e2e: Fix bug in TestWithdrawals #5931

Merged

Conversation

jyellick
Copy link
Contributor

@jyellick jyellick commented Jun 8, 2023

The existing TestWithdrawals test attempts to assert that the total fees of the prove and finalize transactions are accounted for in the L1 balance. But, it re-uses the calcGasFees function and passes in the GasTipCap and the GasFeeCap from the L2 transaction, not from the actual L1 transactions. In the event that the gas fee differs on the L2 from the L1, then the test will fail.

To keep the diff small, this change simply multiplies the GasUsed and EffectiveGasPrice from the receipts. This could be moved into a helper function like calcGasFees. Using the EffectiveGasPrice seems just as good or better than relying on the parameters of the original transaction, and could be similarly utilized higher in the test for the L2 fees. If we really want to get the parameters from the tx, then ProveAndFinalizeWithdrawal would need to be modified to return the txes.

FWIW, I encountered this when using Erigon for the L2 nodes, which compute the SuggestedGasTip slightly differently from Geth resulting in a discrepancy between the L1 and L2 gas tips, but this could conceivably cause flakiness even when using Geth.

@jyellick jyellick requested a review from a team as a code owner June 8, 2023 18:21
@jyellick jyellick requested a review from tynes June 8, 2023 18:21
@changeset-bot
Copy link

changeset-bot bot commented Jun 8, 2023

⚠️ No Changeset found

Latest commit: 769fe00

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@netlify
Copy link

netlify bot commented Jun 8, 2023

Deploy Preview for opstack-docs canceled.

Name Link
🔨 Latest commit 769fe00
🔍 Latest deploy log https://app.netlify.com/sites/opstack-docs/deploys/648233acb10c630008666c6f

@trianglesphere
Copy link
Contributor

hmm, proveReceipt & finalizedReceipt are pulled from L1, not L2.

How is the difference in SuggestedGasTip between erigon/geth showing up here?

@jyellick
Copy link
Contributor Author

jyellick commented Jun 8, 2023

Maybe the Erigon comment was more confusing than it was helpful. To be clear, the bug is that the fee computation is using the gas usage from L1, with the gas pricing from an L2 tx. That is the bug this PR fixes.

The test currently passes because it is using a Geth for both L1 and L2 nodes, which returns the same SuggestedGasTip (1 Gwei) when there is no tip history to infer from. Because the SuggestedGasTip is the same for both L1 and L2, the actual GasTip for the L2 transaction ends up being the same as the GasTip for the L1 transaction. Therefore the test passes even though we're mixing up the L1 and L2 GasTips.

When using Erigon for the L2 nodes, the SuggestedGasTip returns a different suggested gas tip (0 Gwei). So, now the GasTip on the L1 txes (1 Gwei) is not the same as the GasTip on the L2 tx (0 Gwei), so the test fails. Erigon is not breaking anything, it's just the test's assertion that has the bug.

Personally, I'm not entirely sure why calcGasFees takes the parameters from the tx (tip and fee cap), the receipt (gas used), and the header (baseFee) to compute the gas fees. We could instead simply take the gas used and effective gas price from the receipt as this change does. To my understanding, Optimism does not modify the EIP-1559 logic in any way, so I'm not sure what value we're getting by manually computing the gas fee ourselves. I'd be happy to modify calcGasFees and its callers if you agree.

The existing TestWithdrawals test attempts to assert that the total fees
of the prove and finalize transactions are accounted for in the L1
balance.  But, it re-uses the `calcGasFees` function and passes in the
`GasTipCap` and the `GasFeeCap` from the L2 transaction, not from the
actual L1 transactions.  In the event that the gas fee differs on the L2
from the L1, then the test will fail.

To keep the diff small, this change simply multiplies the GasUsed and
`EffectiveGasPrice` from the receipts.  This could be moved into a
helper function like `calcGasFees`.  Using the `EffectiveGasPrice` seems
just as good or better than relying on the parameters of the original
transaction, and could be similarly utilized higher in the test for the
L2 fees.  If we really want to get the parameters from the tx, then
`ProveAndFinalizeWithdrawal` would need to be modified to return the
txes.
Copy link
Contributor

@ajsutton ajsutton left a comment

Choose a reason for hiding this comment

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

Funnily enough, hit this with the latest op-geth as well because it changes the fee estimation for OP networks so L1 and L2 wind up returning different GasTips (#5938).

The test is confirming that the L1 contract transfers the correct amount of ETH so I agree its reasonable to trust the EffectiveGasPrice from the receipt rather than having to calculate from the transaction.

Thanks.

@mergify
Copy link
Contributor

mergify bot commented Jun 9, 2023

This PR has been added to the merge queue, and will be merged soon.

@mergify
Copy link
Contributor

mergify bot commented Jun 9, 2023

Hey @jyellick, this pull request failed to merge and has been dequeued from the merge train. If you believe your PR failed in the merge train because of a flaky test, requeue it by commenting with @mergifyio requeue.
More details can be found on the Queue: Embarked in merge train check-run.

@ajsutton ajsutton merged commit a80c4d6 into ethereum-optimism:develop Jun 9, 2023
77 of 90 checks passed
@jyellick jyellick deleted the fix-withdrawals-test branch September 1, 2023 13:45
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.

None yet

3 participants