From 5cc37e5efd5e4151273b7028c7252e90802ac10a Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Mon, 19 Feb 2024 16:06:11 +0100 Subject: [PATCH] Minor state compatible speedups to txfees (#7535) (#7548) (cherry picked from commit d563553fbce052e70a5e0582142fecb92f58f6cb) Co-authored-by: Dev Ojha --- x/txfees/keeper/feedecorator.go | 4 +++- x/txfees/keeper/feetokens.go | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/x/txfees/keeper/feedecorator.go b/x/txfees/keeper/feedecorator.go index 4a48b39d87c..2df6c547358 100644 --- a/x/txfees/keeper/feedecorator.go +++ b/x/txfees/keeper/feedecorator.go @@ -142,8 +142,10 @@ func (k Keeper) IsSufficientFee(ctx sdk.Context, minBaseGasPrice osmomath.Dec, g // Determine the required fees by multiplying the required minimum gas // price by the gas limit, where fee = ceil(minGasPrice * gasLimit). + // note we mutate this one line below, to avoid extra heap allocations. glDec := osmomath.NewDec(int64(gasRequested)) - requiredBaseFee := sdk.NewCoin(baseDenom, minBaseGasPrice.Mul(glDec).Ceil().RoundInt()) + baseFeeAmt := glDec.MulMut(minBaseGasPrice).Ceil().RoundInt() + requiredBaseFee := sdk.Coin{Denom: baseDenom, Amount: baseFeeAmt} convertedFee, err := k.ConvertToBaseToken(ctx, feeCoin) if err != nil { diff --git a/x/txfees/keeper/feetokens.go b/x/txfees/keeper/feetokens.go index d23d827ca94..d7533641f78 100644 --- a/x/txfees/keeper/feetokens.go +++ b/x/txfees/keeper/feetokens.go @@ -35,7 +35,7 @@ func (k Keeper) ConvertToBaseToken(ctx sdk.Context, inputFee sdk.Coin) (sdk.Coin // Note: spotPrice truncation is done here for maintaining state-compatibility with v19.x // It should be changed to support full spot price precision before // https://github.com/osmosis-labs/osmosis/issues/6064 is complete - return sdk.NewCoin(baseDenom, spotPrice.Dec().MulInt(inputFee.Amount).RoundInt()), nil + return sdk.NewCoin(baseDenom, spotPrice.Dec().MulIntMut(inputFee.Amount).RoundInt()), nil } // CalcFeeSpotPrice converts the provided tx fees into their equivalent value in the base denomination.