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

core: switch EVM tx context in ApplyMessage #30809

Merged
merged 8 commits into from
Nov 29, 2024

Conversation

rjl493456442
Copy link
Member

@rjl493456442 rjl493456442 commented Nov 26, 2024

This pull request relocates the EVM tx context switching to the ApplyMessage function.
With this change, we can remove a tons of EVM.SetTxContext call before the message
execution for simplification.

Tracing API changes

  • This PR replaces the GasPrice field of the VMContext struct with BaseFee. Users may instead take the effective gas price from tx.EffectiveGasTipValue(env.BaseFee).

@@ -605,7 +605,7 @@ func (evm *EVM) GetVMContext() *tracing.VMContext {
BlockNumber: evm.Context.BlockNumber,
Time: evm.Context.Time,
Random: evm.Context.Random,
GasPrice: evm.TxContext.GasPrice,
Copy link
Member Author

Choose a reason for hiding this comment

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

@s1na it might be an incompatible change, but I feel like it's the right direction.

The effectiveGasPrice could be derived with BaseFee (block context) and tx gas price.

Originally, we must to invoke evm.SetTxContext before the TxStartHook, with this change, the requirement is gone

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm.. Why not just move the tracer stuff a bit? We ought to be able to get the tx-specific stuff into OnTxStart?

Copy link
Contributor

Choose a reason for hiding this comment

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

Wait a minute. The TxStart hook:

	TxStartHook = func(vm *VMContext, tx *types.Transaction, from common.Address)

It has the tx. The tx has a GasPrice method. Why would we have it also in the VMContext? Gary's change makes total sense

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good to me

Copy link
Contributor

@maoueh maoueh Nov 26, 2024

Choose a reason for hiding this comment

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

For info, in our case, we indeed take the gasPrice from the transaction and not from the *VMContext struct in our tracer.

Copy link
Member Author

Choose a reason for hiding this comment

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

@maoueh Just want to mention that the GasPrice taken from the transaction object is the different with one in the *tracing.VMContext, the first one refers to the full gas price while the latter one refers to the effectiveGasPrice

Copy link
Contributor

Choose a reason for hiding this comment

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

@rjl493456442 Yes thanks for the info. We are handling the different tx types to pick the correct gas values.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should bring it back in another tracing API version. The tracer implementation should not have to compute the effective gas price by itself. It should be handled by the tracing infrastructure.

@rjl493456442 rjl493456442 added this to the 1.14.13 milestone Nov 27, 2024
Copy link
Contributor

@holiman holiman left a comment

Choose a reason for hiding this comment

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

LGTM

@rjl493456442
Copy link
Member Author

@s1na May I get your approval?

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.

SGTM

@fjl fjl mentioned this pull request Nov 29, 2024
@fjl fjl merged commit a793bc7 into ethereum:master Nov 29, 2024
3 checks passed
@fjl fjl changed the title all: switch evm tx context in the applyMessage core: switch EVM tx context in ApplyMessage Nov 29, 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.

6 participants