mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 19:09:54 +00:00
chore(net): Expose max seen transactions history size as cli arg (#10327)
Co-authored-by: Oliver <onbjerg@users.noreply.github.com>
This commit is contained in:
@ -1,16 +1,28 @@
|
||||
use derive_more::Constructor;
|
||||
|
||||
use super::{
|
||||
DEFAULT_MAX_COUNT_TRANSACTIONS_SEEN_BY_PEER,
|
||||
DEFAULT_SOFT_LIMIT_BYTE_SIZE_POOLED_TRANSACTIONS_RESP_ON_PACK_GET_POOLED_TRANSACTIONS_REQ,
|
||||
SOFT_LIMIT_BYTE_SIZE_POOLED_TRANSACTIONS_RESPONSE,
|
||||
};
|
||||
|
||||
/// Configuration for managing transactions within the network.
|
||||
#[derive(Debug, Default, Clone)]
|
||||
#[derive(Debug, Clone)]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
pub struct TransactionsManagerConfig {
|
||||
/// Configuration for fetching transactions.
|
||||
pub transaction_fetcher_config: TransactionFetcherConfig,
|
||||
/// Max number of seen transactions to store for each peer.
|
||||
pub max_transactions_seen_by_peer_history: u32,
|
||||
}
|
||||
|
||||
impl Default for TransactionsManagerConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
transaction_fetcher_config: TransactionFetcherConfig::default(),
|
||||
max_transactions_seen_by_peer_history: DEFAULT_MAX_COUNT_TRANSACTIONS_SEEN_BY_PEER,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Configuration for fetching transactions.
|
||||
|
||||
@ -39,7 +39,7 @@ pub mod tx_manager {
|
||||
|
||||
/// Default limit for number of transactions to keep track of for a single peer.
|
||||
///
|
||||
/// Default is 10 KiB, i.e. 320 transaction hashes.
|
||||
/// Default is 320 transaction hashes.
|
||||
pub const DEFAULT_MAX_COUNT_TRANSACTIONS_SEEN_BY_PEER: u32 = 10 * 1024 / 32;
|
||||
|
||||
/// Default maximum pending pool imports to tolerate.
|
||||
|
||||
@ -245,6 +245,8 @@ pub struct TransactionsManager<Pool> {
|
||||
pending_transactions: ReceiverStream<TxHash>,
|
||||
/// Incoming events from the [`NetworkManager`](crate::NetworkManager).
|
||||
transaction_events: UnboundedMeteredReceiver<NetworkTransactionEvent>,
|
||||
/// Max number of seen transactions to store for each peer.
|
||||
max_transactions_seen_by_peer_history: u32,
|
||||
/// `TransactionsManager` metrics
|
||||
metrics: TransactionsManagerMetrics,
|
||||
}
|
||||
@ -295,6 +297,8 @@ impl<Pool: TransactionPool> TransactionsManager<Pool> {
|
||||
from_network,
|
||||
NETWORK_POOL_TRANSACTIONS_SCOPE,
|
||||
),
|
||||
max_transactions_seen_by_peer_history: transactions_manager_config
|
||||
.max_transactions_seen_by_peer_history,
|
||||
metrics,
|
||||
}
|
||||
}
|
||||
@ -904,7 +908,12 @@ where
|
||||
peer_id, client_version, messages, version, ..
|
||||
} => {
|
||||
// Insert a new peer into the peerset.
|
||||
let peer = PeerMetadata::new(messages, version, client_version);
|
||||
let peer = PeerMetadata::new(
|
||||
messages,
|
||||
version,
|
||||
client_version,
|
||||
self.max_transactions_seen_by_peer_history,
|
||||
);
|
||||
let peer = match self.peers.entry(peer_id) {
|
||||
Entry::Occupied(mut entry) => {
|
||||
entry.insert(peer);
|
||||
@ -1613,9 +1622,14 @@ pub struct PeerMetadata {
|
||||
|
||||
impl PeerMetadata {
|
||||
/// Returns a new instance of [`PeerMetadata`].
|
||||
fn new(request_tx: PeerRequestSender, version: EthVersion, client_version: Arc<str>) -> Self {
|
||||
fn new(
|
||||
request_tx: PeerRequestSender,
|
||||
version: EthVersion,
|
||||
client_version: Arc<str>,
|
||||
max_transactions_seen_by_peer: u32,
|
||||
) -> Self {
|
||||
Self {
|
||||
seen_transactions: LruCache::new(DEFAULT_MAX_COUNT_TRANSACTIONS_SEEN_BY_PEER),
|
||||
seen_transactions: LruCache::new(max_transactions_seen_by_peer),
|
||||
request_tx,
|
||||
version,
|
||||
client_version,
|
||||
@ -1782,6 +1796,7 @@ mod tests {
|
||||
PeerRequestSender::new(peer_id, to_mock_session_tx),
|
||||
version,
|
||||
Arc::from(""),
|
||||
DEFAULT_MAX_COUNT_TRANSACTIONS_SEEN_BY_PEER,
|
||||
),
|
||||
to_mock_session_rx,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user