only use block gas for deliver

This commit is contained in:
rigelrozanski 2018-11-14 00:57:27 -05:00
parent 7e6fcc0161
commit 68e3b9a559
1 changed files with 22 additions and 11 deletions

View File

@ -264,6 +264,15 @@ func (app *BaseApp) InitChain(req abci.RequestInitChain) (res abci.ResponseInitC
} }
res = app.initChainer(app.deliverState.ctx, req) res = app.initChainer(app.deliverState.ctx, req)
// add block gas meter
if app.maximumBlockGas > 0 {
app.deliverState.ctx = app.deliverState.ctx.
WithBlockGasMeter(sdk.NewGasMeter(app.maximumBlockGas))
} else {
app.deliverState.ctx = app.deliverState.ctx.
WithBlockGasMeter(sdk.NewInfiniteGasMeter())
}
// NOTE: we don't commit, but BeginBlock for block 1 // NOTE: we don't commit, but BeginBlock for block 1
// starts from this deliverState // starts from this deliverState
return return
@ -434,7 +443,6 @@ func (app *BaseApp) BeginBlock(req abci.RequestBeginBlock) (res abci.ResponseBeg
app.deliverState.ctx = app.deliverState.ctx. app.deliverState.ctx = app.deliverState.ctx.
WithBlockHeader(req.Header). WithBlockHeader(req.Header).
WithBlockHeight(req.Header.Height) WithBlockHeight(req.Header.Height)
}
// add block gas meter // add block gas meter
if app.maximumBlockGas > 0 { if app.maximumBlockGas > 0 {
@ -444,6 +452,7 @@ func (app *BaseApp) BeginBlock(req abci.RequestBeginBlock) (res abci.ResponseBeg
app.deliverState.ctx = app.deliverState.ctx. app.deliverState.ctx = app.deliverState.ctx.
WithBlockGasMeter(sdk.NewInfiniteGasMeter()) WithBlockGasMeter(sdk.NewInfiniteGasMeter())
} }
}
if app.beginBlocker != nil { if app.beginBlocker != nil {
res = app.beginBlocker(app.deliverState.ctx, req) res = app.beginBlocker(app.deliverState.ctx, req)
@ -619,7 +628,7 @@ func (app *BaseApp) runTx(mode runTxMode, txBytes []byte, tx sdk.Tx) (result sdk
ctx = app.initializeContext(ctx, mode) ctx = app.initializeContext(ctx, mode)
// only run the tx if there is block gas remaining // only run the tx if there is block gas remaining
if ctx.BlockGasMeter().PastLimit() { if mode == runTxModeDeliver && ctx.BlockGasMeter().PastLimit() {
result = sdk.ErrOutOfGas("no block gas left to run tx").Result() result = sdk.ErrOutOfGas("no block gas left to run tx").Result()
return return
} }
@ -678,8 +687,10 @@ func (app *BaseApp) runTx(mode runTxMode, txBytes []byte, tx sdk.Tx) (result sdk
result.GasWanted = gasWanted result.GasWanted = gasWanted
// consume block gas // consume block gas
if mode == runTxModeDeliver {
ctx.BlockGasMeter().ConsumeGas( ctx.BlockGasMeter().ConsumeGas(
ctx.GasMeter().GasConsumed(), "block gas meter") ctx.GasMeter().GasConsumed(), "block gas meter")
}
// only update state if all messages pass // only update state if all messages pass
if result.IsOK() { if result.IsOK() {