Skip to content

Commit

Permalink
handling behavior change in infinitegasmeter.Limit()
Browse files Browse the repository at this point in the history
  • Loading branch information
spoo-bar committed Oct 9, 2023
1 parent 312e18d commit 0b21325
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
15 changes: 11 additions & 4 deletions x/rewards/keeper/min_cons_fee.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package keeper

import (
"reflect"
"strings"

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

"github.com/archway-network/archway/pkg"
Expand All @@ -14,19 +17,23 @@ func (k Keeper) UpdateMinConsensusFee(ctx sdk.Context, inflationRewards sdk.Coin
k.Logger(ctx).Info("Minimum consensus fee update skipped: inflation rewards are zero")
return
}

inflationRewardsAmt := sdk.NewDecFromInt(inflationRewards.Amount)

blockGasLimit := pkg.NewDecFromUint64(ctx.BlockGasMeter().Limit())
if blockGasLimit.IsZero() {
blockGasLimit := ctx.BlockGasMeter().Limit()
if strings.Contains(reflect.TypeOf(ctx.BlockGasMeter()).String(), "infiniteGasMeter") { // Because thisss https://github.com/cosmos/cosmos-sdk/pull/9651
blockGasLimit = 0
}

blockGasLimitAsDec := pkg.NewDecFromUint64(blockGasLimit)
if blockGasLimitAsDec.IsZero() {
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)
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
10 changes: 9 additions & 1 deletion x/rewards/keeper/tracking.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package keeper

import (
"reflect"
"strings"

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

Expand All @@ -18,9 +21,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 strings.Contains(reflect.TypeOf(ctx.BlockGasMeter()).String(), "infiniteGasMeter") { // 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 0b21325

Please sign in to comment.