Skip to content

Commit

Permalink
Update tax gas meter after each tx
Browse files Browse the repository at this point in the history
  • Loading branch information
phamminh0811 committed Jul 30, 2024
1 parent e1d17ec commit 6221992
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,7 @@ func (app *BaseApp) runTx(mode runTxMode, txBytes []byte) (gInfo sdk.GasInfo, re
var gasWanted uint64

ctx := app.getContextForTx(mode, txBytes)
ctx = ctx.WithNewTaxGasMeter()
ms := ctx.MultiStore()

// only run the tx if there is block gas remaining
Expand Down Expand Up @@ -756,6 +757,7 @@ func (app *BaseApp) runTx(mode runTxMode, txBytes []byte) (gInfo sdk.GasInfo, re
// We clear this to correctly order events without duplicates.
// Note that the state is still preserved.
postCtx := runMsgCtx.WithEventManager(sdk.NewEventManager())
fmt.Println("postCtx taxgas meter: ", postCtx.TaxGasMeter().GasConsumed())

newCtx, err := app.postHandler(postCtx, tx, mode == runTxModeSimulate, err == nil)
if err != nil {
Expand Down
6 changes: 6 additions & 0 deletions types/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,12 @@ func (c Context) WithMinGasPrices(gasPrices DecCoins) Context {
return c
}

// WithTaxGasMeter returns a Context with an updated tax gas meter value
func (c Context) WithNewTaxGasMeter() Context {
c.taxGasMeter = storetypes.NewTaxGasMeter()
return c
}

// WithConsensusParams returns a Context with an updated consensus params
func (c Context) WithConsensusParams(params *tmproto.ConsensusParams) Context {
c.consParams = params
Expand Down

0 comments on commit 6221992

Please sign in to comment.