refactor(block): extract shared transaction selection logic into tx_selection module#94
refactor(block): extract shared transaction selection logic into tx_selection module#94davidtaikocha merged 9 commits intomainfrom
tx_selection module#94Conversation
Design document for unifying transaction selection logic between payload builder and RPC endpoint into a shared module in crates/block. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Unify overlapping transaction selection logic between payload builder and RPC endpoint into a shared `tx_selection` module in crates/block. Changes: - Add `TxSelectionConfig`, `ExecutedTx`, `ExecutedTxList`, `SelectionOutcome` - Add `select_and_execute_pool_transactions` function - Refactor `execute_anchor_and_pool_transactions` in payload builder - Refactor `tx_pool_content_with_min_tip` in RPC auth module This reduces code duplication (~160 lines removed) and ensures consistent behavior between payload building and RPC pre-building. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
Claude finished @davidtaikocha's task —— View job Code Review Complete ✓Todo List
Review Feedback✅ Overall AssessmentSolid refactoring that successfully eliminates ~130 lines of duplication. The extracted logic is well-structured and the unified API improves maintainability. A few issues need attention before merging. 🐛 Bugs & Issues1. CRITICAL: Incorrect error mapping for DA limit violationsLocation: When a transaction exceeds DA limits, it's marked as // Current (line 153):
} else {
best_txs.mark_invalid(&pool_tx, &InvalidPoolTransactionError::Underpriced);
}Problem: DA limit violations aren't pricing issues. Marking them as underpriced will affect tip-based pool ordering and could remove valid high-tip transactions. Fix: Use a more appropriate error like best_txs.mark_invalid(&pool_tx, &InvalidPoolTransactionError::Other(
Box::new("Transaction exceeds DA size limit")
));2. Nonce-too-low handling differs from originalLocation: Original code in Impact: This changes behavior. Not marking invalid means dependent transactions will still be tried (could be intentional, but should be documented in PR description if so). Recommendation: Either revert to original behavior or add a comment explaining why nonce-too-low deserves special treatment. 3. Unreachable panic in RPC codeLocation: Ok(SelectionOutcome::Cancelled) => {
unreachable!("tx selection should never be cancelled")
}If the Ok(SelectionOutcome::Cancelled) => {
Err(EthApiError::Internal("unexpected cancellation".into()).into())
}⚡ Performance Considerations4. Redundant DA size calculation on list overflowLocation: DA size is calculated before checking if it fits in any list. For transactions that don't fit in the current list when Optimization: Move line 134 inside the 5. Vec allocation patternLists are allocated with let mut lists = Vec::with_capacity(config.max_lists);
lists.push(ExecutedTxList::default());Minor improvement but reduces allocations for multi-list scenarios. 🔒 Security Concerns6. Local account filtering bypasses tip requirementLocation: Non-local transactions are marked
Recommendation: Use a different error type or add a comment explaining this is intentional censorship of non-locals. 7. No validation of config parameters
Add validation in 🧪 Test Coverage8. Zero test coverage for new moduleNo tests exist for
Action Required: Add unit tests, especially for edge cases like:
📝 Code Quality & Best Practices9. Missing documentation
10. Typo in branch nameBranch is 11. Inconsistent error messages
Consider standardizing error message format across the module. ✨ Strengths
📋 SummaryMust Fix Before Merge:
Should Fix:
Nice to Have:
| Branch: |
Summary
tx_selectionmodule incrates/blockTxSelectionConfigsupporting gas limits, DA size limits, multi-list generation, min tip filtering, and local account filteringChanges
crates/block/src/tx_selection.rsselect_and_execute_pool_transactionscrates/payload/src/builder.rscrates/rpc/src/eth/auth.rsMotivation
execute_anchor_and_pool_transactions(payload builder) andtx_pool_content_with_min_tip(RPC) shared nearly identical logic for:Unifying this logic ensures: