@@ -78,7 +78,8 @@ use crate::{
78
78
PoolTransaction , PropagatedTransactions , TransactionOrigin ,
79
79
} ,
80
80
validate:: { TransactionValidationOutcome , ValidPoolTransaction } ,
81
- CanonicalStateUpdate , PoolConfig , TransactionOrdering , TransactionValidator ,
81
+ CanonicalStateUpdate , EthPoolTransaction , PoolConfig , TransactionOrdering ,
82
+ TransactionValidator ,
82
83
} ;
83
84
use alloy_primitives:: { Address , TxHash , B256 } ;
84
85
use best:: BestTransactions ;
@@ -87,9 +88,7 @@ use reth_eth_wire_types::HandleMempoolData;
87
88
use reth_execution_types:: ChangedAccount ;
88
89
89
90
use alloy_eips:: eip4844:: BlobTransactionSidecar ;
90
- use reth_primitives:: {
91
- BlobTransaction , PooledTransactionsElement , TransactionSigned , TransactionSignedEcRecovered ,
92
- } ;
91
+ use reth_primitives:: PooledTransactionsElement ;
93
92
use std:: {
94
93
collections:: { HashMap , HashSet } ,
95
94
fmt,
@@ -312,18 +311,33 @@ where
312
311
self . get_pool_data ( ) . all ( ) . transactions_iter ( ) . filter ( |tx| tx. propagate ) . take ( max) . collect ( )
313
312
}
314
313
315
- /// Returns the [`BlobTransaction`] for the given transaction if the sidecar exists .
314
+ /// Converts the internally tracked transaction to the pooled format .
316
315
///
317
- /// Caution: this assumes the given transaction is eip-4844
318
- fn get_blob_transaction ( & self , transaction : TransactionSigned ) -> Option < BlobTransaction > {
319
- if let Ok ( Some ( sidecar) ) = self . blob_store . get ( transaction. hash ( ) ) {
320
- if let Ok ( blob) =
321
- BlobTransaction :: try_from_signed ( transaction, Arc :: unwrap_or_clone ( sidecar) )
322
- {
323
- return Some ( blob)
324
- }
316
+ /// If the transaction is an EIP-4844 transaction, the blob sidecar is fetched from the blob
317
+ /// store and attached to the transaction.
318
+ fn to_pooled_transaction (
319
+ & self ,
320
+ transaction : Arc < ValidPoolTransaction < T :: Transaction > > ,
321
+ ) -> Option < <<V as TransactionValidator >:: Transaction as PoolTransaction >:: Pooled >
322
+ where
323
+ <V as TransactionValidator >:: Transaction : EthPoolTransaction ,
324
+ {
325
+ if transaction. is_eip4844 ( ) {
326
+ let sidecar = self . blob_store . get ( * transaction. hash ( ) ) . ok ( ) ??;
327
+ transaction. transaction . clone ( ) . try_into_pooled_eip4844 ( sidecar)
328
+ } else {
329
+ transaction
330
+ . transaction
331
+ . clone ( )
332
+ . try_into_pooled ( )
333
+ . inspect_err ( |err| {
334
+ debug ! (
335
+ target: "txpool" , %err,
336
+ "failed to convert transaction to pooled element; skipping" ,
337
+ ) ;
338
+ } )
339
+ . ok ( )
325
340
}
326
- None
327
341
}
328
342
329
343
/// Returns converted [`PooledTransactionsElement`] for the given transaction hashes.
@@ -333,39 +347,19 @@ where
333
347
limit : GetPooledTransactionLimit ,
334
348
) -> Vec < PooledTransactionsElement >
335
349
where
336
- <V as TransactionValidator >:: Transaction :
337
- PoolTransaction < Consensus : Into < TransactionSignedEcRecovered > > ,
350
+ <V as TransactionValidator >:: Transaction : EthPoolTransaction ,
338
351
{
339
352
let transactions = self . get_all ( tx_hashes) ;
340
353
let mut elements = Vec :: with_capacity ( transactions. len ( ) ) ;
341
354
let mut size = 0 ;
342
355
for transaction in transactions {
343
356
let encoded_len = transaction. encoded_length ( ) ;
344
- let recovered: TransactionSignedEcRecovered =
345
- transaction. transaction . clone ( ) . into_consensus ( ) . into ( ) ;
346
- let tx = recovered. into_signed ( ) ;
347
- let pooled = if tx. is_eip4844 ( ) {
348
- // for EIP-4844 transactions, we need to fetch the blob sidecar from the blob store
349
- if let Some ( blob) = self . get_blob_transaction ( tx) {
350
- PooledTransactionsElement :: BlobTransaction ( blob)
351
- } else {
352
- continue
353
- }
354
- } else {
355
- match PooledTransactionsElement :: try_from ( tx) {
356
- Ok ( element) => element,
357
- Err ( err) => {
358
- debug ! (
359
- target: "txpool" , %err,
360
- "failed to convert transaction to pooled element; skipping" ,
361
- ) ;
362
- continue
363
- }
364
- }
357
+ let Some ( pooled) = self . to_pooled_transaction ( transaction) else {
358
+ continue ;
365
359
} ;
366
360
367
361
size += encoded_len;
368
- elements. push ( pooled) ;
362
+ elements. push ( pooled. into ( ) ) ;
369
363
370
364
if limit. exceeds ( size) {
371
365
break
@@ -381,19 +375,9 @@ where
381
375
tx_hash : TxHash ,
382
376
) -> Option < PooledTransactionsElement >
383
377
where
384
- <V as TransactionValidator >:: Transaction :
385
- PoolTransaction < Consensus : Into < TransactionSignedEcRecovered > > ,
378
+ <V as TransactionValidator >:: Transaction : EthPoolTransaction ,
386
379
{
387
- self . get ( & tx_hash) . and_then ( |transaction| {
388
- let recovered: TransactionSignedEcRecovered =
389
- transaction. transaction . clone ( ) . into_consensus ( ) . into ( ) ;
390
- let tx = recovered. into_signed ( ) ;
391
- if tx. is_eip4844 ( ) {
392
- self . get_blob_transaction ( tx) . map ( PooledTransactionsElement :: BlobTransaction )
393
- } else {
394
- PooledTransactionsElement :: try_from ( tx) . ok ( )
395
- }
396
- } )
380
+ self . get ( & tx_hash) . and_then ( |tx| self . to_pooled_transaction ( tx) . map ( Into :: into) )
397
381
}
398
382
399
383
/// Updates the entire pool after a new block was executed.
0 commit comments