diff --git a/crates/net/network/src/transactions/fetcher.rs b/crates/net/network/src/transactions/fetcher.rs index 403c8b03ee..5e261eca7f 100644 --- a/crates/net/network/src/transactions/fetcher.rs +++ b/crates/net/network/src/transactions/fetcher.rs @@ -90,10 +90,10 @@ impl TransactionFetcher { fn decrement_inflight_request_count_for(&mut self, peer_id: &PeerId) { let remove = || -> bool { if let Some(inflight_count) = self.active_peers.get(peer_id) { - if *inflight_count <= DEFAULT_MAX_COUNT_CONCURRENT_REQUESTS_PER_PEER { + *inflight_count -= 1; + if *inflight_count == 0 { return true } - *inflight_count -= 1; } false }(); diff --git a/crates/net/network/src/transactions/mod.rs b/crates/net/network/src/transactions/mod.rs index 8efcb24d19..5980182d6e 100644 --- a/crates/net/network/src/transactions/mod.rs +++ b/crates/net/network/src/transactions/mod.rs @@ -2053,6 +2053,7 @@ mod tests { // peer_1 is idle assert!(tx_fetcher.is_idle(&peer_id_1)); + assert_eq!(tx_fetcher.active_peers.len(), 0); // sends request for buffered hashes to peer_1 tx_fetcher.on_fetch_pending_hashes(&tx_manager.peers, |_| true, || ()); @@ -2062,6 +2063,7 @@ mod tests { assert!(tx_fetcher.hashes_pending_fetch.is_empty()); // as long as request is in inflight peer_1 is not idle assert!(!tx_fetcher.is_idle(&peer_id_1)); + assert_eq!(tx_fetcher.active_peers.len(), 1); // mock session of peer_1 receives request let req = to_mock_session_rx @@ -2085,6 +2087,7 @@ mod tests { // request has resolved, peer_1 is idle again assert!(tx_fetcher.is_idle(&peer_id)); + assert_eq!(tx_fetcher.active_peers.len(), 0); // failing peer_1's request buffers requested hashes for retry assert_eq!(tx_fetcher.hashes_pending_fetch.len(), 2); @@ -2098,6 +2101,9 @@ mod tests { let tx_fetcher = &mut tx_manager.transaction_fetcher; + // peer_2 should be in active_peers. + assert_eq!(tx_fetcher.active_peers.len(), 1); + // since hashes are already seen, no changes to length of unknown hashes assert_eq!(tx_fetcher.hashes_fetch_inflight_and_pending_fetch.len(), 2); // but hashes are taken out of buffer and packed into request to peer_2 @@ -2119,5 +2125,6 @@ mod tests { // `MAX_REQUEST_RETRIES_PER_TX_HASH`, 2, for hashes reached so this time won't be buffered // for retry assert!(tx_fetcher.hashes_pending_fetch.is_empty()); + assert_eq!(tx_fetcher.active_peers.len(), 0); } }