Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow for no bank balances in all simulations #137

Merged
merged 12 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading