Skip to content
Merged
Changes from 2 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
32 changes: 28 additions & 4 deletions x/auth/middleware/fee.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import (
"context"
"fmt"

abci "github.com/tendermint/tendermint/abci/types"

sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"

"github.com/cosmos/cosmos-sdk/types/tx"
"github.com/cosmos/cosmos-sdk/x/auth/types"
abci "github.com/tendermint/tendermint/abci/types"
)

var _ tx.Handler = mempoolFeeTxHandler{}
Expand All @@ -30,7 +30,17 @@ func MempoolFeeMiddleware(txh tx.Handler) tx.Handler {
}
}

// CheckTx implements tx.Handler.CheckTx.
// CheckTx implements tx.Handler.CheckTx. It is responsible for determining if a
// transaction's fees meet the required minimum of the processing node. Note, a
// node can have zero fees set as the minimum. If non-zero minimum fees are set
// and the transaction does not meet the minimum, the transaction is rejected.
//
// Recall, a transaction's fee is determined by ceil(minGasPrice * gasLimit).
// In addition, we set the Priority of the transaction to be ordered in the
// Tendermint mempool based naively on the total sum of all fees included.
// Applications that need more sophisticated mempool ordering should look to
// implement their own fee handling middleware instead of using
// mempoolFeeTxHandler.
func (txh mempoolFeeTxHandler) CheckTx(ctx context.Context, tx sdk.Tx, req abci.RequestCheckTx) (abci.ResponseCheckTx, error) {
sdkCtx := sdk.UnwrapSDKContext(ctx)

Expand Down Expand Up @@ -62,7 +72,10 @@ func (txh mempoolFeeTxHandler) CheckTx(ctx context.Context, tx sdk.Tx, req abci.
}
}

return txh.next.CheckTx(ctx, tx, req)
res, err := txh.next.CheckTx(ctx, tx, req)
res.Priority = GetTxPriority(feeCoins)

return res, err
}

// DeliverTx implements tx.Handler.DeliverTx.
Expand Down Expand Up @@ -192,3 +205,14 @@ func DeductFees(bankKeeper types.BankKeeper, ctx sdk.Context, acc types.AccountI

return nil
}

// GetTxPriority returns a naive tx priority based on the total sum of all fees
// provided in a transaction.
func GetTxPriority(fee sdk.Coins) int64 {
var priority int64
for _, c := range fee {
priority += c.Amount.Int64()
}

return priority
}