-
Notifications
You must be signed in to change notification settings - Fork 21.9k
core: implement eip-7778: block gas accounting without refunds #33593
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
Changes from all commits
2e5c9c2
c6f6dbc
87c071b
4749593
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -34,7 +34,7 @@ import ( | |||||||||||
| // ExecutionResult includes all output after executing given evm | ||||||||||||
| // message no matter the execution itself is successful or not. | ||||||||||||
| type ExecutionResult struct { | ||||||||||||
| UsedGas uint64 // Total used gas, not including the refunded gas | ||||||||||||
| UsedGas uint64 // Total used gas, refunded gas is deducted | ||||||||||||
| MaxUsedGas uint64 // Maximum gas consumed during execution, excluding gas refunds. | ||||||||||||
| Err error // Any error encountered during the execution(listed in core/vm/errors.go) | ||||||||||||
| ReturnData []byte // Returned data from evm(function result or data supplied with revert opcode) | ||||||||||||
|
|
@@ -210,6 +210,11 @@ func TransactionToMessage(tx *types.Transaction, s types.Signer, baseFee *big.In | |||||||||||
| // indicates a core error meaning that the message would always fail for that particular | ||||||||||||
| // state and would never be accepted within a block. | ||||||||||||
| func ApplyMessage(evm *vm.EVM, msg *Message, gp *GasPool) (*ExecutionResult, error) { | ||||||||||||
| // Do not panic if the gas pool is nil. This is allowed when executing | ||||||||||||
| // a single message via RPC invocation. | ||||||||||||
| if gp == nil { | ||||||||||||
| gp = NewGasPool(msg.GasLimit) | ||||||||||||
| } | ||||||||||||
| evm.SetTxContext(NewEVMTxContext(msg)) | ||||||||||||
| return newStateTransition(evm, msg, gp).execute() | ||||||||||||
| } | ||||||||||||
|
|
@@ -300,8 +305,8 @@ func (st *stateTransition) buyGas() error { | |||||||||||
| st.evm.Config.Tracer.OnGasChange(0, st.msg.GasLimit, tracing.GasChangeTxInitialBalance) | ||||||||||||
| } | ||||||||||||
| st.gasRemaining = st.msg.GasLimit | ||||||||||||
|
|
||||||||||||
| st.initialGas = st.msg.GasLimit | ||||||||||||
|
|
||||||||||||
| mgvalU256, _ := uint256.FromBig(mgval) | ||||||||||||
| st.state.SubBalance(st.msg.From, mgvalU256, tracing.BalanceDecreaseGasBuy) | ||||||||||||
| return nil | ||||||||||||
|
|
@@ -542,8 +547,20 @@ func (st *stateTransition) execute() (*ExecutionResult, error) { | |||||||||||
| peakGasUsed = floorDataGas | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
| // Return gas to the user | ||||||||||||
| st.returnGas() | ||||||||||||
|
|
||||||||||||
| // Return gas to the gas pool | ||||||||||||
| if rules.IsAmsterdam { | ||||||||||||
| // Refund is excluded for returning | ||||||||||||
| err = st.gp.ReturnGas(st.initialGas-peakGasUsed, st.gasUsed()) | ||||||||||||
| } else { | ||||||||||||
| // Refund is included for returning | ||||||||||||
| err = st.gp.ReturnGas(st.gasRemaining, st.gasUsed()) | ||||||||||||
| } | ||||||||||||
| if err != nil { | ||||||||||||
| return nil, err | ||||||||||||
| } | ||||||||||||
| effectiveTip := msg.GasPrice | ||||||||||||
| if rules.IsLondon { | ||||||||||||
| effectiveTip = new(big.Int).Sub(msg.GasPrice, st.evm.Context.BaseFee) | ||||||||||||
|
|
@@ -564,7 +581,6 @@ func (st *stateTransition) execute() (*ExecutionResult, error) { | |||||||||||
| st.evm.AccessEvents.AddAccount(st.evm.Context.Coinbase, true, math.MaxUint64) | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| return &ExecutionResult{ | ||||||||||||
| UsedGas: st.gasUsed(), | ||||||||||||
| MaxUsedGas: peakGasUsed, | ||||||||||||
|
|
@@ -660,10 +676,6 @@ func (st *stateTransition) returnGas() { | |||||||||||
| if st.evm.Config.Tracer != nil && st.evm.Config.Tracer.OnGasChange != nil && st.gasRemaining > 0 { | ||||||||||||
| st.evm.Config.Tracer.OnGasChange(st.gasRemaining, 0, tracing.GasChangeTxLeftOverReturned) | ||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we want to update the enum comment? It currently says “returned to the chain,” which might be confusing post-Amsterdam. I figured I would point this out just in case. go-ethereum/core/tracing/hooks.go Lines 360 to 364 in 5a1990d
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, it should definitely be updated to indicate that the refunds are only to accounts and not the gas pool after Amsterdam. |
||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| // Also return remaining gas to the block gas counter so it is | ||||||||||||
| // available for the next transaction. | ||||||||||||
| st.gp.AddGas(st.gasRemaining) | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| // gasUsed returns the amount of gas used up by the state transition. | ||||||||||||
|
|
||||||||||||
Uh oh!
There was an error while loading. Please reload this page.