mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-20 11:46:44 +00:00
core: implement eip-7778: block gas accounting without refunds
This commit is contained in:
parent
31d5d82ce5
commit
7869c18c0a
2 changed files with 12 additions and 6 deletions
|
|
@ -528,6 +528,7 @@ func (st *stateTransition) execute() (*ExecutionResult, error) {
|
||||||
peakGasUsed := st.gasUsed()
|
peakGasUsed := st.gasUsed()
|
||||||
|
|
||||||
// Compute refund counter, capped to a refund quotient.
|
// Compute refund counter, capped to a refund quotient.
|
||||||
|
gasBeforeRefunds := peakGasUsed
|
||||||
st.gasRemaining += st.calcRefund()
|
st.gasRemaining += st.calcRefund()
|
||||||
if rules.IsPrague {
|
if rules.IsPrague {
|
||||||
// After EIP-7623: Data-heavy transactions pay the floor gas.
|
// After EIP-7623: Data-heavy transactions pay the floor gas.
|
||||||
|
|
@ -542,7 +543,7 @@ func (st *stateTransition) execute() (*ExecutionResult, error) {
|
||||||
peakGasUsed = floorDataGas
|
peakGasUsed = floorDataGas
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
st.returnGas()
|
st.returnGas(rules, gasBeforeRefunds)
|
||||||
|
|
||||||
effectiveTip := msg.GasPrice
|
effectiveTip := msg.GasPrice
|
||||||
if rules.IsLondon {
|
if rules.IsLondon {
|
||||||
|
|
@ -652,7 +653,7 @@ func (st *stateTransition) calcRefund() uint64 {
|
||||||
|
|
||||||
// returnGas returns ETH for remaining gas,
|
// returnGas returns ETH for remaining gas,
|
||||||
// exchanged at the original rate.
|
// exchanged at the original rate.
|
||||||
func (st *stateTransition) returnGas() {
|
func (st *stateTransition) returnGas(rules params.Rules, gasBeforeRefunds uint64) {
|
||||||
remaining := uint256.NewInt(st.gasRemaining)
|
remaining := uint256.NewInt(st.gasRemaining)
|
||||||
remaining.Mul(remaining, uint256.MustFromBig(st.msg.GasPrice))
|
remaining.Mul(remaining, uint256.MustFromBig(st.msg.GasPrice))
|
||||||
st.state.AddBalance(st.msg.From, remaining, tracing.BalanceIncreaseGasReturn)
|
st.state.AddBalance(st.msg.From, remaining, tracing.BalanceIncreaseGasReturn)
|
||||||
|
|
@ -661,9 +662,14 @@ func (st *stateTransition) returnGas() {
|
||||||
st.evm.Config.Tracer.OnGasChange(st.gasRemaining, 0, tracing.GasChangeTxLeftOverReturned)
|
st.evm.Config.Tracer.OnGasChange(st.gasRemaining, 0, tracing.GasChangeTxLeftOverReturned)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Also return remaining gas to the block gas counter so it is
|
if !rules.IsAmsterdam {
|
||||||
// available for the next transaction.
|
// Pre-Amsterdam return remaining gas to the block gas counter so it is
|
||||||
st.gp.AddGas(st.gasRemaining)
|
// available for the next transaction.
|
||||||
|
st.gp.AddGas(st.gasRemaining)
|
||||||
|
} else {
|
||||||
|
// Post-Amsterdam only return the remaining gas minus the refunds.
|
||||||
|
st.gp.AddGas(gasBeforeRefunds)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// gasUsed returns the amount of gas used up by the state transition.
|
// gasUsed returns the amount of gas used up by the state transition.
|
||||||
|
|
|
||||||
|
|
@ -358,7 +358,7 @@ const (
|
||||||
// this generates an increase in gas. There is at most one of such gas change per transaction.
|
// this generates an increase in gas. There is at most one of such gas change per transaction.
|
||||||
GasChangeTxRefunds GasChangeReason = 3
|
GasChangeTxRefunds GasChangeReason = 3
|
||||||
// GasChangeTxLeftOverReturned is the amount of gas left over at the end of transaction's execution that will be returned
|
// GasChangeTxLeftOverReturned is the amount of gas left over at the end of transaction's execution that will be returned
|
||||||
// to the chain. This change will always be a negative change as we "drain" left over gas towards 0. If there was no gas
|
// to the account. This change will always be a negative change as we "drain" left over gas towards 0. If there was no gas
|
||||||
// left at the end of execution, no such even will be emitted. The returned gas's value in Wei is returned to caller.
|
// left at the end of execution, no such even will be emitted. The returned gas's value in Wei is returned to caller.
|
||||||
// There is at most one of such gas change per transaction.
|
// There is at most one of such gas change per transaction.
|
||||||
GasChangeTxLeftOverReturned GasChangeReason = 4
|
GasChangeTxLeftOverReturned GasChangeReason = 4
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue