@@ -387,6 +387,7 @@ pub struct Task<P, V, B, T> {
387387 broadcast : B ,
388388 tx_pool : T ,
389389 max_headers_per_request : usize ,
390+ max_txs_per_request : usize ,
390391 // milliseconds wait time between peer heartbeat reputation checks
391392 heartbeat_check_interval : Duration ,
392393 heartbeat_max_avg_interval : Duration ,
@@ -643,9 +644,10 @@ where
643644 request_id : InboundRequestId ,
644645 ) -> anyhow:: Result < ( ) > {
645646 let tx_pool = self . tx_pool . clone ( ) ;
647+ let max_txs = self . max_txs_per_request ;
646648 self . handle_txpool_request (
647649 request_id,
648- move || tx_pool. get_all_tx_ids ( ) ,
650+ move || tx_pool. get_all_tx_ids ( ) . into_iter ( ) . take ( max_txs ) . collect ( ) ,
649651 ResponseMessage :: TxPoolAllTransactionsIds ,
650652 |response, request_id| TaskRequest :: TxPoolAllTransactionsIds {
651653 response,
@@ -660,9 +662,16 @@ where
660662 request_id : InboundRequestId ,
661663 ) -> anyhow:: Result < ( ) > {
662664 let tx_pool = self . tx_pool . clone ( ) ;
665+ let max_txs = self . max_txs_per_request ;
663666 self . handle_txpool_request (
664667 request_id,
665- move || tx_pool. get_full_txs ( tx_ids) ,
668+ move || {
669+ tx_pool
670+ . get_full_txs ( tx_ids)
671+ . into_iter ( )
672+ . take ( max_txs)
673+ . collect ( )
674+ } ,
666675 ResponseMessage :: TxPoolFullTransactions ,
667676 |response, request_id| TaskRequest :: TxPoolFullTransactions {
668677 response,
@@ -715,6 +724,7 @@ where
715724 let Config {
716725 max_block_size,
717726 max_headers_per_request,
727+ max_txs_per_request,
718728 heartbeat_check_interval,
719729 heartbeat_max_avg_interval,
720730 heartbeat_max_time_since_last,
@@ -757,6 +767,7 @@ where
757767 tx_pool,
758768 heavy_task_processor,
759769 max_headers_per_request,
770+ max_txs_per_request,
760771 heartbeat_check_interval,
761772 heartbeat_max_avg_interval,
762773 heartbeat_max_time_since_last,
@@ -1529,6 +1540,7 @@ pub mod tests {
15291540 heavy_task_processor : HeavyTaskProcessor :: new ( 1 , 1 ) . unwrap ( ) ,
15301541 broadcast,
15311542 max_headers_per_request : 0 ,
1543+ max_txs_per_request : 100 ,
15321544 heartbeat_check_interval : Duration :: from_secs ( 0 ) ,
15331545 heartbeat_max_avg_interval,
15341546 heartbeat_max_time_since_last,
@@ -1617,6 +1629,7 @@ pub mod tests {
16171629 heavy_task_processor : HeavyTaskProcessor :: new ( 1 , 1 ) . unwrap ( ) ,
16181630 broadcast,
16191631 max_headers_per_request : 0 ,
1632+ max_txs_per_request : 100 ,
16201633 heartbeat_check_interval : Duration :: from_secs ( 0 ) ,
16211634 heartbeat_max_avg_interval,
16221635 heartbeat_max_time_since_last,
@@ -1677,6 +1690,7 @@ pub mod tests {
16771690 heavy_task_processor : HeavyTaskProcessor :: new ( 1 , 1 ) . unwrap ( ) ,
16781691 broadcast,
16791692 max_headers_per_request : 0 ,
1693+ max_txs_per_request : 100 ,
16801694 heartbeat_check_interval : Duration :: from_secs ( 0 ) ,
16811695 heartbeat_max_avg_interval : Default :: default ( ) ,
16821696 heartbeat_max_time_since_last : Default :: default ( ) ,
0 commit comments