Skip to content

Commit

Permalink
fix: allow for no bank balances in all simulations (skip-mev#137)
Browse files Browse the repository at this point in the history
* init

* recreate and fix bug

* helper

* ante tests

* ok

* fix via gas consume call during simulation

* test

* revert

* lint fix

* retract more

* replace linter

* set lint to what we use
  • Loading branch information
Alex Johnson authored Aug 26, 2024
1 parent 1aac4a6 commit f1f216e
Show file tree
Hide file tree
Showing 11 changed files with 1,916 additions and 71 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
uses: golangci/golangci-lint-action@v3
with:
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
version: latest
version: v1.59.1
only-new-issues: true
lint-markdown:
name: Lint markdown
Expand Down
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ linters:
disable-all: true
enable:
- dogsled
- exportloopref
- copyloopvar
- goconst
- gocritic
- gofumpt
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -352,5 +352,5 @@ replace (
github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7
)

// simulation and fee UX
retract [v1.0.0, v1.0.2]
// simulation and fee UX, blackberry fix
retract [v1.0.0, v1.0.4]
7 changes: 2 additions & 5 deletions x/feemarket/ante/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"cosmossdk.io/core/address"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"

feemarkettypes "github.com/skip-mev/feemarket/x/feemarket/types"
)
Expand Down Expand Up @@ -35,11 +36,7 @@ type FeeGrantKeeper interface {
//
//go:generate mockery --name BankKeeper --filename mock_bank_keeper.go
type BankKeeper interface {
IsSendEnabledCoins(ctx context.Context, coins ...sdk.Coin) error
SendCoins(ctx context.Context, from, to sdk.AccAddress, amt sdk.Coins) error
SendCoinsFromAccountToModule(ctx context.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error
SendCoinsFromModuleToModule(ctx context.Context, senderModule, recipientModule string, amt sdk.Coins) error
SendCoinsFromModuleToAccount(ctx context.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error
bankkeeper.Keeper
}

// FeeMarketKeeper defines the expected feemarket keeper.
Expand Down
24 changes: 12 additions & 12 deletions x/feemarket/ante/fee.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,18 +109,17 @@ func (dfd feeMarketCheckDecorator) anteHandle(ctx sdk.Context, tx sdk.Tx, simula
return ctx, errorsmod.Wrapf(feemarkettypes.ErrTooManyFeeCoins, "got length %d", len(feeCoins))
}

var feeCoin sdk.Coin
if simulate && len(feeCoins) == 0 {
// if simulating and user did not provider a fee - create a dummy value for them
feeCoin = sdk.NewCoin(params.FeeDenom, sdkmath.OneInt())
} else {
feeCoin = feeCoins[0]
// if simulating - create a dummy zero value for the user
payCoin := sdk.NewCoin(params.FeeDenom, sdkmath.ZeroInt())
if !simulate {
payCoin = feeCoins[0]
}

feeGas := int64(feeTx.GetGas())

minGasPrice, err := dfd.feemarketKeeper.GetMinGasPrice(ctx, feeCoin.GetDenom())
minGasPrice, err := dfd.feemarketKeeper.GetMinGasPrice(ctx, payCoin.GetDenom())
if err != nil {
return ctx, errorsmod.Wrapf(err, "unable to get min gas price for denom %s", feeCoin.GetDenom())
return ctx, errorsmod.Wrapf(err, "unable to get min gas price for denom %s", payCoin.GetDenom())
}

ctx.Logger().Info("fee deduct ante handle",
Expand All @@ -132,19 +131,19 @@ func (dfd feeMarketCheckDecorator) anteHandle(ctx sdk.Context, tx sdk.Tx, simula
ctx = ctx.WithMinGasPrices(sdk.NewDecCoins(minGasPrice))

if !simulate {
_, _, err := CheckTxFee(ctx, minGasPrice, feeCoin, feeGas, true)
_, _, err := CheckTxFee(ctx, minGasPrice, payCoin, feeGas, true)
if err != nil {
return ctx, errorsmod.Wrapf(err, "error checking fee")
}
}

// escrow the entire amount that the account provided as fee (feeCoin)
err = dfd.EscrowFunds(ctx, tx, feeCoin)
err = dfd.EscrowFunds(ctx, tx, payCoin)
if err != nil {
return ctx, errorsmod.Wrapf(err, "error escrowing funds")
}

priorityFee, err := dfd.resolveTxPriorityCoins(ctx, feeCoin, params.FeeDenom)
priorityFee, err := dfd.resolveTxPriorityCoins(ctx, payCoin, params.FeeDenom)
if err != nil {
return ctx, errorsmod.Wrapf(err, "error resolving fee priority")
}
Expand Down Expand Up @@ -194,7 +193,8 @@ func (dfd feeMarketCheckDecorator) EscrowFunds(ctx sdk.Context, sdkTx sdk.Tx, pr
return sdkerrors.ErrInvalidRequest.Wrap("fee grants are not enabled")
} else if !bytes.Equal(feeGranter, feePayer) {
if !providedFee.IsNil() {
err := dfd.feegrantKeeper.UseGrantedFees(ctx, feeGranter, feePayer, sdk.NewCoins(providedFee), sdkTx.GetMsgs())
err := dfd.feegrantKeeper.UseGrantedFees(ctx, feeGranter, feePayer, sdk.NewCoins(providedFee),
sdkTx.GetMsgs())
if err != nil {
return errorsmod.Wrapf(err, "%s does not allow to pay fees for %s", feeGranter, feePayer)
}
Expand Down
Loading

0 comments on commit f1f216e

Please sign in to comment.