bound hashes inflight and pending fetch size (#6877)

Signed-off-by: int88 <golden-miner@qq.com>
This commit is contained in:
int88
2024-03-01 09:58:42 +08:00
committed by GitHub
parent 2df0d91f8d
commit 1d28fc606e
2 changed files with 16 additions and 3 deletions

View File

@@ -132,6 +132,15 @@ pub mod tx_fetcher {
pub const DEFAULT_MAX_CAPACITY_CACHE_PENDING_FETCH: usize =
100 * SOFT_LIMIT_COUNT_HASHES_IN_GET_POOLED_TRANSACTIONS_REQUEST;
/// Default max size for cache of inflight and pending transactions fetch.
///
/// Default is [`DEFAULT_MAX_CAPACITY_CACHE_PENDING_FETCH`] +
/// [`DEFAULT_MAX_COUNT_INFLIGHT_REQUESTS_ON_FETCH_PENDING_HASHES`], which is 25600 hashes and
/// 65 requests, so it is 25665 hashes.
pub const DEFAULT_MAX_CAPACITY_CACHE_INFLIGHT_AND_PENDING_FETCH: usize =
DEFAULT_MAX_CAPACITY_CACHE_PENDING_FETCH +
DEFAULT_MAX_COUNT_INFLIGHT_REQUESTS_ON_FETCH_PENDING_HASHES;
/// Default maximum number of hashes pending fetch to tolerate at any time.
///
/// Default is half of [`DEFAULT_MAX_CAPACITY_CACHE_PENDING_FETCH`], which defaults to 25 600

View File

@@ -16,7 +16,7 @@ use reth_metrics::common::mpsc::{
metered_unbounded_channel, UnboundedMeteredReceiver, UnboundedMeteredSender,
};
use reth_primitives::{PeerId, PooledTransactionsElement, TxHash};
use schnellru::{ByLength, Unlimited};
use schnellru::ByLength;
#[cfg(debug_assertions)]
use smallvec::{smallvec, SmallVec};
use std::{
@@ -58,7 +58,7 @@ pub struct TransactionFetcher {
/// which a [`GetPooledTransactions`] request is inflight.
pub hashes_pending_fetch: LruCache<TxHash>,
/// Tracks all hashes in the transaction fetcher.
pub(super) hashes_fetch_inflight_and_pending_fetch: LruMap<TxHash, TxFetchMetadata, Unlimited>,
pub(super) hashes_fetch_inflight_and_pending_fetch: LruMap<TxHash, TxFetchMetadata, ByLength>,
/// Filter for valid announcement and response data.
pub(super) filter_valid_message: MessageFilter,
/// Info on capacity of the transaction fetcher.
@@ -949,7 +949,11 @@ impl Default for TransactionFetcher {
NonZeroUsize::new(DEFAULT_MAX_CAPACITY_CACHE_PENDING_FETCH)
.expect("buffered cache limit should be non-zero"),
),
hashes_fetch_inflight_and_pending_fetch: LruMap::new_unlimited(),
hashes_fetch_inflight_and_pending_fetch: LruMap::new(
DEFAULT_MAX_CAPACITY_CACHE_INFLIGHT_AND_PENDING_FETCH
.try_into()
.expect("proper size for inflight and pending fetch cache"),
),
filter_valid_message: Default::default(),
info: TransactionFetcherInfo::default(),
fetch_events_head,