From 29d3142f7596f16dc2e00e6eb194cfe59cd11075 Mon Sep 17 00:00:00 2001 From: yihuang Date: Wed, 3 Apr 2024 16:57:42 +0800 Subject: [PATCH] Problem: invalid tx returns negative gas wanted (#253) Solution: - add checks --- baseapp/abci.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/baseapp/abci.go b/baseapp/abci.go index 25efa3b224f6..027f94763944 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -801,8 +801,14 @@ func (app *BaseApp) internalFinalizeBlock(ctx context.Context, req *abci.Request blockGasWanted uint64 ) for _, res := range txResults { - blockGasUsed += uint64(res.GasUsed) - blockGasWanted += uint64(res.GasWanted) + // GasUsed should not be -1 but just in case + if res.GasUsed > 0 { + blockGasUsed += uint64(res.GasUsed) + } + // GasWanted could be -1 if the tx is invalid + if res.GasWanted > 0 { + blockGasWanted += uint64(res.GasWanted) + } } app.finalizeBlockState.SetContext( app.finalizeBlockState.Context().