Skip to content

Commit 75d1151

Browse files
committed
Remove block gas meter in occ (#407)
## Describe your changes and provide context This removes the block gas meter for occ, and will eventually be rebased out with a corresponding change that will end up in main ## Testing performed to validate your change loadtest cluster testing
1 parent d08b8f0 commit 75d1151

File tree

11 files changed

+31
-355
lines changed

11 files changed

+31
-355
lines changed

baseapp/abci.go

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,6 @@ func (app *BaseApp) InitChain(ctx context.Context, req *abci.RequestInitChain) (
7171
return
7272
}
7373

74-
// add block gas meter for any genesis transactions (allow infinite gas)
75-
app.deliverState.ctx = app.deliverState.ctx.WithBlockGasMeter(sdk.NewInfiniteGasMeter())
76-
app.prepareProposalState.ctx = app.prepareProposalState.ctx.WithBlockGasMeter(sdk.NewInfiniteGasMeter())
77-
app.processProposalState.ctx = app.processProposalState.ctx.WithBlockGasMeter(sdk.NewInfiniteGasMeter())
78-
7974
resp := app.initChainer(app.deliverState.ctx, *req)
8075
app.initChainer(app.prepareProposalState.ctx, *req)
8176
app.initChainer(app.processProposalState.ctx, *req)
@@ -1034,16 +1029,9 @@ func (app *BaseApp) ProcessProposal(ctx context.Context, req *abci.RequestProces
10341029
app.setProcessProposalHeader(header)
10351030
}
10361031

1037-
// add block gas meter
1038-
var gasMeter sdk.GasMeter
1039-
if maxGas := app.getMaximumBlockGas(app.processProposalState.ctx); maxGas > 0 {
1040-
gasMeter = sdk.NewGasMeter(maxGas)
1041-
} else {
1042-
gasMeter = sdk.NewInfiniteGasMeter()
1043-
}
1044-
10451032
// NOTE: header hash is not set in NewContext, so we manually set it here
1046-
app.prepareProcessProposalState(gasMeter, req.Hash)
1033+
1034+
app.prepareProcessProposalState(req.Hash)
10471035

10481036
defer func() {
10491037
if err := recover(); err != nil {
@@ -1116,22 +1104,14 @@ func (app *BaseApp) FinalizeBlock(ctx context.Context, req *abci.RequestFinalize
11161104
app.setDeliverStateHeader(header)
11171105
}
11181106

1119-
// add block gas meter
1120-
var gasMeter sdk.GasMeter
1121-
if maxGas := app.getMaximumBlockGas(app.deliverState.ctx); maxGas > 0 {
1122-
gasMeter = sdk.NewGasMeter(maxGas)
1123-
} else {
1124-
gasMeter = sdk.NewInfiniteGasMeter()
1125-
}
1126-
11271107
// NOTE: header hash is not set in NewContext, so we manually set it here
11281108

1129-
app.prepareDeliverState(gasMeter, req.Hash)
1109+
app.prepareDeliverState(req.Hash)
11301110

11311111
// we also set block gas meter to checkState in case the application needs to
11321112
// verify gas consumption during (Re)CheckTx
11331113
if app.checkState != nil {
1134-
app.checkState.SetContext(app.checkState.ctx.WithBlockGasMeter(gasMeter).WithHeaderHash(req.Hash))
1114+
app.checkState.SetContext(app.checkState.ctx.WithHeaderHash(req.Hash))
11351115
}
11361116

11371117
if app.finalizeBlocker != nil {

baseapp/baseapp.go

Lines changed: 3 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -613,8 +613,8 @@ func (app *BaseApp) preparePrepareProposalState() {
613613
}
614614
}
615615

616-
func (app *BaseApp) prepareProcessProposalState(gasMeter sdk.GasMeter, headerHash []byte) {
617-
app.processProposalState.SetContext(app.processProposalState.Context().WithBlockGasMeter(gasMeter).
616+
func (app *BaseApp) prepareProcessProposalState(headerHash []byte) {
617+
app.processProposalState.SetContext(app.processProposalState.Context().
618618
WithHeaderHash(headerHash).
619619
WithConsensusParams(app.GetConsensusParams(app.processProposalState.Context())))
620620

@@ -623,9 +623,8 @@ func (app *BaseApp) prepareProcessProposalState(gasMeter sdk.GasMeter, headerHas
623623
}
624624
}
625625

626-
func (app *BaseApp) prepareDeliverState(gasMeter sdk.GasMeter, headerHash []byte) {
626+
func (app *BaseApp) prepareDeliverState(headerHash []byte) {
627627
app.deliverState.SetContext(app.deliverState.Context().
628-
WithBlockGasMeter(gasMeter).
629628
WithHeaderHash(headerHash).
630629
WithConsensusParams(app.GetConsensusParams(app.deliverState.Context())))
631630
}
@@ -724,27 +723,6 @@ func (app *BaseApp) StoreConsensusParams(ctx sdk.Context, cp *tmproto.ConsensusP
724723
app.paramStore.Set(ctx, ParamStoreKeyABCIParams, cp.Abci)
725724
}
726725

727-
// getMaximumBlockGas gets the maximum gas from the consensus params. It panics
728-
// if maximum block gas is less than negative one and returns zero if negative
729-
// one.
730-
func (app *BaseApp) getMaximumBlockGas(ctx sdk.Context) uint64 {
731-
cp := app.GetConsensusParams(ctx)
732-
if cp == nil || cp.Block == nil {
733-
return 0
734-
}
735-
736-
maxGas := cp.Block.MaxGas
737-
738-
// TODO::: This is a temporary fix, max gas causes non-deterministic behavior
739-
// with parallel TX
740-
switch {
741-
case maxGas < -1:
742-
panic(fmt.Sprintf("invalid maximum block gas: %d", maxGas))
743-
default:
744-
return 0
745-
}
746-
}
747-
748726
func (app *BaseApp) validateHeight(req abci.RequestBeginBlock) error {
749727
if req.Header.Height < 1 {
750728
return fmt.Errorf("invalid height: %d", req.Header.Height)
@@ -879,11 +857,6 @@ func (app *BaseApp) runTx(ctx sdk.Context, mode runTxMode, txBytes []byte) (gInf
879857

880858
ms := ctx.MultiStore()
881859

882-
// only run the tx if there is block gas remaining
883-
if mode == runTxModeDeliver && ctx.BlockGasMeter().IsOutOfGas() {
884-
return gInfo, nil, nil, -1, sdkerrors.Wrap(sdkerrors.ErrOutOfGas, "no block gas left to run tx")
885-
}
886-
887860
defer func() {
888861
if r := recover(); r != nil {
889862
acltypes.SendAllSignalsForTx(ctx.TxCompletionChannels())
@@ -896,27 +869,6 @@ func (app *BaseApp) runTx(ctx sdk.Context, mode runTxMode, txBytes []byte) (gInf
896869
gInfo = sdk.GasInfo{GasWanted: gasWanted, GasUsed: ctx.GasMeter().GasConsumed()}
897870
}()
898871

899-
blockGasConsumed := false
900-
// consumeBlockGas makes sure block gas is consumed at most once. It must happen after
901-
// tx processing, and must be execute even if tx processing fails. Hence we use trick with `defer`
902-
consumeBlockGas := func() {
903-
if !blockGasConsumed {
904-
blockGasConsumed = true
905-
ctx.BlockGasMeter().ConsumeGas(
906-
ctx.GasMeter().GasConsumedToLimit(), "block gas meter",
907-
)
908-
}
909-
}
910-
911-
// If BlockGasMeter() panics it will be caught by the above recover and will
912-
// return an error - in any case BlockGasMeter will consume gas past the limit.
913-
//
914-
// NOTE: This must exist in a separate defer function for the above recovery
915-
// to recover from this one.
916-
if mode == runTxModeDeliver {
917-
defer consumeBlockGas()
918-
}
919-
920872
tx, err := app.txDecoder(txBytes)
921873
if err != nil {
922874
return sdk.GasInfo{}, nil, nil, 0, err
@@ -1004,9 +956,6 @@ func (app *BaseApp) runTx(ctx sdk.Context, mode runTxMode, txBytes []byte) (gInf
1004956
result, err = app.runMsgs(runMsgCtx, msgs, mode)
1005957

1006958
if err == nil && mode == runTxModeDeliver {
1007-
// When block gas exceeds, it'll panic and won't commit the cached store.
1008-
consumeBlockGas()
1009-
1010959
msCache.Write()
1011960
}
1012961
// we do this since we will only be looking at result in DeliverTx

baseapp/block_gas_test.go

Lines changed: 0 additions & 202 deletions
This file was deleted.

baseapp/deliver_tx_batch_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ func TestDeliverTxBatch(t *testing.T) {
111111
for blockN := 0; blockN < nBlocks; blockN++ {
112112
header := tmproto.Header{Height: int64(blockN) + 1}
113113
app.setDeliverState(header)
114-
app.deliverState.ctx = app.deliverState.ctx.WithBlockGasMeter(sdk.NewInfiniteGasMeter())
115114
app.BeginBlock(app.deliverState.ctx, abci.RequestBeginBlock{Header: header})
116115

117116
var requests []*sdk.DeliverTxEntry

0 commit comments

Comments
 (0)