Skip to content

Commit

Permalink
adjust
Browse files Browse the repository at this point in the history
  • Loading branch information
aljo242 committed Aug 23, 2024
1 parent 5811698 commit 8f9f034
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 56 deletions.
8 changes: 8 additions & 0 deletions x/feemarket/ante/fee.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

errorsmod "cosmossdk.io/errors"
sdkmath "cosmossdk.io/math"
storetypes "cosmossdk.io/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"

Expand Down Expand Up @@ -209,6 +210,13 @@ func (dfd feeMarketCheckDecorator) EscrowFunds(ctx sdk.Context, sdkTx sdk.Tx, pr
return sdkerrors.ErrUnknownAddress.Wrapf("fee payer address: %s does not exist", deductFeesFrom)
}

// fork gas and don't count escrow cost
cacheGas := ctx.GasMeter().GasConsumed()
defer func() {
ctx = ctx.WithGasMeter(storetypes.NewGasMeter(ctx.GasMeter().Limit()))
ctx.GasMeter().ConsumeGas(cacheGas, "escrow gas reset")
}()

return escrow(dfd.bankKeeper, ctx, deductFeesFromAcc, sdk.NewCoins(providedFee))
}

Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

20 changes: 9 additions & 11 deletions x/feemarket/post/fee.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ package post
import (
"fmt"

"cosmossdk.io/math"

errorsmod "cosmossdk.io/errors"

"cosmossdk.io/math"
storetypes "cosmossdk.io/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
Expand All @@ -15,9 +14,6 @@ import (
feemarkettypes "github.com/skip-mev/feemarket/x/feemarket/types"
)

// BankSendGasConsumption is the gas consumption of the bank sends that occur during feemarket handler execution.
const BankSendGasConsumption = 12490

// FeeMarketDeductDecorator deducts fees from the fee payer based off of the current state of the feemarket.
// The fee payer is the fee granter (if specified) or first signer of the tx.
// If the fee payer does not have the funds to pay for the fees, return an InsufficientFunds error.
Expand Down Expand Up @@ -140,11 +136,6 @@ func (dfd FeeMarketDeductDecorator) PostHandle(ctx sdk.Context, tx sdk.Tx, simul
return ctx, errorsmod.Wrapf(err, "unable to set fee market state")
}

if simulate {
// consume the gas that would be consumed during normal execution
ctx.GasMeter().ConsumeGas(BankSendGasConsumption, "simulation send gas consumption")
}

return next(ctx, tx, simulate, success)
}

Expand All @@ -158,6 +149,13 @@ func (dfd FeeMarketDeductDecorator) PayOutFeeAndTip(ctx sdk.Context, fee, tip sd

var events sdk.Events

// fork gas and don't count payout cost
cacheGas := ctx.GasMeter().GasConsumed()
defer func() {
ctx = ctx.WithGasMeter(storetypes.NewGasMeter(ctx.GasMeter().Limit()))
ctx.GasMeter().ConsumeGas(cacheGas, "gas deduction reset")
}()

// deduct the fees and tip
if !fee.IsNil() {
err := DeductCoins(dfd.bankKeeper, ctx, sdk.NewCoins(fee), params.DistributeFees)
Expand Down
4 changes: 2 additions & 2 deletions x/feemarket/post/fee_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func TestPostHandleMock(t *testing.T) {
baseDenom = "stake"
resolvableDenom = "atom"
expectedConsumedGas = 10631
expectedConsumedSimGas = expectedConsumedGas + post.BankSendGasConsumption
expectedConsumedSimGas = expectedConsumedGas
gasLimit = expectedConsumedSimGas
)

Expand Down Expand Up @@ -539,7 +539,7 @@ func TestPostHandle(t *testing.T) {
const (
baseDenom = "stake"
resolvableDenom = "atom"
expectedConsumedGas = 36650
expectedConsumedGas = 24160

expectedConsumedGasResolve = 36524 // slight difference due to denom resolver

Expand Down

0 comments on commit 8f9f034

Please sign in to comment.