mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-19 03:10:48 +00:00
core: fix 7778 logic
This commit is contained in:
parent
7869c18c0a
commit
ce8f1bd856
2 changed files with 19 additions and 16 deletions
|
|
@ -61,7 +61,8 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
|
|||
var (
|
||||
config = p.chainConfig()
|
||||
receipts types.Receipts
|
||||
usedGas = new(uint64)
|
||||
chargedGas = new(uint64)
|
||||
usedGas = uint64(0)
|
||||
header = block.Header()
|
||||
blockHash = block.Hash()
|
||||
blockNumber = block.Number()
|
||||
|
|
@ -102,10 +103,11 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
|
|||
}
|
||||
statedb.SetTxContext(tx.Hash(), i)
|
||||
|
||||
receipt, err := ApplyTransactionWithEVM(msg, gp, statedb, blockNumber, blockHash, context.Time, tx, usedGas, evm)
|
||||
receipt, err := ApplyTransactionWithEVM(msg, gp, statedb, blockNumber, blockHash, context.Time, tx, chargedGas, evm)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not apply tx %d [%v]: %w", i, tx.Hash().Hex(), err)
|
||||
}
|
||||
usedGas += receipt.GasUsed
|
||||
receipts = append(receipts, receipt)
|
||||
allLogs = append(allLogs, receipt.Logs...)
|
||||
}
|
||||
|
|
@ -134,7 +136,7 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
|
|||
Receipts: receipts,
|
||||
Requests: requests,
|
||||
Logs: allLogs,
|
||||
GasUsed: *usedGas,
|
||||
GasUsed: usedGas,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
|
@ -183,7 +185,11 @@ func MakeReceipt(evm *vm.EVM, result *ExecutionResult, statedb *state.StateDB, b
|
|||
receipt.Status = types.ReceiptStatusSuccessful
|
||||
}
|
||||
receipt.TxHash = tx.Hash()
|
||||
receipt.GasUsed = result.UsedGas
|
||||
if evm.ChainConfig().IsAmsterdam(blockNumber, blockTime) {
|
||||
receipt.GasUsed = result.MaxUsedGas
|
||||
} else {
|
||||
receipt.GasUsed = result.UsedGas
|
||||
}
|
||||
|
||||
if tx.Type() == types.BlobTxType {
|
||||
receipt.BlobGasUsed = uint64(len(tx.BlobHashes()) * params.BlobTxBlobGasPerBlob)
|
||||
|
|
|
|||
|
|
@ -528,7 +528,6 @@ func (st *stateTransition) execute() (*ExecutionResult, error) {
|
|||
peakGasUsed := st.gasUsed()
|
||||
|
||||
// Compute refund counter, capped to a refund quotient.
|
||||
gasBeforeRefunds := peakGasUsed
|
||||
st.gasRemaining += st.calcRefund()
|
||||
if rules.IsPrague {
|
||||
// After EIP-7623: Data-heavy transactions pay the floor gas.
|
||||
|
|
@ -543,7 +542,14 @@ func (st *stateTransition) execute() (*ExecutionResult, error) {
|
|||
peakGasUsed = floorDataGas
|
||||
}
|
||||
}
|
||||
st.returnGas(rules, gasBeforeRefunds)
|
||||
// Return gas to the user
|
||||
st.returnGas()
|
||||
// Return gas to the gas pool
|
||||
if rules.IsAmsterdam {
|
||||
st.gp.AddGas(st.initialGas - peakGasUsed)
|
||||
} else {
|
||||
st.gp.AddGas(st.gasRemaining)
|
||||
}
|
||||
|
||||
effectiveTip := msg.GasPrice
|
||||
if rules.IsLondon {
|
||||
|
|
@ -653,7 +659,7 @@ func (st *stateTransition) calcRefund() uint64 {
|
|||
|
||||
// returnGas returns ETH for remaining gas,
|
||||
// exchanged at the original rate.
|
||||
func (st *stateTransition) returnGas(rules params.Rules, gasBeforeRefunds uint64) {
|
||||
func (st *stateTransition) returnGas() {
|
||||
remaining := uint256.NewInt(st.gasRemaining)
|
||||
remaining.Mul(remaining, uint256.MustFromBig(st.msg.GasPrice))
|
||||
st.state.AddBalance(st.msg.From, remaining, tracing.BalanceIncreaseGasReturn)
|
||||
|
|
@ -661,15 +667,6 @@ func (st *stateTransition) returnGas(rules params.Rules, gasBeforeRefunds uint64
|
|||
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)
|
||||
}
|
||||
|
||||
if !rules.IsAmsterdam {
|
||||
// Pre-Amsterdam return remaining gas to the block gas counter so it is
|
||||
// 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.
|
||||
|
|
|
|||
Loading…
Reference in a new issue