mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-03-07 11:55:13 +00:00
core: fix mining issues
This commit is contained in:
parent
964a117ea7
commit
95c278fc20
2 changed files with 15 additions and 3 deletions
|
|
@ -76,12 +76,18 @@ func (gp *GasPool) ReturnGas(returned uint64, gasUsed uint64) error {
|
|||
// ReturnGasAmsterdam returns unused gas to the pool using two-dimensional
|
||||
// gas accounting (EIP-8037). receiptGasUsed is the per-tx gas the user pays
|
||||
// (tx.gas - gas_left - state_gas_reservoir), used for receipt cumulative tracking.
|
||||
//
|
||||
// The block gas increment for this tx is the change in max(sumR, sumS) after
|
||||
// adding the tx's per-dimension values, NOT max(txR, txS) per-tx. This avoids
|
||||
// overcounting when the dominant dimension switches between transactions.
|
||||
func (gp *GasPool) ReturnGasAmsterdam(txGasLimit, txRegular, txState, receiptGasUsed uint64) error {
|
||||
txBlockGas := max(txRegular, txState)
|
||||
oldUsed := max(gp.cumulativeRegular, gp.cumulativeState)
|
||||
gp.cumulativeRegular += txRegular
|
||||
gp.cumulativeState += txState
|
||||
gp.cumulativeUsed += receiptGasUsed
|
||||
returned := txGasLimit - txBlockGas
|
||||
newUsed := max(gp.cumulativeRegular, gp.cumulativeState)
|
||||
blockGasIncrement := newUsed - oldUsed
|
||||
returned := txGasLimit - blockGasIncrement
|
||||
if gp.remaining > math.MaxUint64-returned {
|
||||
return fmt.Errorf("%w: remaining: %d, returned: %d", ErrGasLimitOverflow, gp.remaining, returned)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -223,6 +223,10 @@ func (miner *Miner) generateWork(genParam *generateParams, witness bool) *newPay
|
|||
}
|
||||
}
|
||||
|
||||
// EIP-8037: set header.GasUsed before FinalizeAndAssemble so the block
|
||||
// header reflects the correct 2D gas metric max(sum_regular, sum_state).
|
||||
work.header.GasUsed = work.gasPool.Used()
|
||||
|
||||
block, err := miner.engine.FinalizeAndAssemble(miner.chain, work.header, work.state, &body, work.receipts, onBlockFinalization)
|
||||
if err != nil {
|
||||
return &newPayloadResult{err: err}
|
||||
|
|
@ -329,7 +333,9 @@ func (miner *Miner) prepareWork(genParams *generateParams, witness bool) (*envir
|
|||
if miner.chainConfig.IsPrague(header.Number, header.Time) {
|
||||
mut.Merge(core.ProcessParentBlockHash(header.ParentHash, env.evm))
|
||||
}
|
||||
env.accessList.AccumulateMutations(mut, 0)
|
||||
if env.accessList != nil {
|
||||
env.accessList.AccumulateMutations(mut, 0)
|
||||
}
|
||||
return env, nil
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue