From 39faa9a83d75c7c7acd99c9360aeb461d0786edb Mon Sep 17 00:00:00 2001 From: Spoorthi <9302666+spoo-bar@users.noreply.github.com> Date: Tue, 10 Oct 2023 15:37:24 +0530 Subject: [PATCH] fix: updating logic for how we deal with infiniteGasMeter (#467) * handling behavior change in infinitegasmeter.Limit() * reflect no mo --- x/rewards/keeper/min_cons_fee.go | 9 ++++++--- x/rewards/keeper/tracking.go | 9 ++++++++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/x/rewards/keeper/min_cons_fee.go b/x/rewards/keeper/min_cons_fee.go index c2962afa..128c707a 100644 --- a/x/rewards/keeper/min_cons_fee.go +++ b/x/rewards/keeper/min_cons_fee.go @@ -1,6 +1,8 @@ package keeper import ( + "math" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/archway-network/archway/pkg" @@ -17,8 +19,8 @@ func (k Keeper) UpdateMinConsensusFee(ctx sdk.Context, inflationRewards sdk.Coin inflationRewardsAmt := sdk.NewDecFromInt(inflationRewards.Amount) - blockGasLimit := pkg.NewDecFromUint64(ctx.BlockGasMeter().Limit()) - if blockGasLimit.IsZero() { + blockGasLimit := ctx.BlockGasMeter().Limit() + if blockGasLimit == math.MaxUint64 { // Because thisss https://github.com/cosmos/cosmos-sdk/pull/9651 k.Logger(ctx).Info("Minimum consensus fee update skipped: block gas limit is not set") return } @@ -26,7 +28,8 @@ func (k Keeper) UpdateMinConsensusFee(ctx sdk.Context, inflationRewards sdk.Coin txFeeRebateRatio := k.TxFeeRebateRatio(ctx) // Calculate - feeAmt := calculateMinConsensusFeeAmt(inflationRewardsAmt, blockGasLimit, txFeeRebateRatio) + blockGasLimitAsDec := pkg.NewDecFromUint64(blockGasLimit) + feeAmt := calculateMinConsensusFeeAmt(inflationRewardsAmt, blockGasLimitAsDec, txFeeRebateRatio) if feeAmt.IsZero() || feeAmt.IsNegative() { k.Logger(ctx).Info("Minimum consensus fee update skipped: calculated amount is zero or bellow zero") return diff --git a/x/rewards/keeper/tracking.go b/x/rewards/keeper/tracking.go index 01b6741b..1f9f2849 100644 --- a/x/rewards/keeper/tracking.go +++ b/x/rewards/keeper/tracking.go @@ -1,6 +1,8 @@ package keeper import ( + "math" + sdk "github.com/cosmos/cosmos-sdk/types" ) @@ -18,9 +20,14 @@ func (k Keeper) TrackFeeRebatesRewards(ctx sdk.Context, rewards sdk.Coins) { // TrackInflationRewards creates a new inflation reward record for the current block. func (k Keeper) TrackInflationRewards(ctx sdk.Context, rewards sdk.Coin) { + blockGasLimit := ctx.BlockGasMeter().Limit() + if ctx.BlockGasMeter().Limit() == math.MaxUint64 { // Because thisss https://github.com/cosmos/cosmos-sdk/pull/9651 + blockGasLimit = 0 + } + k.state.BlockRewardsState(ctx).CreateBlockRewards( ctx.BlockHeight(), rewards, - ctx.BlockGasMeter().Limit(), + blockGasLimit, ) }