Skip to content

Commit 82a9b86

Browse files
committed
Check size when sending and add documentation port
1 parent b6537bf commit 82a9b86

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

crates/services/p2p/src/ports.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ pub trait BlockHeightImporter: Send + Sync {
3434
}
3535

3636
pub trait TxPool: Send + Sync + Clone {
37+
/// Get all tx ids in the pool
3738
fn get_all_tx_ids(&self) -> Vec<TxId>;
3839

40+
/// Get full txs from the pool
3941
fn get_full_txs(&self, tx_ids: Vec<TxId>) -> Vec<Option<NetworkableTransactionPool>>;
4042
}

crates/services/p2p/src/service.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)