Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions crates/net/network/src/transactions/fetcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ impl<N: NetworkPrimitives> TransactionFetcher<N> {
&mut self,
peers: &HashMap<PeerId, PeerMetadata<N>>,
has_capacity_wrt_pending_pool_imports: impl Fn(usize) -> bool,
) {
) -> bool {
let mut hashes_to_request = RequestTxHashes::with_capacity(
DEFAULT_MARGINAL_COUNT_HASHES_GET_POOLED_TRANSACTIONS_REQUEST,
);
Expand All @@ -440,7 +440,7 @@ impl<N: NetworkPrimitives> TransactionFetcher<N> {
budget_find_idle_fallback_peer,
) else {
// no peers are idle or budget is depleted
return
return false
};

peer_id
Expand All @@ -449,7 +449,7 @@ impl<N: NetworkPrimitives> TransactionFetcher<N> {
);

// peer should always exist since `is_session_active` already checked
let Some(peer) = peers.get(&peer_id) else { return };
let Some(peer) = peers.get(&peer_id) else { return false };
let conn_eth_version = peer.version;

// fill the request with more hashes pending fetch that have been announced by the peer.
Expand Down Expand Up @@ -493,7 +493,10 @@ impl<N: NetworkPrimitives> TransactionFetcher<N> {
);

self.buffer_hashes(failed_to_request_hashes, Some(peer_id));
return false
}

true
}

/// Filters out hashes that have been seen before. For hashes that have already been seen, the
Expand Down
11 changes: 7 additions & 4 deletions crates/net/network/src/transactions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -495,15 +495,17 @@ impl<Pool: TransactionPool, N: NetworkPrimitives> TransactionsManager<Pool, N> {
}

/// Runs an operation to fetch hashes that are cached in [`TransactionFetcher`].
fn on_fetch_hashes_pending_fetch(&mut self) {
///
/// Returns `true` if a request was sent.
fn on_fetch_hashes_pending_fetch(&mut self) -> bool {
// try drain transaction hashes pending fetch
let info = &self.pending_pool_imports_info;
let max_pending_pool_imports = info.max_pending_pool_imports;
let has_capacity_wrt_pending_pool_imports =
|divisor| info.has_capacity(max_pending_pool_imports / divisor);

self.transaction_fetcher
.on_fetch_pending_hashes(&self.peers, has_capacity_wrt_pending_pool_imports);
.on_fetch_pending_hashes(&self.peers, has_capacity_wrt_pending_pool_imports)
}

fn on_request_error(&self, peer_id: PeerId, req_err: RequestError) {
Expand Down Expand Up @@ -1625,8 +1627,9 @@ where
// Sends at most one request.
duration_metered_exec!(
{
if this.has_capacity_for_fetching_pending_hashes() {
this.on_fetch_hashes_pending_fetch();
if this.has_capacity_for_fetching_pending_hashes() &&
this.on_fetch_hashes_pending_fetch()
{
maybe_more_tx_fetch_events = true;
}
},
Expand Down
Loading