Skip to content

Commit

Permalink
perf: rm redundant lookup (#13398)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse authored Dec 16, 2024
1 parent 8b647d6 commit 37ca547
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions crates/net/network/src/transactions/fetcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,16 +191,12 @@ impl<N: NetworkPrimitives> TransactionFetcher<N> {
}

/// Returns any idle peer for the given hash.
pub fn get_idle_peer_for(
&self,
hash: TxHash,
peers: &HashMap<PeerId, PeerMetadata<N>>,
) -> Option<&PeerId> {
pub fn get_idle_peer_for(&self, hash: TxHash) -> Option<&PeerId> {
let TxFetchMetadata { fallback_peers, .. } =
self.hashes_fetch_inflight_and_pending_fetch.peek(&hash)?;

for peer_id in fallback_peers.iter() {
if self.is_idle(peer_id) && peers.contains_key(peer_id) {
if self.is_idle(peer_id) {
return Some(peer_id)
}
}
Expand All @@ -216,15 +212,14 @@ impl<N: NetworkPrimitives> TransactionFetcher<N> {
pub fn find_any_idle_fallback_peer_for_any_pending_hash(
&mut self,
hashes_to_request: &mut RequestTxHashes,
peers: &HashMap<PeerId, PeerMetadata<N>>,
mut budget: Option<usize>, // search fallback peers for max `budget` lru pending hashes
) -> Option<PeerId> {
let mut hashes_pending_fetch_iter = self.hashes_pending_fetch.iter();

let idle_peer = loop {
let &hash = hashes_pending_fetch_iter.next()?;

let idle_peer = self.get_idle_peer_for(hash, peers);
let idle_peer = self.get_idle_peer_for(hash);

if idle_peer.is_some() {
hashes_to_request.insert(hash);
Expand Down Expand Up @@ -442,7 +437,6 @@ impl<N: NetworkPrimitives> TransactionFetcher<N> {
{
let Some(peer_id) = self.find_any_idle_fallback_peer_for_any_pending_hash(
&mut hashes_to_request,
peers,
budget_find_idle_fallback_peer,
) else {
// no peers are idle or budget is depleted
Expand Down

0 comments on commit 37ca547

Please sign in to comment.