Skip to content

Commit

Permalink
fix: updating logic for how we deal with infiniteGasMeter (#467)
Browse files Browse the repository at this point in the history
* handling behavior change in infinitegasmeter.Limit()

* reflect no mo
  • Loading branch information
spoo-bar authored Oct 10, 2023
1 parent 12496d3 commit 39faa9a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
9 changes: 6 additions & 3 deletions x/rewards/keeper/min_cons_fee.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package keeper

import (
"math"

sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/archway-network/archway/pkg"
Expand All @@ -17,16 +19,17 @@ 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
}

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
Expand Down
9 changes: 8 additions & 1 deletion x/rewards/keeper/tracking.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package keeper

import (
"math"

sdk "github.com/cosmos/cosmos-sdk/types"
)

Expand All @@ -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,
)
}

0 comments on commit 39faa9a

Please sign in to comment.