Skip to main content

reth_network/transactions/
constants.rs

1/* ==================== BROADCAST ==================== */
2
3pub use reth_eth_wire_types::SOFT_LIMIT_COUNT_HASHES_IN_NEW_POOLED_TRANSACTIONS_BROADCAST_MESSAGE;
4
5/// Default soft limit for the byte size of a [`Transactions`](reth_eth_wire::Transactions)
6/// broadcast message.
7///
8/// Default is 128 KiB.
9pub const DEFAULT_SOFT_LIMIT_BYTE_SIZE_TRANSACTIONS_BROADCAST_MESSAGE: usize = 128 * 1024;
10
11/* ================ REQUEST-RESPONSE ================ */
12
13/// Recommended soft limit for the number of hashes in a
14/// [`GetPooledTransactions`](reth_eth_wire::GetPooledTransactions) request.
15///
16/// Spec'd at 256 hashes (8 KiB).
17///
18/// <https://github.com/ethereum/devp2p/blob/master/caps/eth.md#getpooledtransactions-0x09>
19pub const SOFT_LIMIT_COUNT_HASHES_IN_GET_POOLED_TRANSACTIONS_REQUEST: usize = 256;
20
21/// Soft limit for the byte size of a [`PooledTransactions`](reth_eth_wire::PooledTransactions)
22/// response on assembling a [`GetPooledTransactions`](reth_eth_wire::GetPooledTransactions)
23/// request.
24///
25/// Spec'd at 2 MiB.
26///
27/// <https://github.com/ethereum/devp2p/blob/master/caps/eth.md#protocol-messages>.
28pub const SOFT_LIMIT_BYTE_SIZE_POOLED_TRANSACTIONS_RESPONSE: usize = 2 * 1024 * 1024;
29
30/// Constants used by [`TransactionsManager`](super::TransactionsManager).
31pub mod tx_manager {
32    use super::SOFT_LIMIT_COUNT_HASHES_IN_NEW_POOLED_TRANSACTIONS_BROADCAST_MESSAGE;
33
34    /// Default limit for number of transactions to keep track of for a single peer.
35    ///
36    /// Default is 320 transaction hashes.
37    pub const DEFAULT_MAX_COUNT_TRANSACTIONS_SEEN_BY_PEER: u32 = 10 * 1024 / 32;
38
39    /// Default maximum pending pool imports to tolerate.
40    ///
41    /// Default is equivalent to the number of hashes in one full announcement, which is spec'd at
42    /// 4096 hashes, so 4096 pending pool imports.
43    pub const DEFAULT_MAX_COUNT_PENDING_POOL_IMPORTS: usize =
44        SOFT_LIMIT_COUNT_HASHES_IN_NEW_POOLED_TRANSACTIONS_BROADCAST_MESSAGE;
45
46    /// Default limit for number of bad imports to keep track of.
47    ///
48    /// Default is 100 KiB, i.e. 3 200 transaction hashes.
49    pub const DEFAULT_MAX_COUNT_BAD_IMPORTS: u32 = 100 * 1024 / 32;
50
51    /// Default memory limit (in bytes) for the channel between
52    /// [`NetworkManager`](crate::NetworkManager) and
53    /// [`TransactionsManager`](crate::transactions::TransactionsManager).
54    ///
55    /// Caps the total in-flight bytes of `NetworkTransactionEvent`s buffered between the two
56    /// tasks. When the budget is exhausted, new events are dropped (see metric
57    /// `total_dropped_tx_events_at_full_capacity`).
58    pub const DEFAULT_TX_MANAGER_CHANNEL_MEMORY_LIMIT_BYTES: usize = 1024 * 1024 * 1024;
59}
60
61/// Constants used by [`TransactionFetcher`](super::TransactionFetcher).
62pub mod tx_fetcher {
63    use super::{
64        SOFT_LIMIT_BYTE_SIZE_POOLED_TRANSACTIONS_RESPONSE,
65        SOFT_LIMIT_COUNT_HASHES_IN_GET_POOLED_TRANSACTIONS_REQUEST,
66        SOFT_LIMIT_COUNT_HASHES_IN_NEW_POOLED_TRANSACTIONS_BROADCAST_MESSAGE,
67    };
68    use reth_network_types::peers::config::{
69        DEFAULT_MAX_COUNT_PEERS_INBOUND, DEFAULT_MAX_COUNT_PEERS_OUTBOUND,
70    };
71
72    /// Default soft limit for the byte size of the expected
73    /// [`PooledTransactions`](reth_eth_wire::PooledTransactions) response when packing a
74    /// [`GetPooledTransactions`](reth_eth_wire::GetPooledTransactions) request. This is much
75    /// smaller than the 2 MiB [`SOFT_LIMIT_BYTE_SIZE_POOLED_TRANSACTIONS_RESPONSE`] applied when
76    /// assembling a response, so that a single request fetches at most about one blob transaction
77    /// and doesn't hog the connection to a peer.
78    ///
79    /// Default is 128 KiB.
80    pub const DEFAULT_SOFT_LIMIT_BYTE_SIZE_POOLED_TRANSACTIONS_RESP_ON_PACK_GET_POOLED_TRANSACTIONS_REQ: usize = 128 * 1024;
81
82    /// Default maximum number of concurrent
83    /// [`GetPooledTransactions`](reth_eth_wire::GetPooledTransactions) requests.
84    ///
85    /// Default is the sum of [`DEFAULT_MAX_COUNT_PEERS_INBOUND`] and
86    /// [`DEFAULT_MAX_COUNT_PEERS_OUTBOUND`], which default to 30 and 100 peers respectively, so
87    /// 130 requests.
88    pub const DEFAULT_MAX_COUNT_CONCURRENT_REQUESTS: u32 =
89        DEFAULT_MAX_COUNT_PEERS_INBOUND + DEFAULT_MAX_COUNT_PEERS_OUTBOUND;
90
91    /// Default maximum number of concurrent
92    /// [`GetPooledTransactions`](reth_eth_wire::GetPooledTransactions) requests per peer.
93    ///
94    /// Default is 1 request. With a single request at a time, the hashes a peer failed to deliver
95    /// are known as soon as its response arrives and can be rescheduled immediately.
96    pub const DEFAULT_MAX_COUNT_CONCURRENT_REQUESTS_PER_PEER: u8 = 1;
97
98    /// Default maximum number of announced transaction hashes to keep track of, pending and
99    /// inflight. Once reached, the peer tracking the most hashes gives up its oldest pending
100    /// hash for a newly announced one.
101    ///
102    /// Default is 100 times the [`SOFT_LIMIT_COUNT_HASHES_IN_GET_POOLED_TRANSACTIONS_REQUEST`],
103    /// which is 256 hashes, so 25 600 hashes.
104    pub const DEFAULT_MAX_CAPACITY_CACHE_PENDING_FETCH: u32 =
105        100 * SOFT_LIMIT_COUNT_HASHES_IN_GET_POOLED_TRANSACTIONS_REQUEST as u32;
106
107    /// Default maximum number of tracked hashes a single peer can be a candidate for. Bounds the
108    /// memory a single peer can occupy in the fetcher with its announcements.
109    ///
110    /// Default is one full announcement,
111    /// [`SOFT_LIMIT_COUNT_HASHES_IN_NEW_POOLED_TRANSACTIONS_BROADCAST_MESSAGE`], so 4096 hashes.
112    pub const DEFAULT_MAX_COUNT_ANNOUNCED_HASHES_PER_PEER: u32 =
113        SOFT_LIMIT_COUNT_HASHES_IN_NEW_POOLED_TRANSACTIONS_BROADCAST_MESSAGE as u32;
114
115    /// Maximum number of peers remembered as candidates for a single hash. The first eager
116    /// sources are retained while later announcements replace the oldest fallback sources.
117    ///
118    /// Default is 8 peers.
119    pub const MAX_COUNT_CANDIDATE_PEERS_PER_HASH: usize = 8;
120
121    /// Maximum fetch attempts for a single hash, independent of candidate storage capacity.
122    pub const MAX_FETCH_ATTEMPTS_PER_HASH: usize = 16;
123
124    /// Number of candidates a hash is queued for right away. The remaining candidates only get
125    /// the hash queued once one of these failed to deliver it, which keeps late announcements
126    /// cheap while a hash is not given up on when its first announcers fail.
127    ///
128    /// Default is half of [`MAX_COUNT_CANDIDATE_PEERS_PER_HASH`], so 4 peers.
129    pub const MAX_COUNT_EAGER_CANDIDATE_PEERS_PER_HASH: usize =
130        MAX_COUNT_CANDIDATE_PEERS_PER_HASH / 2;
131
132    /// Assumed byte size of a transaction whose size wasn't announced, used when packing
133    /// requests.
134    ///
135    /// Default is [`SOFT_LIMIT_BYTE_SIZE_POOLED_TRANSACTIONS_RESPONSE`], which defaults to 2 MiB,
136    /// divided by [`SOFT_LIMIT_COUNT_HASHES_IN_NEW_POOLED_TRANSACTIONS_BROADCAST_MESSAGE`], which
137    /// is spec'd at 4096 hashes, so 512 bytes.
138    pub const AVERAGE_BYTE_SIZE_TX_ENCODED: usize =
139        SOFT_LIMIT_BYTE_SIZE_POOLED_TRANSACTIONS_RESPONSE /
140            SOFT_LIMIT_COUNT_HASHES_IN_NEW_POOLED_TRANSACTIONS_BROADCAST_MESSAGE;
141}