mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-19 19:30:44 +00:00
fix eip-7778 in the miner and BAL parallel state processor
This commit is contained in:
parent
022e460d1e
commit
bf0f959751
5 changed files with 18 additions and 16 deletions
|
|
@ -76,12 +76,16 @@ func (p *ParallelStateProcessor) prepareExecResult(block *types.Block, allStateR
|
|||
return cmp.Compare(a.TransactionIndex, b.TransactionIndex)
|
||||
})
|
||||
|
||||
var cumulativeGasUsed uint64
|
||||
var (
|
||||
cumulativeGasUsed uint64
|
||||
cumulativeBlockGasUsed uint64
|
||||
)
|
||||
var allLogs []*types.Log
|
||||
for _, receipt := range receipts {
|
||||
receipt.CumulativeGasUsed = cumulativeGasUsed + receipt.GasUsed
|
||||
cumulativeGasUsed += receipt.GasUsed
|
||||
if receipt.CumulativeGasUsed > header.GasLimit {
|
||||
cumulativeBlockGasUsed += receipt.BlockGasUsed
|
||||
if cumulativeBlockGasUsed > header.GasLimit {
|
||||
return &ProcessResultWithMetrics{
|
||||
ProcessResult: &ProcessResult{Error: fmt.Errorf("gas limit exceeded")},
|
||||
}
|
||||
|
|
@ -184,7 +188,7 @@ func (p *ParallelStateProcessor) resultHandler(block *types.Block, preTxStateRea
|
|||
if res.err != nil {
|
||||
execErr = res.err
|
||||
} else {
|
||||
if err := gp.SubGas(res.receipt.GasUsed); err != nil {
|
||||
if err := gp.SubGas(res.receipt.BlockGasUsed); err != nil {
|
||||
execErr = err
|
||||
} else {
|
||||
receipts = append(receipts, res.receipt)
|
||||
|
|
|
|||
|
|
@ -108,16 +108,9 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
|
|||
if err != nil {
|
||||
return nil, fmt.Errorf("could not apply tx %d [%v]: %w", i, tx.Hash().Hex(), err)
|
||||
}
|
||||
usedGas += receipt.GasUsed
|
||||
usedGas += receipt.BlockGasUsed
|
||||
receipts = append(receipts, receipt)
|
||||
allLogs = append(allLogs, receipt.Logs...)
|
||||
|
||||
/*
|
||||
enc, _ := json.MarshalIndent(receipt, "", " ")
|
||||
fmt.Printf("receipt json %s\n", string(enc))
|
||||
encRLP, _ := rlp.EncodeToBytes(receipt)
|
||||
fmt.Printf("receipt rlp %x\n", encRLP)
|
||||
*/
|
||||
}
|
||||
|
||||
// Read requests if Prague is enabled.
|
||||
|
|
@ -210,10 +203,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
|
||||
receipt.BlockGasUsed = result.MaxUsedGas
|
||||
} else {
|
||||
receipt.GasUsed = result.UsedGas
|
||||
receipt.BlockGasUsed = result.UsedGas
|
||||
}
|
||||
|
||||
if tx.Type() == types.BlobTxType {
|
||||
|
|
|
|||
|
|
@ -33,7 +33,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 gas used, with refunds subtracted
|
||||
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)
|
||||
|
|
|
|||
|
|
@ -63,6 +63,7 @@ type Receipt struct {
|
|||
TxHash common.Hash `json:"transactionHash" gencodec:"required"`
|
||||
ContractAddress common.Address `json:"contractAddress"`
|
||||
GasUsed uint64 `json:"gasUsed" gencodec:"required"`
|
||||
BlockGasUsed uint64 `json:"blockGasUsed"`
|
||||
EffectiveGasPrice *big.Int `json:"effectiveGasPrice"` // required, but tag omitted for backwards compatibility
|
||||
BlobGasUsed uint64 `json:"blobGasUsed,omitempty"`
|
||||
BlobGasPrice *big.Int `json:"blobGasPrice,omitempty"`
|
||||
|
|
|
|||
|
|
@ -66,7 +66,9 @@ type environment struct {
|
|||
coinbase common.Address
|
||||
evm *vm.EVM
|
||||
|
||||
header *types.Header
|
||||
header *types.Header
|
||||
blockGasUsed uint64 // block gas used incl refunds
|
||||
|
||||
txs []*types.Transaction
|
||||
receipts []*types.Receipt
|
||||
sidecars []*types.BlobTxSidecar
|
||||
|
|
@ -382,11 +384,12 @@ func (miner *Miner) applyTransaction(env *environment, tx *types.Transaction) (*
|
|||
snap = env.state.Snapshot()
|
||||
gp = env.gasPool.Gas()
|
||||
)
|
||||
receipt, err := core.ApplyTransaction(env.evm, env.gasPool, env.state, env.header, tx, &env.header.GasUsed)
|
||||
receipt, err := core.ApplyTransaction(env.evm, env.gasPool, env.state, env.header, tx, &env.blockGasUsed)
|
||||
if err != nil {
|
||||
env.state.RevertToSnapshot(snap)
|
||||
env.gasPool.SetGas(gp)
|
||||
}
|
||||
env.header.GasUsed += receipt.BlockGasUsed
|
||||
return receipt, err
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue