Skip to content

Commit

Permalink
chore: revert early exit in case of no budget
Browse files Browse the repository at this point in the history
  • Loading branch information
Elvis339 committed Dec 13, 2024
1 parent dc2af71 commit b5ce2a6
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions crates/net/network/src/transactions/fetcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,13 +222,6 @@ impl<N: NetworkPrimitives> TransactionFetcher<N> {
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);
Expand All @@ -237,6 +230,13 @@ impl<N: NetworkPrimitives> TransactionFetcher<N> {
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()?;

Expand Down Expand Up @@ -743,14 +743,6 @@ impl<N: NetworkPrimitives> TransactionFetcher<N> {
// 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
Expand Down Expand Up @@ -778,6 +770,13 @@ impl<N: NetworkPrimitives> TransactionFetcher<N> {
{
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.
Expand Down

0 comments on commit b5ce2a6

Please sign in to comment.