fix(txpool): sort transactions by effective tip instead of max_fee_per_gas#13
Open
wpank wants to merge 2 commits into
Open
fix(txpool): sort transactions by effective tip instead of max_fee_per_gas#13wpank wants to merge 2 commits into
wpank wants to merge 2 commits into
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes a critical EIP-1559 ordering bug where the transaction pool sorted by
max_fee_per_gasinstead of the effective tip (priority fee). This caused transactions with highmax_feebut lowpriority_feeto be incorrectly prioritized over transactions with genuinely high tips.Per EIP-1559:
Impact of the bug:
Changes
ordering.rs: Addbase_feefield toOrderedTransaction. UpdateOrdto sort byeffective_tip()instead ofeffective_gas_price. Update replacement logic inSenderQueueto compare tips.validator.rs: Fixeffective_gas_price()to computemin(max_fee, base_fee + priority_fee)for EIP-1559/4844/7702 txs. Addmax_fee_per_gas()helper for balance checks. Addwith_base_fee()builder toTransactionValidator. Fix min gas price check to usemax_fee_per_gas(not effective price). Fixmax_tx_cost()to use worst-casemax_fee_per_gas.pool.rs: Addbase_feetracking (set_base_fee()/base_fee()) toTransactionPool. Fixtx_to_ordered()to compute correct EIP-1559 effective gas price. Update eviction to useeffective_tip().rpc/txpool.rs: Update test helper for newOrderedTransaction::new()signature.Test plan
eip1559_ordering_by_effective_tiptest verifies correct ordering: a tx withmax_fee=50, priority_fee=50is ordered before a tx withmax_fee=100, priority_fee=1(atbase_fee=10)effective_gas_price_eip1559test updated to verify correct computation at multiple base fee levelscargo checkpasses for kora-txpool, kora-rpc, and kora-runnerCloses #7
🤖 Generated with Claude Code