@@ -78,7 +78,8 @@ use crate::{
7878 PoolTransaction , PropagatedTransactions , TransactionOrigin ,
7979 } ,
8080 validate:: { TransactionValidationOutcome , ValidPoolTransaction } ,
81- CanonicalStateUpdate , PoolConfig , TransactionOrdering , TransactionValidator ,
81+ CanonicalStateUpdate , EthPoolTransaction , PoolConfig , TransactionOrdering ,
82+ TransactionValidator ,
8283} ;
8384use alloy_primitives:: { Address , TxHash , B256 } ;
8485use best:: BestTransactions ;
@@ -87,9 +88,7 @@ use reth_eth_wire_types::HandleMempoolData;
8788use reth_execution_types:: ChangedAccount ;
8889
8990use alloy_eips:: eip4844:: BlobTransactionSidecar ;
90- use reth_primitives:: {
91- BlobTransaction , PooledTransactionsElement , TransactionSigned , TransactionSignedEcRecovered ,
92- } ;
91+ use reth_primitives:: PooledTransactionsElement ;
9392use std:: {
9493 collections:: { HashMap , HashSet } ,
9594 fmt,
@@ -312,18 +311,33 @@ where
312311 self . get_pool_data ( ) . all ( ) . transactions_iter ( ) . filter ( |tx| tx. propagate ) . take ( max) . collect ( )
313312 }
314313
315- /// Returns the [`BlobTransaction`] for the given transaction if the sidecar exists .
314+ /// Converts the internally tracked transaction to the pooled format .
316315 ///
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 ( )
325340 }
326- None
327341 }
328342
329343 /// Returns converted [`PooledTransactionsElement`] for the given transaction hashes.
@@ -333,39 +347,19 @@ where
333347 limit : GetPooledTransactionLimit ,
334348 ) -> Vec < PooledTransactionsElement >
335349 where
336- <V as TransactionValidator >:: Transaction :
337- PoolTransaction < Consensus : Into < TransactionSignedEcRecovered > > ,
350+ <V as TransactionValidator >:: Transaction : EthPoolTransaction ,
338351 {
339352 let transactions = self . get_all ( tx_hashes) ;
340353 let mut elements = Vec :: with_capacity ( transactions. len ( ) ) ;
341354 let mut size = 0 ;
342355 for transaction in transactions {
343356 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 ;
365359 } ;
366360
367361 size += encoded_len;
368- elements. push ( pooled) ;
362+ elements. push ( pooled. into ( ) ) ;
369363
370364 if limit. exceeds ( size) {
371365 break
@@ -381,19 +375,9 @@ where
381375 tx_hash : TxHash ,
382376 ) -> Option < PooledTransactionsElement >
383377 where
384- <V as TransactionValidator >:: Transaction :
385- PoolTransaction < Consensus : Into < TransactionSignedEcRecovered > > ,
378+ <V as TransactionValidator >:: Transaction : EthPoolTransaction ,
386379 {
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) )
397381 }
398382
399383 /// Updates the entire pool after a new block was executed.
0 commit comments