Skip to content

Commit

Permalink
feat: improve the fee check error log (cosmos#2480)
Browse files Browse the repository at this point in the history
* feat: improve the fee check error log

* docs: remove invalid links

* Update x/globalfee/ante/fee.go

Co-authored-by: lg <8335464+glnro@users.noreply.github.com>

---------

Co-authored-by: lg <8335464+glnro@users.noreply.github.com>
  • Loading branch information
yaruwangway and glnro authored May 11, 2023
1 parent 11273e8 commit 2fd6f6d
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions x/globalfee/ante/fee.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ante

import (
"errors"
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
Expand Down Expand Up @@ -69,7 +70,7 @@ func (mfd FeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, ne
}

// reject the transaction early if the feeCoins have more denoms than the fee requirement
// feeRequired cannot be be empty
// feeRequired cannot be empty
if feeTx.GetFee().Len() > feeRequired.Len() {
return ctx, sdkerrors.Wrapf(sdkerrors.ErrInvalidCoins, "fee is not a subset of required fees; got %s, required: %s", feeTx.GetFee().String(), feeRequired.String())
}
Expand Down Expand Up @@ -107,7 +108,8 @@ func (mfd FeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, ne
// i.e., totalGas <= MaxTotalBypassMinFeeMsgGasUsage
// Otherwise, minimum fees and global fees are checked to prevent spam.
doesNotExceedMaxGasUsage := gas <= mfd.MaxTotalBypassMinFeeMsgGasUsage
allowedToBypassMinFee := mfd.ContainsOnlyBypassMinFeeMsgs(msgs) && doesNotExceedMaxGasUsage
allBypassMsgs := mfd.ContainsOnlyBypassMinFeeMsgs(msgs)
allowedToBypassMinFee := allBypassMsgs && doesNotExceedMaxGasUsage
if allowedToBypassMinFee {
return next(ctx, tx, simulate)
}
Expand Down Expand Up @@ -139,7 +141,12 @@ func (mfd FeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, ne
//
// check if the feeCoins's feeCoinsNonZeroDenom part has coins' amount higher/equal to nonZeroCoinFeesReq
if !feeCoinsNonZeroDenom.IsAnyGTE(nonZeroCoinFeesReq) {
return ctx, sdkerrors.Wrapf(sdkerrors.ErrInsufficientFee, "insufficient fees; got: %s required: %s", feeCoins.String(), feeRequired.String())
errMsg := fmt.Sprintf("Insufficient fees; got: %s required: %s", feeCoins.String(), feeRequired.String())
if allBypassMsgs && !doesNotExceedMaxGasUsage {
errMsg = fmt.Sprintf("Insufficient fees; bypass-min-fee-msg-types with gas consumption %v exceeds the maximum allowed gas value of %v.", gas, mfd.MaxTotalBypassMinFeeMsgGasUsage)
}

return ctx, sdkerrors.Wrap(sdkerrors.ErrInsufficientFee, errMsg)
}

return next(ctx, tx, simulate)
Expand Down

0 comments on commit 2fd6f6d

Please sign in to comment.