Skip to content

Commit 1ac3c16

Browse files
committed
core, miner: revert block gas counter in case of invalid transaction
1 parent 27e5982 commit 1ac3c16

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

core/gaspool.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ func (gp *GasPool) Gas() uint64 {
4949
return uint64(*gp)
5050
}
5151

52+
// SetGas sets the amount of gas with the provided number.
53+
func (gp *GasPool) SetGas(gas uint64) {
54+
*(*uint64)(gp) = gas
55+
}
56+
5257
func (gp *GasPool) String() string {
5358
return fmt.Sprintf("%d", *gp)
5459
}

miner/worker.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -861,11 +861,14 @@ func (w *worker) updateSnapshot(env *environment) {
861861
}
862862

863863
func (w *worker) commitTransaction(env *environment, tx *types.Transaction) ([]*types.Log, error) {
864-
snap := env.state.Snapshot()
865-
864+
var (
865+
snap = env.state.Snapshot()
866+
gp = env.gasPool.Gas()
867+
)
866868
receipt, err := core.ApplyTransaction(w.chainConfig, w.chain, &env.coinbase, env.gasPool, env.state, env.header, tx, &env.header.GasUsed, *w.chain.GetVMConfig())
867869
if err != nil {
868870
env.state.RevertToSnapshot(snap)
871+
env.gasPool.SetGas(gp)
869872
return nil, err
870873
}
871874
env.txs = append(env.txs, tx)

0 commit comments

Comments
 (0)