diff --git a/crates/net/network/src/transactions/fetcher.rs b/crates/net/network/src/transactions/fetcher.rs index 130883a827ad..c31567b59aeb 100644 --- a/crates/net/network/src/transactions/fetcher.rs +++ b/crates/net/network/src/transactions/fetcher.rs @@ -222,13 +222,6 @@ impl TransactionFetcher { let mut hashes_pending_fetch_iter = self.hashes_pending_fetch.iter(); let idle_peer = loop { - if let Some(ref mut bud) = budget { - *bud = bud.saturating_sub(1); - if *bud == 0 { - return None - } - } - let &hash = hashes_pending_fetch_iter.next()?; let idle_peer = self.get_idle_peer_for(hash, peers); @@ -237,6 +230,13 @@ impl TransactionFetcher { hashes_to_request.insert(hash); break idle_peer.copied() } + + if let Some(ref mut bud) = budget { + *bud = bud.saturating_sub(1); + if *bud == 0 { + return None + } + } }; let hash = hashes_to_request.iter().next()?; @@ -743,14 +743,6 @@ impl TransactionFetcher { // try to fill request by checking if any other hashes pending fetch (in lru order) are // also seen by peer for hash in self.hashes_pending_fetch.iter() { - // Early exit if there's no budget - if let Some(ref mut bud) = budget_fill_request { - *bud = bud.saturating_sub(1); - if *bud == 0 { - return - } - } - // 1. Check if a hash pending fetch is seen by peer. if !seen_hashes.contains(hash) { continue @@ -778,6 +770,13 @@ impl TransactionFetcher { { break } + + if let Some(ref mut bud) = budget_fill_request { + *bud = bud.saturating_sub(1); + if *bud == 0 { + return + } + } } // 5. Remove hashes to request from cache of hashes pending fetch.