diff --git a/crates/net/network/src/transactions/fetcher.rs b/crates/net/network/src/transactions/fetcher.rs index e15972df08..0b849b6591 100644 --- a/crates/net/network/src/transactions/fetcher.rs +++ b/crates/net/network/src/transactions/fetcher.rs @@ -98,6 +98,11 @@ pub struct TransactionFetcher { // === impl TransactionFetcher === impl TransactionFetcher { + /// Removes the peer from the active set. + pub(crate) fn remove_peer(&mut self, peer_id: &PeerId) { + self.active_peers.remove(peer_id); + } + /// Updates metrics. #[inline] pub fn update_metrics(&self) { @@ -157,7 +162,7 @@ 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) { - *inflight_count -= 1; + *inflight_count = inflight_count.saturating_sub(1); if *inflight_count == 0 { return true } @@ -659,8 +664,6 @@ impl TransactionFetcher { return Some(new_announced_hashes) } - *inflight_count += 1; - #[cfg(debug_assertions)] { for hash in &new_announced_hashes { @@ -695,6 +698,8 @@ impl TransactionFetcher { } } } + + *inflight_count += 1; // stores a new request future for the request self.inflight_requests.push(GetPooledTxRequestFut::new(peer_id, new_announced_hashes, rx)); diff --git a/crates/net/network/src/transactions/mod.rs b/crates/net/network/src/transactions/mod.rs index 2fa4ccfbb6..24cc8f6140 100644 --- a/crates/net/network/src/transactions/mod.rs +++ b/crates/net/network/src/transactions/mod.rs @@ -904,6 +904,7 @@ where NetworkEvent::SessionClosed { peer_id, .. } => { // remove the peer self.peers.remove(&peer_id); + self.transaction_fetcher.remove_peer(&peer_id); } NetworkEvent::SessionEstablished { peer_id, client_version, messages, version, ..