From 8c02acad79f3225e6ffb7cc46358e0772eeec995 Mon Sep 17 00:00:00 2001 From: Emilia Hane Date: Sat, 17 Aug 2024 15:31:31 -0700 Subject: [PATCH] chore(net): Expose max seen transactions history size as cli arg (#10327) Co-authored-by: Oliver --- book/cli/reth/debug/execution.md | 7 +++++++ book/cli/reth/debug/in-memory-merkle.md | 7 +++++++ book/cli/reth/debug/merkle.md | 7 +++++++ book/cli/reth/debug/replay-engine.md | 7 +++++++ book/cli/reth/node.md | 7 +++++++ book/cli/reth/p2p.md | 7 +++++++ book/cli/reth/stage/run.md | 7 +++++++ book/cli/reth/stage/unwind.md | 7 +++++++ crates/net/network/src/transactions/config.rs | 14 ++++++++++++- .../net/network/src/transactions/constants.rs | 2 +- crates/net/network/src/transactions/mod.rs | 21 ++++++++++++++++--- crates/node/core/src/args/network.rs | 9 ++++++++ 12 files changed, 97 insertions(+), 5 deletions(-) diff --git a/book/cli/reth/debug/execution.md b/book/cli/reth/debug/execution.md index 55095499f..fed6f2cb8 100644 --- a/book/cli/reth/debug/execution.md +++ b/book/cli/reth/debug/execution.md @@ -177,6 +177,13 @@ Networking: --max-inbound-peers Maximum number of inbound requests. default: 30 + --max-seen-tx-history + Max number of seen transactions to remember per peer. + + Default is 320 transaction hashes. + + [default: 320] + --pooled-tx-response-soft-limit Experimental, for usage in research. Sets the max accumulated byte size of transactions to pack in one response. diff --git a/book/cli/reth/debug/in-memory-merkle.md b/book/cli/reth/debug/in-memory-merkle.md index 476499f12..044ce7b09 100644 --- a/book/cli/reth/debug/in-memory-merkle.md +++ b/book/cli/reth/debug/in-memory-merkle.md @@ -177,6 +177,13 @@ Networking: --max-inbound-peers Maximum number of inbound requests. default: 30 + --max-seen-tx-history + Max number of seen transactions to remember per peer. + + Default is 320 transaction hashes. + + [default: 320] + --pooled-tx-response-soft-limit Experimental, for usage in research. Sets the max accumulated byte size of transactions to pack in one response. diff --git a/book/cli/reth/debug/merkle.md b/book/cli/reth/debug/merkle.md index 4f4839212..7ea6835eb 100644 --- a/book/cli/reth/debug/merkle.md +++ b/book/cli/reth/debug/merkle.md @@ -177,6 +177,13 @@ Networking: --max-inbound-peers Maximum number of inbound requests. default: 30 + --max-seen-tx-history + Max number of seen transactions to remember per peer. + + Default is 320 transaction hashes. + + [default: 320] + --pooled-tx-response-soft-limit Experimental, for usage in research. Sets the max accumulated byte size of transactions to pack in one response. diff --git a/book/cli/reth/debug/replay-engine.md b/book/cli/reth/debug/replay-engine.md index bbd04272f..aec120e8d 100644 --- a/book/cli/reth/debug/replay-engine.md +++ b/book/cli/reth/debug/replay-engine.md @@ -177,6 +177,13 @@ Networking: --max-inbound-peers Maximum number of inbound requests. default: 30 + --max-seen-tx-history + Max number of seen transactions to remember per peer. + + Default is 320 transaction hashes. + + [default: 320] + --pooled-tx-response-soft-limit Experimental, for usage in research. Sets the max accumulated byte size of transactions to pack in one response. diff --git a/book/cli/reth/node.md b/book/cli/reth/node.md index 5bcf9d14d..1bc5c1ff2 100644 --- a/book/cli/reth/node.md +++ b/book/cli/reth/node.md @@ -169,6 +169,13 @@ Networking: --max-inbound-peers Maximum number of inbound requests. default: 30 + --max-seen-tx-history + Max number of seen transactions to remember per peer. + + Default is 320 transaction hashes. + + [default: 320] + --pooled-tx-response-soft-limit Experimental, for usage in research. Sets the max accumulated byte size of transactions to pack in one response. diff --git a/book/cli/reth/p2p.md b/book/cli/reth/p2p.md index 1b031049f..24091f57d 100644 --- a/book/cli/reth/p2p.md +++ b/book/cli/reth/p2p.md @@ -154,6 +154,13 @@ Networking: --max-inbound-peers Maximum number of inbound requests. default: 30 + --max-seen-tx-history + Max number of seen transactions to remember per peer. + + Default is 320 transaction hashes. + + [default: 320] + --pooled-tx-response-soft-limit Experimental, for usage in research. Sets the max accumulated byte size of transactions to pack in one response. diff --git a/book/cli/reth/stage/run.md b/book/cli/reth/stage/run.md index 3a1afc949..06bb16a9b 100644 --- a/book/cli/reth/stage/run.md +++ b/book/cli/reth/stage/run.md @@ -220,6 +220,13 @@ Networking: --max-inbound-peers Maximum number of inbound requests. default: 30 + --max-seen-tx-history + Max number of seen transactions to remember per peer. + + Default is 320 transaction hashes. + + [default: 320] + --pooled-tx-response-soft-limit Experimental, for usage in research. Sets the max accumulated byte size of transactions to pack in one response. diff --git a/book/cli/reth/stage/unwind.md b/book/cli/reth/stage/unwind.md index f141275c4..1544d271f 100644 --- a/book/cli/reth/stage/unwind.md +++ b/book/cli/reth/stage/unwind.md @@ -182,6 +182,13 @@ Networking: --max-inbound-peers Maximum number of inbound requests. default: 30 + --max-seen-tx-history + Max number of seen transactions to remember per peer. + + Default is 320 transaction hashes. + + [default: 320] + --pooled-tx-response-soft-limit Experimental, for usage in research. Sets the max accumulated byte size of transactions to pack in one response. diff --git a/crates/net/network/src/transactions/config.rs b/crates/net/network/src/transactions/config.rs index 083aefa8a..5d9455b6e 100644 --- a/crates/net/network/src/transactions/config.rs +++ b/crates/net/network/src/transactions/config.rs @@ -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. diff --git a/crates/net/network/src/transactions/constants.rs b/crates/net/network/src/transactions/constants.rs index 929087295..7eef8165c 100644 --- a/crates/net/network/src/transactions/constants.rs +++ b/crates/net/network/src/transactions/constants.rs @@ -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. diff --git a/crates/net/network/src/transactions/mod.rs b/crates/net/network/src/transactions/mod.rs index 1ad0ab0be..9e6bd4efc 100644 --- a/crates/net/network/src/transactions/mod.rs +++ b/crates/net/network/src/transactions/mod.rs @@ -245,6 +245,8 @@ pub struct TransactionsManager { pending_transactions: ReceiverStream, /// Incoming events from the [`NetworkManager`](crate::NetworkManager). transaction_events: UnboundedMeteredReceiver, + /// 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 TransactionsManager { 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) -> Self { + fn new( + request_tx: PeerRequestSender, + version: EthVersion, + client_version: Arc, + 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, ) diff --git a/crates/node/core/src/args/network.rs b/crates/node/core/src/args/network.rs index f1d223a92..bcd8fab7c 100644 --- a/crates/node/core/src/args/network.rs +++ b/crates/node/core/src/args/network.rs @@ -12,6 +12,7 @@ use reth_discv5::{ use reth_net_nat::NatResolver; use reth_network::{ transactions::{ + constants::tx_manager::DEFAULT_MAX_COUNT_TRANSACTIONS_SEEN_BY_PEER, TransactionFetcherConfig, TransactionsManagerConfig, DEFAULT_SOFT_LIMIT_BYTE_SIZE_POOLED_TRANSACTIONS_RESP_ON_PACK_GET_POOLED_TRANSACTIONS_REQ, SOFT_LIMIT_BYTE_SIZE_POOLED_TRANSACTIONS_RESPONSE, @@ -96,6 +97,12 @@ pub struct NetworkArgs { #[arg(long)] pub max_inbound_peers: Option, + /// Max number of seen transactions to remember per peer. + /// + /// Default is 320 transaction hashes. + #[arg(long = "max-seen-tx-history", value_name = "MAX_SEEN_TX_HISTORY", default_value_t = DEFAULT_MAX_COUNT_TRANSACTIONS_SEEN_BY_PEER, verbatim_doc_comment)] + pub max_seen_tx_history: u32, + /// Experimental, for usage in research. Sets the max accumulated byte size of transactions /// to pack in one response. /// Spec'd at 2MiB. @@ -161,6 +168,7 @@ impl NetworkArgs { self.soft_limit_byte_size_pooled_transactions_response, self.soft_limit_byte_size_pooled_transactions_response_on_pack_request, ), + max_transactions_seen_by_peer_history: self.max_seen_tx_history, }; // Configure basic network stack @@ -261,6 +269,7 @@ impl Default for NetworkArgs { soft_limit_byte_size_pooled_transactions_response: SOFT_LIMIT_BYTE_SIZE_POOLED_TRANSACTIONS_RESPONSE, soft_limit_byte_size_pooled_transactions_response_on_pack_request: DEFAULT_SOFT_LIMIT_BYTE_SIZE_POOLED_TRANSACTIONS_RESP_ON_PACK_GET_POOLED_TRANSACTIONS_REQ, + max_seen_tx_history: DEFAULT_MAX_COUNT_TRANSACTIONS_SEEN_BY_PEER, } } }