Skip to content

fix(txpool): sort transactions by effective tip instead of max_fee_per_gas#13

Open
wpank wants to merge 2 commits into
Nunchi-trade:mainfrom
wpank:fix/txpool-eip1559-effective-tip-ordering
Open

fix(txpool): sort transactions by effective tip instead of max_fee_per_gas#13
wpank wants to merge 2 commits into
Nunchi-trade:mainfrom
wpank:fix/txpool-eip1559-effective-tip-ordering

Conversation

@wpank
Copy link
Copy Markdown

@wpank wpank commented May 30, 2026

Summary

Fixes a critical EIP-1559 ordering bug where the transaction pool sorted by max_fee_per_gas instead of the effective tip (priority fee). This caused transactions with high max_fee but low priority_fee to be incorrectly prioritized over transactions with genuinely high tips.

Per EIP-1559:

effective_gas_price = min(max_fee_per_gas, base_fee + max_priority_fee_per_gas)
effective_tip = effective_gas_price - base_fee

Impact of the bug:

  • Validators lost fee revenue (low-tip txs were included first)
  • Users paying high priority fees saw no benefit
  • Pool eviction dropped high-tip txs in favor of low-tip/high-max-fee txs
  • DEX/MEV ordering was incorrect

Changes

  • ordering.rs: Add base_fee field to OrderedTransaction. Update Ord to sort by effective_tip() instead of effective_gas_price. Update replacement logic in SenderQueue to compare tips.
  • validator.rs: Fix effective_gas_price() to compute min(max_fee, base_fee + priority_fee) for EIP-1559/4844/7702 txs. Add max_fee_per_gas() helper for balance checks. Add with_base_fee() builder to TransactionValidator. Fix min gas price check to use max_fee_per_gas (not effective price). Fix max_tx_cost() to use worst-case max_fee_per_gas.
  • pool.rs: Add base_fee tracking (set_base_fee()/base_fee()) to TransactionPool. Fix tx_to_ordered() to compute correct EIP-1559 effective gas price. Update eviction to use effective_tip().
  • rpc/txpool.rs: Update test helper for new OrderedTransaction::new() signature.

Test plan

  • All 86 existing txpool tests pass
  • New eip1559_ordering_by_effective_tip test verifies correct ordering: a tx with max_fee=50, priority_fee=50 is ordered before a tx with max_fee=100, priority_fee=1 (at base_fee=10)
  • effective_gas_price_eip1559 test updated to verify correct computation at multiple base fee levels
  • cargo check passes for kora-txpool, kora-rpc, and kora-runner
  • Run full e2e tests

Closes #7

🤖 Generated with Claude Code

will pankiewicz and others added 2 commits May 29, 2026 22:55
…r_gas

The transaction pool was using max_fee_per_gas for EIP-1559 transaction
ordering, eviction, and replacement decisions. Per the EIP-1559 spec,
ordering should use the effective tip (priority fee):

  effective_gas_price = min(max_fee_per_gas, base_fee + max_priority_fee_per_gas)
  effective_tip = effective_gas_price - base_fee

This caused transactions with high max_fee but low priority fee to be
ordered ahead of transactions with genuinely high tips, reducing
validator revenue and degrading user experience.

Changes:
- Add base_fee field to OrderedTransaction and ValidatedTransaction
- Fix effective_gas_price() to compute min(max_fee, base_fee + priority_fee)
  for EIP-1559/4844/7702 transactions instead of returning max_fee_per_gas
- Update Ord impl to sort by effective_tip() instead of effective_gas_price
- Update eviction and replacement logic to use effective_tip()
- Add set_base_fee()/base_fee() to TransactionPool for fee market updates
- Fix min gas price validation to check max_fee_per_gas (not effective price)
- Fix max_tx_cost() to use max_fee_per_gas for balance checks (worst case)
- Add test proving correct EIP-1559 ordering by effective tip

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add `const` qualifier to `OrderedTransaction::effective_tip` and
`max_fee_per_gas` as suggested by `clippy::missing_const_for_fn`.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant