fix BlockGasRecovery

This commit is contained in:
rigelrozanski 2018-11-22 12:34:13 -05:00
parent 2d3e1afea8
commit 56fa7dc4ef
2 changed files with 12 additions and 8 deletions

View File

@ -704,16 +704,20 @@ func (app *BaseApp) runTx(mode runTxMode, txBytes []byte, tx sdk.Tx) (result sdk
}
}
// If BlockGasMeter() panics it will be caught by the above recover and
// return an error - in any case BlockGasMeter will consume gas past
// the limit.
result.GasWanted = gasWanted
result.GasUsed = ctx.GasMeter().GasConsumed()
}()
// If BlockGasMeter() panics it will be caught by the above recover and
// return an error - in any case BlockGasMeter will consume gas past
// the limit.
// NOTE: this must exist in a separate defer function for the
// above recovery to recover from this one
defer func() {
if mode == runTxModeDeliver {
ctx.BlockGasMeter().ConsumeGas(
ctx.GasMeter().GasConsumedToLimit(), "block gas meter")
}
result.GasWanted = gasWanted
result.GasUsed = ctx.GasMeter().GasConsumed()
}()
var msgs = tx.GetMsgs()

View File

@ -922,12 +922,13 @@ func TestMaxBlockGasLimits(t *testing.T) {
{newTxCounter(2, 7), 11, 9, false, 0},
{newTxCounter(10, 0), 10, 10, false, 0}, // hit the limit but pass
{newTxCounter(9, 0), 12, 9, true, 11}, // fail after 11
{newTxCounter(10, 0), 11, 10, true, 10},
{newTxCounter(10, 0), 15, 10, true, 10},
{newTxCounter(9, 0), 12, 9, true, 11}, // fly past the limit
}
for i, tc := range testCases {
fmt.Printf("debug i: %v\n", i)
tx := tc.tx
// reset the block gas
@ -944,7 +945,6 @@ func TestMaxBlockGasLimits(t *testing.T) {
if tc.fail && (j+1) > tc.failAfterDeliver {
require.Equal(t, res.Code, sdk.CodeOutOfGas, fmt.Sprintf("%d: %v, %v", i, tc, res))
require.Equal(t, res.Codespace, sdk.CodespaceRoot, fmt.Sprintf("%d: %v, %v", i, tc, res))
//require.True(t, ctx.BlockGasMeter().IsPastLimit()) NOTE: not necessarily true.
require.True(t, ctx.BlockGasMeter().IsOutOfGas())
} else {
// check gas used and wanted