Skip to content

Align CosmosPool priority logic with the antehandler’s priority setup #510

@canu0205

Description

@canu0205

Summary

The current design of the experimental EVMMempool does not consistently respect the sdk.Context priority initialized during the antehandler.

  • For EVM txs, this only leads to a scaling discrepancy, since Cosmos EVM already employs the same priority calculation mechanism.
  • For Cosmos txs, however, it introduces inconsistencies in priority handling.

This issue proposes aligning CosmosPool priority logic with the antehandler’s priority setup and ensuring consistent use of same priority calculation across the mempool.

As-Is

  1. CosmosPool Priority Setup
    • In NewExperimentalEVMMempool, when configuring cosmosPool, it defaults TxPriority to use gas price.
    • This ignores the sdk.Context priority set in the antehandler (unlike priority_nonce.go’s default).
    • If the app uses DynamicTxFeeChecker, the correct priority should be the priority tip, not the raw gas price.
	// Create Cosmos Mempool from configuration
	cosmosPoolConfig := config.CosmosPoolConfig
	if cosmosPoolConfig == nil {
		// Default configuration
		defaultConfig := sdkmempool.PriorityNonceMempoolConfig[math.Int]{}
		defaultConfig.TxPriority = sdkmempool.TxPriority[math.Int]{
			GetTxPriority: func(goCtx context.Context, tx sdk.Tx) math.Int {
				cosmosTxFee, ok := tx.(sdk.FeeTx)
				if !ok {
					return math.ZeroInt()
				}
				found, coin := cosmosTxFee.GetFee().Find(bondDenom)
				if !found {
					return math.ZeroInt()
				}

				gasPrice := coin.Amount.Quo(math.NewIntFromUint64(cosmosTxFee.GetGas()))

				return gasPrice
			},
			Compare: func(a, b math.Int) int {
				return a.BigInt().Cmp(b.BigInt())
			},
			MinValue: math.ZeroInt(),
		}
		cosmosPoolConfig = &defaultConfig
	}
  1. Babylon Genesis Context
  2. shouldUseEVM Function
    • Currently retains cosmosFee by calling extractCosmosEffectiveTip.
    • This computes priority only as gas_price - base_fee, missing the min(gas_price - base_fee, priority_tip) rule used by DeductFeeDecorator.
    • This creates discrepancies between cosmosPool config priority (using static fee checker) and shouldUseEVM (using incomplete dynamic fee checker logic).

To-Be

  • Use sdk.Context priority for Cosmos txs in the EVMMempool, so antehandler logic is preserved.
func NewDefaultTxPriority() TxPriority[int64] {
	return TxPriority[int64]{
		GetTxPriority: func(goCtx context.Context, _ sdk.Tx) int64 {
			return sdk.UnwrapSDKContext(goCtx).Priority()
		},
		Compare: func(a, b int64) int {
			return skiplist.Int64.Compare(a, b)
		},
		MinValue: math.MinInt64,
	}
}
  • Adopt the same priority calculation logic as the TxFeeChecker of the DeductFeeDecorator for cosmos txs in the EVMMempool, ensuring consistency with how fees and tips are applied during execution.
    • This can be done by using sdk.Context priority for cosmos txs in the EVMMempool.
  • Unify CosmosPool priority setup, making it consistent across:
    1. cosmosPool config
    2. shouldUseEVM decision logic

Current Limitations

  • Extra setup is currently required for cosmosPool when configuring TxFeeChecker.
  • extractCosmosEffectiveTip only partially implements dynamic fee calculation.
  • Inconsistencies exist between static and dynamic fee checker defaults across the mempool.
    • cosmosPool default config uses static fee checker for calculating priority, which is same with gas price
    • shouldUseEVM decision logic uses incomplete dynamic fee checker for calculating priority, which calculates based on priority tip

Suggestions

  • Update cosmosPool to respect sdk.Context priority values.
  • Replace extractCosmosEffectiveTip logic with the same priority calculation used in DeductFeeDecorator.
  • Ensure cosmosPool config and shouldUseEVM share a single consistent priority algorithm.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions