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 maximum encoded byte size of pending pool imports to tolerate, including blob
47    /// sidecars.
48    ///
49    /// Default is 256 MiB, which holds about 320 transactions carrying six blobs each.
50    pub const DEFAULT_MAX_BYTE_SIZE_PENDING_POOL_IMPORTS: usize = 256 * 1024 * 1024;
51
52    /// Default limit for number of bad imports to keep track of.
53    ///
54    /// Default is 100 KiB, i.e. 3 200 transaction hashes.
55    pub const DEFAULT_MAX_COUNT_BAD_IMPORTS: u32 = 100 * 1024 / 32;
56
57    /// Default memory limit (in bytes) for the channel between
58    /// [`NetworkManager`](crate::NetworkManager) and
59    /// [`TransactionsManager`](crate::transactions::TransactionsManager).
60    ///
61    /// Caps the total in-flight bytes of `NetworkTransactionEvent`s buffered between the two
62    /// tasks. When the budget is exhausted, new events are dropped (see metric
63    /// `total_dropped_tx_events_at_full_capacity`).
64    pub const DEFAULT_TX_MANAGER_CHANNEL_MEMORY_LIMIT_BYTES: usize = 1024 * 1024 * 1024;
65}
66
67/// Constants used by [`TransactionFetcher`](super::TransactionFetcher).
68pub mod tx_fetcher {
69    use super::{
70        SOFT_LIMIT_BYTE_SIZE_POOLED_TRANSACTIONS_RESPONSE,
71        SOFT_LIMIT_COUNT_HASHES_IN_GET_POOLED_TRANSACTIONS_REQUEST,
72        SOFT_LIMIT_COUNT_HASHES_IN_NEW_POOLED_TRANSACTIONS_BROADCAST_MESSAGE,
73    };
74    use reth_network_types::peers::config::{
75        DEFAULT_MAX_COUNT_PEERS_INBOUND, DEFAULT_MAX_COUNT_PEERS_OUTBOUND,
76    };
77
78    /// Default soft limit for the byte size of the expected
79    /// [`PooledTransactions`](reth_eth_wire::PooledTransactions) response when packing a
80    /// [`GetPooledTransactions`](reth_eth_wire::GetPooledTransactions) request. This is much
81    /// smaller than the 2 MiB [`SOFT_LIMIT_BYTE_SIZE_POOLED_TRANSACTIONS_RESPONSE`] applied when
82    /// assembling a response, so that a single request fetches at most about one blob transaction
83    /// and doesn't hog the connection to a peer.
84    ///
85    /// Default is 128 KiB.
86    pub const DEFAULT_SOFT_LIMIT_BYTE_SIZE_POOLED_TRANSACTIONS_RESP_ON_PACK_GET_POOLED_TRANSACTIONS_REQ: usize = 128 * 1024;
87
88    /// Default maximum number of concurrent
89    /// [`GetPooledTransactions`](reth_eth_wire::GetPooledTransactions) requests.
90    ///
91    /// Default is the sum of [`DEFAULT_MAX_COUNT_PEERS_INBOUND`] and
92    /// [`DEFAULT_MAX_COUNT_PEERS_OUTBOUND`], which default to 30 and 100 peers respectively, so
93    /// 130 requests.
94    pub const DEFAULT_MAX_COUNT_CONCURRENT_REQUESTS: u32 =
95        DEFAULT_MAX_COUNT_PEERS_INBOUND + DEFAULT_MAX_COUNT_PEERS_OUTBOUND;
96
97    /// Default maximum number of concurrent
98    /// [`GetPooledTransactions`](reth_eth_wire::GetPooledTransactions) requests per peer.
99    ///
100    /// Default is 1 request. With a single request at a time, the hashes a peer failed to deliver
101    /// are known as soon as its response arrives and can be rescheduled immediately.
102    pub const DEFAULT_MAX_COUNT_CONCURRENT_REQUESTS_PER_PEER: u8 = 1;
103
104    /// Default maximum number of announced transaction hashes to keep track of, pending and
105    /// inflight. Once reached, the peer tracking the most hashes gives up its oldest pending
106    /// hash for a newly announced one.
107    ///
108    /// Default is 100 times the [`SOFT_LIMIT_COUNT_HASHES_IN_GET_POOLED_TRANSACTIONS_REQUEST`],
109    /// which is 256 hashes, so 25 600 hashes.
110    pub const DEFAULT_MAX_CAPACITY_CACHE_PENDING_FETCH: u32 =
111        100 * SOFT_LIMIT_COUNT_HASHES_IN_GET_POOLED_TRANSACTIONS_REQUEST as u32;
112
113    /// Default maximum number of tracked hashes a single peer can be a candidate for. Bounds the
114    /// memory a single peer can occupy in the fetcher with its announcements.
115    ///
116    /// Default is one full announcement,
117    /// [`SOFT_LIMIT_COUNT_HASHES_IN_NEW_POOLED_TRANSACTIONS_BROADCAST_MESSAGE`], so 4096 hashes.
118    pub const DEFAULT_MAX_COUNT_ANNOUNCED_HASHES_PER_PEER: u32 =
119        SOFT_LIMIT_COUNT_HASHES_IN_NEW_POOLED_TRANSACTIONS_BROADCAST_MESSAGE as u32;
120
121    /// Maximum number of peers remembered as candidates for a single hash. The first eager
122    /// sources are retained while later announcements replace the oldest fallback sources.
123    ///
124    /// Default is 8 peers.
125    pub const MAX_COUNT_CANDIDATE_PEERS_PER_HASH: usize = 8;
126
127    /// Maximum fetch attempts for a single hash, independent of candidate storage capacity.
128    pub const MAX_FETCH_ATTEMPTS_PER_HASH: usize = 16;
129
130    /// Number of candidates a hash is queued for right away. The remaining candidates only get
131    /// the hash queued once one of these failed to deliver it, which keeps late announcements
132    /// cheap while a hash is not given up on when its first announcers fail.
133    ///
134    /// Default is half of [`MAX_COUNT_CANDIDATE_PEERS_PER_HASH`], so 4 peers.
135    pub const MAX_COUNT_EAGER_CANDIDATE_PEERS_PER_HASH: usize =
136        MAX_COUNT_CANDIDATE_PEERS_PER_HASH / 2;
137
138    /// Assumed byte size of a transaction whose size wasn't announced, used when packing
139    /// requests.
140    ///
141    /// Default is [`SOFT_LIMIT_BYTE_SIZE_POOLED_TRANSACTIONS_RESPONSE`], which defaults to 2 MiB,
142    /// divided by [`SOFT_LIMIT_COUNT_HASHES_IN_NEW_POOLED_TRANSACTIONS_BROADCAST_MESSAGE`], which
143    /// is spec'd at 4096 hashes, so 512 bytes.
144    pub const AVERAGE_BYTE_SIZE_TX_ENCODED: usize =
145        SOFT_LIMIT_BYTE_SIZE_POOLED_TRANSACTIONS_RESPONSE /
146            SOFT_LIMIT_COUNT_HASHES_IN_NEW_POOLED_TRANSACTIONS_BROADCAST_MESSAGE;
147}