Skip to content

Commit

Permalink
fix: allow for no bank balances in all simulations (#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

(cherry picked from commit f1f216e)

# Conflicts:
#	x/feemarket/ante/expected_keepers.go
#	x/feemarket/ante/mocks/mock_bank_keeper.go
#	x/feemarket/ante/suite/suite.go
#	x/feemarket/post/fee_test.go
  • Loading branch information
Alex Johnson authored and mergify[bot] committed Aug 26, 2024
1 parent ad21c7e commit d58f023
Show file tree
Hide file tree
Showing 11 changed files with 1,969 additions and 46 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 @@ -344,5 +344,5 @@ replace (
golang.org/x/exp => golang.org/x/exp v0.0.0-20230224173230-c95f2b4c22f2
)

// simulation and fee UX
retract [v1.0.0, v1.0.2]
// simulation and fee UX, blackberry fix
retract [v1.0.0, v1.0.4]
5 changes: 5 additions & 0 deletions x/feemarket/ante/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ante
import (
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 @@ -31,11 +32,15 @@ type FeeGrantKeeper interface {
//
//go:generate mockery --name BankKeeper --filename mock_bank_keeper.go
type BankKeeper interface {
<<<<<<< HEAD

Check failure on line 35 in x/feemarket/ante/expected_keepers.go

View workflow job for this annotation

GitHub Actions / golangci-lint

syntax error: unexpected <<, expected ~ term or type

Check failure on line 35 in x/feemarket/ante/expected_keepers.go

View workflow job for this annotation

GitHub Actions / golangci-lint

expected '}', found '<<' (typecheck)

Check failure on line 35 in x/feemarket/ante/expected_keepers.go

View workflow job for this annotation

GitHub Actions / golangci-lint

syntax error: unexpected <<, expected ~ term or type

Check failure on line 35 in x/feemarket/ante/expected_keepers.go

View workflow job for this annotation

GitHub Actions / test-integration

syntax error: unexpected <<, expected ~ term or type
IsSendEnabledCoins(ctx sdk.Context, coins ...sdk.Coin) error

Check failure on line 36 in x/feemarket/ante/expected_keepers.go

View workflow job for this annotation

GitHub Actions / golangci-lint

syntax error: unexpected ) after top level declaration

Check failure on line 36 in x/feemarket/ante/expected_keepers.go

View workflow job for this annotation

GitHub Actions / golangci-lint

syntax error: unexpected ) after top level declaration

Check failure on line 36 in x/feemarket/ante/expected_keepers.go

View workflow job for this annotation

GitHub Actions / test-integration

syntax error: unexpected ) after top level declaration
SendCoins(ctx sdk.Context, from, to sdk.AccAddress, amt sdk.Coins) error
SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error
SendCoinsFromModuleToModule(ctx sdk.Context, senderModule, recipientModule string, amt sdk.Coins) error
SendCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error
=======
bankkeeper.Keeper
>>>>>>> f1f216e (fix: allow for no bank balances in all simulations (#137))

Check failure on line 43 in x/feemarket/ante/expected_keepers.go

View workflow job for this annotation

GitHub Actions / golangci-lint

invalid character U+0023 '#' (typecheck)

Check failure on line 43 in x/feemarket/ante/expected_keepers.go

View workflow job for this annotation

GitHub Actions / golangci-lint

expected declaration, found 'for' (typecheck)

Check failure on line 43 in x/feemarket/ante/expected_keepers.go

View workflow job for this annotation

GitHub Actions / golangci-lint

invalid character U+0023 '#') (typecheck)

Check failure on line 43 in x/feemarket/ante/expected_keepers.go

View workflow job for this annotation

GitHub Actions / test-integration

invalid character U+0023 '#'
}

// 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 @@ -110,18 +110,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 @@ -133,19 +132,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 @@ -195,7 +194,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 d58f023

Please sign in to comment.