core, miner: revert block gas counter in case of invalid transaction (#26799)

This change fixes a flaw where, in certain scenarios, the block sealer did not accurately reset the remaining gas after failing to include an invalid transaction. Fixes #26791
This commit is contained in:
rjl493456442
2023-03-07 05:23:52 -05:00
committed by GitHub
parent 4688d3c8f4
commit 77e33e5a49
3 changed files with 17 additions and 4 deletions
+5 -2
View File
@@ -861,11 +861,14 @@ func (w *worker) updateSnapshot(env *environment) {
}
func (w *worker) commitTransaction(env *environment, tx *types.Transaction) ([]*types.Log, error) {
snap := env.state.Snapshot()
var (
snap = env.state.Snapshot()
gp = env.gasPool.Gas()
)
receipt, err := core.ApplyTransaction(w.chainConfig, w.chain, &env.coinbase, env.gasPool, env.state, env.header, tx, &env.header.GasUsed, *w.chain.GetVMConfig())
if err != nil {
env.state.RevertToSnapshot(snap)
env.gasPool.SetGas(gp)
return nil, err
}
env.txs = append(env.txs, tx)