|
1 | 1 | use alloy_primitives::Bytes; |
2 | | -use alloy_rlp::Encodable; |
3 | 2 | use async_trait::async_trait; |
4 | 3 | use jsonrpsee_core::RpcResult; |
5 | 4 | use jsonrpsee_proc_macros::rpc; |
6 | | -use reth_transaction_pool::{TransactionPool, ValidPoolTransaction}; |
| 5 | +use reth_transaction_pool::{PoolTransaction, TransactionPool}; |
7 | 6 |
|
8 | 7 | /// Rollkit txpool RPC API trait |
9 | 8 | #[rpc(server, namespace = "txpoolExt")] |
@@ -48,31 +47,30 @@ where |
48 | 47 | /// Returns a Geth-style `TxpoolContent` with raw RLP hex strings. |
49 | 48 | async fn get_txs(&self) -> RpcResult<Vec<Bytes>> { |
50 | 49 | //------------------------------------------------------------------// |
51 | | - // 1. Iterate pending txs and stop once we hit the byte cap // |
| 50 | + // 1. Iterate best txs (sorted by priority) and stop once we hit // |
| 51 | + // the byte cap // |
52 | 52 | //------------------------------------------------------------------// |
53 | 53 | let mut total = 0u64; |
54 | | - let mut pending_map: Vec<Bytes> = Vec::new(); |
| 54 | + let mut selected_txs: Vec<Bytes> = Vec::new(); |
55 | 55 |
|
56 | | - for arc_tx in self.pool.pending_transactions() { |
57 | | - // deref Arc<ValidPoolTransaction<_>> |
58 | | - let pooled: &ValidPoolTransaction<_> = &arc_tx; |
59 | | - |
60 | | - let sz = pooled.encoded_length() as u64; |
| 56 | + // Use best_transactions() which returns an iterator of transactions |
| 57 | + // ordered by their priority (gas price/priority fee) |
| 58 | + for best_tx in self.pool.best_transactions() { |
| 59 | + let sz = best_tx.encoded_length() as u64; |
61 | 60 | if total + sz > self.max_bytes { |
62 | 61 | break; |
63 | 62 | } |
64 | 63 |
|
65 | | - // inside the loop |
66 | | - let tx = pooled.to_consensus(); |
67 | | - let mut rlp_bytes = Vec::new(); |
68 | | - tx.encode(&mut rlp_bytes); |
| 64 | + // Convert to consensus transaction and encode to RLP |
| 65 | + let tx = best_tx.transaction.clone().into_consensus_with2718(); |
| 66 | + let bz = tx.encoded_bytes(); |
69 | 67 |
|
70 | | - pending_map.push(Bytes::from(rlp_bytes)); |
| 68 | + selected_txs.push(bz.clone()); |
71 | 69 |
|
72 | 70 | total += sz; |
73 | 71 | } |
74 | 72 |
|
75 | | - Ok(pending_map) |
| 73 | + Ok(selected_txs) |
76 | 74 | } |
77 | 75 | } |
78 | 76 |
|
|
0 commit comments