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

txmgr: call EstimateGas correctly for blob tx #12086

Merged
merged 1 commit into from
Sep 26, 2024

Conversation

zhiqiangxu
Copy link
Contributor

@zhiqiangxu zhiqiangxu commented Sep 24, 2024

SimpleTxManager is a generic tool for sending tx used by various components, and the candidate tx may be a blob tx.

This PR makes EstimateGas work correctly for blob tx.

@zhiqiangxu zhiqiangxu requested a review from a team as a code owner September 24, 2024 16:16
Copy link
Contributor

@geoknee geoknee left a comment

Choose a reason for hiding this comment

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

Thanks @zhiqiangxu. Are you able to add or modify unit tests for this?

@zhiqiangxu
Copy link
Contributor Author

Is there an example for such test?

It needs to be like:

  1. Prepare a contract that's requiring tx blob(e.g., revert if no blob)
  2. Do estimation to call it.

Without this PR it should revert.

@geoknee
Copy link
Contributor

geoknee commented Sep 26, 2024

Is there an example for such test?

It needs to be like:

  1. Prepare a contract that's requiring tx blob(e.g., revert if no blob)
  2. Do estimation to call it.

Without this PR it should revert.

I don't think we need to go to those lengths. I was thinking we could trigger the code path in question inside this test or variant of it where the candidate.GasLimit = 0:

// TestTxMgr_CraftBlobTx ensures that the tx manager will create blob transactions as expected.
func TestTxMgr_CraftBlobTx(t *testing.T) {
t.Parallel()
h := newTestHarness(t)
candidate := h.createBlobTxCandidate()
// Craft the transaction.
gasTipCap, gasFeeCap, _ := h.gasPricer.feesForEpoch(h.gasPricer.epoch + 1)
tx, err := h.mgr.craftTx(context.Background(), candidate)
require.Nil(t, err)
require.NotNil(t, tx)
require.Equal(t, byte(types.BlobTxType), tx.Type())
// Validate the gas tip cap and fee cap.
require.Equal(t, gasTipCap, tx.GasTipCap())
require.Equal(t, gasFeeCap, tx.GasFeeCap())
require.Equal(t, defaultMinBlobTxFee, tx.BlobGasFeeCap())
// Validate the nonce was set correctly using the backend.
require.Equal(t, uint64(startingNonce), tx.Nonce())
// Check that the gas was set using the gas limit.
require.Equal(t, candidate.GasLimit, tx.Gas())

Then we would need to assert that the gas limit is estimated high enough. If you run the test with and without your changes, I think you would expect different gas in each case -- this helps to understand the nature of the bug here.

@zhiqiangxu
Copy link
Contributor Author

Sorry I don't quite understand how's your plan to test it.

The original implementation doesn't carry the blob hash over when estimating, but it doesn't necessarily lead to higher or lower gas IMO.

@geoknee
Copy link
Contributor

geoknee commented Sep 26, 2024

Ah yes I think you are right, the transaction will be charged for blobGas but this is independent of the regular gas estimated in backend.EstimateGas. But this then begs the question, what difference does it make to put the blob information inside the call to EstimateGas? Is it not working correctly already?

@zhiqiangxu
Copy link
Contributor Author

zhiqiangxu commented Sep 26, 2024

Ah yes I think you are right, the transaction will be charged for blobGas but this is independent of the regular gas estimated in backend.EstimateGas. But this then begs the question, what difference does it make to put the blob information inside the call to EstimateGas? Is it not working correctly already?

Yeah it will not work for a contract that's requiring tx blob(e.g., revert if no blob) or any contract that's making use of blobs.

It's quite hard to simulate it in unit test, but I'm quite confident it's a correct change.

@geoknee geoknee changed the title support EstimateGas correctly for blob tx txmgr: call EstimateGas correctly for blob tx Sep 26, 2024
@geoknee
Copy link
Contributor

geoknee commented Sep 26, 2024

I see, the gas estimation could completely in that corner case. On reflection it doesn't seem worth the effort to add any more tests for this.

@tynes tynes added this pull request to the merge queue Sep 26, 2024
Merged via the queue into ethereum-optimism:develop with commit c65c1f8 Sep 26, 2024
65 checks passed
samlaf pushed a commit to samlaf/optimism that referenced this pull request Nov 10, 2024
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