core, miner: log gas limit error when pack transactions (#1905)

This commit is contained in:
Daniel Liu 2026-01-04 19:51:34 +08:00 committed by GitHub
parent 51e3c866c8
commit be5cfd9756
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 6 additions and 6 deletions

View file

@ -38,7 +38,7 @@ func (gp *GasPool) AddGas(amount uint64) *GasPool {
// available and returns an error otherwise. // available and returns an error otherwise.
func (gp *GasPool) SubGas(amount uint64) error { func (gp *GasPool) SubGas(amount uint64) error {
if uint64(*gp) < amount { if uint64(*gp) < amount {
return ErrGasLimitReached return fmt.Errorf("%w, have: %d, need: %d", ErrGasLimitReached, uint64(*gp), amount)
} }
*(*uint64)(gp) -= amount *(*uint64)(gp) -= amount
return nil return nil

View file

@ -158,7 +158,7 @@ func TestStateProcessorErrors(t *testing.T) {
txs: []*types.Transaction{ txs: []*types.Transaction{
makeTx(key1, 0, common.Address{}, big.NewInt(0), 21000000, big.NewInt(12500000000), nil), makeTx(key1, 0, common.Address{}, big.NewInt(0), 21000000, big.NewInt(12500000000), nil),
}, },
want: "could not apply tx 0 [0x062b0e84f2d48f09f91e434fca8cb1fb864c4fb82f8bf27d58879ebe60c9f773]: gas limit reached", want: "could not apply tx 0 [0x062b0e84f2d48f09f91e434fca8cb1fb864c4fb82f8bf27d58879ebe60c9f773]: gas limit reached, have: 4712388, need: 21000000",
}, },
{ // ErrInsufficientFundsForTransfer { // ErrInsufficientFundsForTransfer
txs: []*types.Transaction{ txs: []*types.Transaction{
@ -186,7 +186,7 @@ func TestStateProcessorErrors(t *testing.T) {
txs: []*types.Transaction{ txs: []*types.Transaction{
makeTx(key1, 0, common.Address{}, big.NewInt(0), params.TxGas*1000, big.NewInt(12500000000), nil), makeTx(key1, 0, common.Address{}, big.NewInt(0), params.TxGas*1000, big.NewInt(12500000000), nil),
}, },
want: "could not apply tx 0 [0x062b0e84f2d48f09f91e434fca8cb1fb864c4fb82f8bf27d58879ebe60c9f773]: gas limit reached", want: "could not apply tx 0 [0x062b0e84f2d48f09f91e434fca8cb1fb864c4fb82f8bf27d58879ebe60c9f773]: gas limit reached, have: 4712388, need: 21000000",
}, },
{ // ErrFeeCapTooLow { // ErrFeeCapTooLow
txs: []*types.Transaction{ txs: []*types.Transaction{

View file

@ -970,7 +970,7 @@ func (w *Work) commitTransactions(mux *event.TypeMux, balanceFee map[common.Addr
} }
if gp.Gas() < params.TxGas && tx.Gas() > 0 { if gp.Gas() < params.TxGas && tx.Gas() > 0 {
log.Trace("Not enough gas for further transactions", "gp", gp) log.Warn("Not enough gas for further transactions", "hash", tx.Hash().Hex(), "tx.Gas", tx.Gas(), "gp", gp, "need", params.TxGas)
break break
} }
// Error may be ignored here. The error has already been checked // Error may be ignored here. The error has already been checked
@ -1033,7 +1033,7 @@ func (w *Work) commitTransactions(mux *event.TypeMux, balanceFee map[common.Addr
for { for {
// If we don't have enough gas for any further transactions then we're done // If we don't have enough gas for any further transactions then we're done
if gp.Gas() < params.TxGas { if gp.Gas() < params.TxGas {
log.Trace("Not enough gas for further transactions", "gp", gp) log.Warn("Not enough gas for further transactions", "gp", gp, "need", params.TxGas)
break break
} }
if txs == nil { if txs == nil {
@ -1115,7 +1115,7 @@ func (w *Work) commitTransactions(mux *event.TypeMux, balanceFee map[common.Addr
switch { switch {
case errors.Is(err, core.ErrGasLimitReached): case errors.Is(err, core.ErrGasLimitReached):
// Pop the current out-of-gas transaction without shifting in the next from the account // Pop the current out-of-gas transaction without shifting in the next from the account
log.Trace("Gas limit exceeded for current block", "sender", from) log.Warn("Gas limit exceeded for current block", "hash", tx.Hash().Hex(), "tx.Gas", tx.Gas(), "err", err)
txs.Pop() txs.Pop()
case errors.Is(err, core.ErrNonceTooLow): case errors.Is(err, core.ErrNonceTooLow):