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