Skip to content

Commit

Permalink
Bugfix: GasPool should return ErrGasLimitReached
Browse files Browse the repository at this point in the history
  • Loading branch information
jdowning100 committed Apr 29, 2024
1 parent 761d8ca commit 4b51928
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 0 additions & 4 deletions core/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,6 @@ var (
// next one expected based on the local chain.
ErrNonceTooHigh = errors.New("nonce too high")

// ErrGasLimitReached is returned by the gas pool if the amount of gas required
// by a transaction is higher than what's left in the block.
ErrGasLimitReached = errors.New("gas limit reached")

// ErrEtxLimitReached is returned when the ETXs emitted by a transaction
// would violate the block's ETX limits.
ErrEtxLimitReached = errors.New("etx limit reached")
Expand Down
6 changes: 5 additions & 1 deletion core/types/gaspool.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ import (
"math"
)

// ErrGasLimitReached is returned by the gas pool if the amount of gas required
// by a transaction is higher than what's left in the block.
var ErrGasLimitReached = errors.New("gas limit reached")

// GasPool tracks the amount of gas available during execution of the transactions
// in a block. The zero value is a pool with zero gas available.
type GasPool uint64
Expand All @@ -39,7 +43,7 @@ func (gp *GasPool) AddGas(amount uint64) *GasPool {
// available and returns an error otherwise.
func (gp *GasPool) SubGas(amount uint64) error {
if uint64(*gp) < amount {
return errors.New("gas limit reached")
return ErrGasLimitReached
}
*(*uint64)(gp) -= amount
return nil
Expand Down
2 changes: 1 addition & 1 deletion core/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -945,7 +945,7 @@ func (w *worker) commitTransactions(env *environment, parent *types.WorkObject,

logs, err := w.commitTransaction(env, parent, tx)
switch {
case errors.Is(err, ErrGasLimitReached):
case errors.Is(err, types.ErrGasLimitReached):
// Pop the current out-of-gas transaction without shifting in the next from the account
w.logger.WithField("sender", from).Trace("Gas limit exceeded for current block")
txs.PopNoSort()
Expand Down

0 comments on commit 4b51928

Please sign in to comment.