Skip to content

Commit

Permalink
Fix bug, add concurrency param from config to TransactionFetcherInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
emhane committed Oct 9, 2024
1 parent 6295459 commit 3525244
Showing 1 changed file with 7 additions and 21 deletions.
28 changes: 7 additions & 21 deletions crates/net/network/src/transactions/fetcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ impl TransactionFetcher {
/// Returns `true` if peer is idle with respect to `self.inflight_requests`.
pub fn is_idle(&self, peer_id: &PeerId) -> bool {
let Some(inflight_count) = self.active_peers.peek(peer_id) else { return true };
if *inflight_count < DEFAULT_MAX_COUNT_CONCURRENT_REQUESTS_PER_PEER {
if *inflight_count < self.info.max_inflight_requests_per_peer {
return true
}
false
Expand Down Expand Up @@ -648,12 +648,12 @@ impl TransactionFetcher {
return Some(new_announced_hashes)
};

if *inflight_count >= DEFAULT_MAX_COUNT_CONCURRENT_REQUESTS_PER_PEER {
if *inflight_count >= self.info.max_inflight_requests_per_peer {
trace!(target: "net::tx",
peer_id=format!("{peer_id:#}"),
hashes=?*new_announced_hashes,
%conn_eth_version,
max_concurrent_tx_reqs_per_peer=DEFAULT_MAX_COUNT_CONCURRENT_REQUESTS_PER_PEER,
max_concurrent_tx_reqs_per_peer=self.info.max_inflight_requests_per_peer,
"limit for concurrent `GetPooledTransactions` requests per peer reached"
);
return Some(new_announced_hashes)
Expand Down Expand Up @@ -1283,10 +1283,12 @@ pub enum VerificationOutcome {
}

/// Tracks stats about the [`TransactionFetcher`].
#[derive(Debug)]
#[derive(Debug, Constructor)]
pub struct TransactionFetcherInfo {
/// Max inflight [`GetPooledTransactions`] requests.
pub max_inflight_requests: usize,
/// Max inflight [`GetPooledTransactions`] requests per peer.
pub max_inflight_requests_per_peer: u8,
/// Soft limit for the byte size of the expected [`PooledTransactions`] response, upon packing
/// a [`GetPooledTransactions`] request with hashes (by default less than 2 MiB worth of
/// transactions is requested).
Expand All @@ -1300,27 +1302,11 @@ pub struct TransactionFetcherInfo {
pub max_capacity_cache_txns_pending_fetch: u32,
}

impl TransactionFetcherInfo {
/// Creates a new max
pub const fn new(
max_inflight_requests: usize,
soft_limit_byte_size_pooled_transactions_response_on_pack_request: usize,
soft_limit_byte_size_pooled_transactions_response: usize,
max_capacity_cache_txns_pending_fetch: u32,
) -> Self {
Self {
max_inflight_requests,
soft_limit_byte_size_pooled_transactions_response_on_pack_request,
soft_limit_byte_size_pooled_transactions_response,
max_capacity_cache_txns_pending_fetch,
}
}
}

impl Default for TransactionFetcherInfo {
fn default() -> Self {
Self::new(
DEFAULT_MAX_COUNT_CONCURRENT_REQUESTS as usize * DEFAULT_MAX_COUNT_CONCURRENT_REQUESTS_PER_PEER as usize,
DEFAULT_MAX_COUNT_CONCURRENT_REQUESTS_PER_PEER,
DEFAULT_SOFT_LIMIT_BYTE_SIZE_POOLED_TRANSACTIONS_RESP_ON_PACK_GET_POOLED_TRANSACTIONS_REQ,
SOFT_LIMIT_BYTE_SIZE_POOLED_TRANSACTIONS_RESPONSE,
DEFAULT_MAX_CAPACITY_CACHE_PENDING_FETCH,
Expand Down

0 comments on commit 3525244

Please sign in to comment.