Skip to content

Commit

Permalink
fix BlockGasRecovery
Browse files Browse the repository at this point in the history
  • Loading branch information
rigelrozanski committed Nov 22, 2018
1 parent 2d3e1af commit 56fa7dc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
16 changes: 10 additions & 6 deletions baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions baseapp/baseapp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 56fa7dc

Please sign in to comment.