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

ethapi: add block override to estimateGas #30695

Merged
merged 6 commits into from
Dec 12, 2024

Conversation

antonydenyer
Copy link
Contributor

Add block overrides to eth_estimateGas to align consistency with eth_call

#27800 (comment)

Fixes #28175

accounts/abi/abi.go Outdated Show resolved Hide resolved
@antonydenyer antonydenyer force-pushed the estimate-gas-block-overrides branch from 7702e9e to b304b13 Compare November 1, 2024 08:50
Chain: NewChainContext(ctx, b),
Header: header,
Chain: chainContext,
Header: blockOverrides.MakeHeader(header),
Copy link
Contributor

Choose a reason for hiding this comment

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

Please revert this line. The EVM doesn't have access to the header directly anyway. It only accesses block fields via the block context object.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah it took me a while to find this, I was taking most of the code fromDoCall path which doesn't do this. But the problem with the estimate path is that it uses the header in https://github.com/ethereum/go-ethereum/blob/master/eth/gasestimator/gasestimator.go#L221

Without this line the block overrides are not available in solidity code when running the unit test; this could be because is the test isn't setup correctly or it could genuinely be needed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Riighhtt this made me realize we should do this differently. Right now you're effectively only applying the block overrides to mutate the header and pass that to the gasestimator.

IMO we should pass in the overrides to gasestimator and apply them there just before execution. But that will create an import cycle. Hmm...

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 was surprised by the number of differences between the two endpoints. They are basically the same thing, except when they are not!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Another option is to move the gasestimator package up into the ethapi package to prevent this.

let me know what you think ...
c5af175

Copy link
Contributor

Choose a reason for hiding this comment

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

This was a deliberate change to move gas estimator out of rpc: #28600. let me think about it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alternatively, I could pass it in on the options, but that didn't feel right.

@s1na
Copy link
Contributor

s1na commented Nov 27, 2024

I moved the overrides to their own package so we can pass it down to gasestimator. @antonydenyer can you try this patch see if it works for you?

@@ -50,8 +51,8 @@ const (

// simBlock is a batch of calls to be simulated sequentially.
type simBlock struct {
BlockOverrides *BlockOverrides
StateOverrides *StateOverride
BlockOverrides *override.BlockOverrides
Copy link
Member

Choose a reason for hiding this comment

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

override.BlockOverrides kinda duplicates the "Overrides" part. Maybe we could rename it to override.Block and overrides.State wdyt? cc @fjl

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure, we could change the name. All of this is in internal/ anyway.

Copy link
Contributor

@fjl fjl Nov 28, 2024

Choose a reason for hiding this comment

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

I do think that introducing types Block and State is a bit weird, even though it's technically possible, because these words have a very definitive meaning already. I personally don't mind the duplication in naming for these 'override' types, since they are so low-use.

Copy link
Contributor

@s1na s1na left a comment

Choose a reason for hiding this comment

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

LGTM

@s1na s1na added this to the 1.14.13 milestone Dec 12, 2024
@s1na s1na merged commit 88cbfab into ethereum:master Dec 12, 2024
3 checks passed
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.

Use next block's context for eth_estimateGas
4 participants