Skip to content

Commit

Permalink
Fix fee check for simulate mode
Browse files Browse the repository at this point in the history
  • Loading branch information
codchen committed May 2, 2023
1 parent 148625c commit bcb6e9a
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions baseapp/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func (app *BaseApp) InitChain(ctx context.Context, req *abci.RequestInitChain) (
app.StoreConsensusParams(app.deliverState.ctx, req.ConsensusParams)
app.StoreConsensusParams(app.prepareProposalState.ctx, req.ConsensusParams)
app.StoreConsensusParams(app.processProposalState.ctx, req.ConsensusParams)
app.StoreConsensusParams(app.checkState.ctx, req.ConsensusParams)
}

app.SetDeliverStateToCommit()
Expand Down
4 changes: 4 additions & 0 deletions baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -1120,3 +1120,7 @@ func (app *BaseApp) ReloadDB() error {
}
return nil
}

func (app *BaseApp) GetCheckCtx() sdk.Context {
return app.checkState.ctx
}
4 changes: 2 additions & 2 deletions x/auth/ante/fee.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

// TxFeeChecker check if the provided fee is enough and returns the effective fee and tx priority,
// the effective fee should be deducted later, and the priority should be returned in abci response.
type TxFeeChecker func(ctx sdk.Context, tx sdk.Tx) (sdk.Coins, int64, error)
type TxFeeChecker func(ctx sdk.Context, tx sdk.Tx, simulate bool) (sdk.Coins, int64, error)

// DeductFeeDecorator deducts fees from the first signer of the tx
// If the first signer does not have the funds to pay for the fees, return with InsufficientFunds error
Expand Down Expand Up @@ -79,7 +79,7 @@ func (d DeductFeeDecorator) AnteDeps(txDeps []sdkacltypes.AccessOperation, tx sd
}

func (dfd DeductFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error) {
fee, priority, err := dfd.txFeeChecker(ctx, tx)
fee, priority, err := dfd.txFeeChecker(ctx, tx, simulate)
if err != nil {
return ctx, err
}
Expand Down
4 changes: 2 additions & 2 deletions x/auth/ante/validator_tx_fee.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

// checkTxFeeWithValidatorMinGasPrices implements the default fee logic, where the minimum price per
// unit of gas is fixed and set by each validator, can the tx priority is computed from the gas price.
func CheckTxFeeWithValidatorMinGasPrices(ctx sdk.Context, tx sdk.Tx) (sdk.Coins, int64, error) {
func CheckTxFeeWithValidatorMinGasPrices(ctx sdk.Context, tx sdk.Tx, simulate bool) (sdk.Coins, int64, error) {
feeTx, ok := tx.(sdk.FeeTx)
if !ok {
return nil, 0, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "Tx must be a FeeTx")
Expand All @@ -21,7 +21,7 @@ func CheckTxFeeWithValidatorMinGasPrices(ctx sdk.Context, tx sdk.Tx) (sdk.Coins,
// Ensure that the provided fees meet a minimum threshold for the validator,
// if this is a CheckTx. This is only for local mempool purposes, and thus
// is only ran on check tx.
if ctx.IsCheckTx() {
if ctx.IsCheckTx() && !simulate {
minGasPrices := ctx.MinGasPrices()
if !minGasPrices.IsZero() {
requiredFees := make(sdk.Coins, len(minGasPrices))
Expand Down

0 comments on commit bcb6e9a

Please sign in to comment.