fix: active inflight count (#11598)

This commit is contained in:
Matthias Seitz
2024-10-09 12:03:25 +02:00
committed by GitHub
parent 62954591d2
commit d5372a739e
2 changed files with 9 additions and 3 deletions

View File

@ -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));

View File

@ -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, ..