Skip to content

Commit

Permalink
Fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
emhane committed Aug 17, 2024
1 parent d4acf69 commit c23c67a
Show file tree
Hide file tree
Showing 12 changed files with 135 additions and 23 deletions.
10 changes: 10 additions & 0 deletions book/cli/reth/debug/execution.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,16 @@ Networking:
--max-inbound-peers <MAX_INBOUND_PEERS>
Maximum number of inbound requests. default: 30
--max-tx-reqs <MAX_TX_REQS>
Max concurrent `GetPooledTransactions` requests.
[default: 130]
--max-tx-reqs-peer <MAX_TX_REQS_PEER>
Max concurrent `GetPooledTransactions` requests per peer.
[default: 1]
--pooled-tx-response-soft-limit <BYTES>
Experimental, for usage in research. Sets the max accumulated byte size of transactions
to pack in one response.
Expand Down
10 changes: 10 additions & 0 deletions book/cli/reth/debug/in-memory-merkle.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,16 @@ Networking:
--max-inbound-peers <MAX_INBOUND_PEERS>
Maximum number of inbound requests. default: 30
--max-tx-reqs <MAX_TX_REQS>
Max concurrent `GetPooledTransactions` requests.
[default: 130]
--max-tx-reqs-peer <MAX_TX_REQS_PEER>
Max concurrent `GetPooledTransactions` requests per peer.
[default: 1]
--pooled-tx-response-soft-limit <BYTES>
Experimental, for usage in research. Sets the max accumulated byte size of transactions
to pack in one response.
Expand Down
10 changes: 10 additions & 0 deletions book/cli/reth/debug/merkle.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,16 @@ Networking:
--max-inbound-peers <MAX_INBOUND_PEERS>
Maximum number of inbound requests. default: 30
--max-tx-reqs <MAX_TX_REQS>
Max concurrent `GetPooledTransactions` requests.
[default: 130]
--max-tx-reqs-peer <MAX_TX_REQS_PEER>
Max concurrent `GetPooledTransactions` requests per peer.
[default: 1]
--pooled-tx-response-soft-limit <BYTES>
Experimental, for usage in research. Sets the max accumulated byte size of transactions
to pack in one response.
Expand Down
10 changes: 10 additions & 0 deletions book/cli/reth/debug/replay-engine.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,16 @@ Networking:
--max-inbound-peers <MAX_INBOUND_PEERS>
Maximum number of inbound requests. default: 30
--max-tx-reqs <MAX_TX_REQS>
Max concurrent `GetPooledTransactions` requests.
[default: 130]
--max-tx-reqs-peer <MAX_TX_REQS_PEER>
Max concurrent `GetPooledTransactions` requests per peer.
[default: 1]
--pooled-tx-response-soft-limit <BYTES>
Experimental, for usage in research. Sets the max accumulated byte size of transactions
to pack in one response.
Expand Down
10 changes: 10 additions & 0 deletions book/cli/reth/node.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,16 @@ Networking:
--max-inbound-peers <MAX_INBOUND_PEERS>
Maximum number of inbound requests. default: 30
--max-tx-reqs <MAX_TX_REQS>
Max concurrent `GetPooledTransactions` requests.
[default: 130]
--max-tx-reqs-peer <MAX_TX_REQS_PEER>
Max concurrent `GetPooledTransactions` requests per peer.
[default: 1]
--pooled-tx-response-soft-limit <BYTES>
Experimental, for usage in research. Sets the max accumulated byte size of transactions
to pack in one response.
Expand Down
10 changes: 10 additions & 0 deletions book/cli/reth/p2p.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,16 @@ Networking:
--max-inbound-peers <MAX_INBOUND_PEERS>
Maximum number of inbound requests. default: 30
--max-tx-reqs <MAX_TX_REQS>
Max concurrent `GetPooledTransactions` requests.
[default: 130]
--max-tx-reqs-peer <MAX_TX_REQS_PEER>
Max concurrent `GetPooledTransactions` requests per peer.
[default: 1]
--pooled-tx-response-soft-limit <BYTES>
Experimental, for usage in research. Sets the max accumulated byte size of transactions
to pack in one response.
Expand Down
10 changes: 10 additions & 0 deletions book/cli/reth/stage/run.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,16 @@ Networking:
--max-inbound-peers <MAX_INBOUND_PEERS>
Maximum number of inbound requests. default: 30

--max-tx-reqs <MAX_TX_REQS>
Max concurrent `GetPooledTransactions` requests.

[default: 130]

--max-tx-reqs-peer <MAX_TX_REQS_PEER>
Max concurrent `GetPooledTransactions` requests per peer.

[default: 1]

--pooled-tx-response-soft-limit <BYTES>
Experimental, for usage in research. Sets the max accumulated byte size of transactions
to pack in one response.
Expand Down
10 changes: 10 additions & 0 deletions book/cli/reth/stage/unwind.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,16 @@ Networking:
--max-inbound-peers <MAX_INBOUND_PEERS>
Maximum number of inbound requests. default: 30
--max-tx-reqs <MAX_TX_REQS>
Max concurrent `GetPooledTransactions` requests.
[default: 130]
--max-tx-reqs-peer <MAX_TX_REQS_PEER>
Max concurrent `GetPooledTransactions` requests per peer.
[default: 1]
--pooled-tx-response-soft-limit <BYTES>
Experimental, for usage in research. Sets the max accumulated byte size of transactions
to pack in one response.
Expand Down
2 changes: 1 addition & 1 deletion book/developers/exex/hello-world.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ use reth_exex::{ExExContext, ExExEvent, ExExNotification};
use reth_node_ethereum::EthereumNode;
use reth_tracing::tracing::info;
async fn my_exex<Node: FullNodeComponents>(mut _ctx: ExExContext<Node>) -> eyre::Result<()> {
async fn my_exex<Node: FullNodeComponents>(mut ctx: ExExContext<Node>) -> eyre::Result<()> {
loop {}
}
Expand Down
16 changes: 15 additions & 1 deletion crates/net/network/src/transactions/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ use super::{
DEFAULT_SOFT_LIMIT_BYTE_SIZE_POOLED_TRANSACTIONS_RESP_ON_PACK_GET_POOLED_TRANSACTIONS_REQ,
SOFT_LIMIT_BYTE_SIZE_POOLED_TRANSACTIONS_RESPONSE,
};
use crate::transactions::constants::tx_fetcher::{
DEFAULT_MAX_COUNT_CONCURRENT_REQUESTS, DEFAULT_MAX_COUNT_CONCURRENT_REQUESTS_PER_PEER,
};

/// Configuration for managing transactions within the network.
#[derive(Debug, Default, Clone)]
Expand All @@ -17,6 +20,11 @@ pub struct TransactionsManagerConfig {
#[derive(Debug, Constructor, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct TransactionFetcherConfig {
/// Max inflight [`GetPooledTransactions`](reth_eth_wire::GetPooledTransactions) requests.
pub max_inflight_requests: u32,
/// Max inflight [`GetPooledTransactions`](reth_eth_wire::GetPooledTransactions) requests per
/// peer.
pub max_inflight_requests_per_peer: u8,
/// Soft limit for the byte size of a
/// [`PooledTransactions`](reth_eth_wire::PooledTransactions) response on assembling a
/// [`GetPooledTransactions`](reth_eth_wire::GetPooledTransactions) request. Spec'd at 2
Expand All @@ -30,7 +38,13 @@ pub struct TransactionFetcherConfig {

impl Default for TransactionFetcherConfig {
fn default() -> Self {
Self { 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
Self {
max_inflight_requests: DEFAULT_MAX_COUNT_CONCURRENT_REQUESTS,
max_inflight_requests_per_peer: DEFAULT_MAX_COUNT_CONCURRENT_REQUESTS_PER_PEER,
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
}
}
}
29 changes: 15 additions & 14 deletions crates/net/network/src/transactions/fetcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ impl TransactionFetcher {
config.soft_limit_byte_size_pooled_transactions_response;
tx_fetcher.info.soft_limit_byte_size_pooled_transactions_response_on_pack_request =
config.soft_limit_byte_size_pooled_transactions_response_on_pack_request;
tx_fetcher.info.max_inflight_requests_per_peer = config.max_inflight_requests_per_peer;
tx_fetcher.info.max_inflight_requests = config.max_inflight_requests as usize;
tx_fetcher
.metrics
.capacity_inflight_requests
Expand Down Expand Up @@ -170,7 +172,7 @@ impl TransactionFetcher {
/// Returns `true` if peer is idle with respect to `self.inflight_requests`.
pub fn is_idle(&self, peer_id: &PeerId) -> bool {
let Some(inflight_count) = self.active_peers.peek(peer_id) else { return true };
if *inflight_count < DEFAULT_MAX_COUNT_CONCURRENT_REQUESTS_PER_PEER {
if *inflight_count < self.info.max_inflight_requests_per_peer {
return true
}
false
Expand All @@ -185,13 +187,7 @@ impl TransactionFetcher {
let TxFetchMetadata { fallback_peers, .. } =
self.hashes_fetch_inflight_and_pending_fetch.peek(&hash)?;

for peer_id in fallback_peers.iter() {
if self.is_idle(peer_id) && is_session_active(peer_id) {
return Some(peer_id)
}
}

None
fallback_peers.iter().find(|&peer_id| self.is_idle(peer_id) && is_session_active(peer_id))
}

/// Returns any idle peer for any hash pending fetch. If one is found, the corresponding
Expand All @@ -214,7 +210,7 @@ impl TransactionFetcher {

if idle_peer.is_some() {
hashes_to_request.insert(hash);
break idle_peer.copied()
break idle_peer.copied();
}

if let Some(ref mut bud) = budget {
Expand Down Expand Up @@ -309,7 +305,7 @@ impl TransactionFetcher {
acc_size_response;

if free_space < MEDIAN_BYTE_SIZE_SMALL_LEGACY_TX_ENCODED {
break
break;
}
}

Expand Down Expand Up @@ -691,7 +687,7 @@ impl TransactionFetcher {
self.metrics.egress_peer_channel_full.increment(1);
Some(new_announced_hashes)
}
}
};
} else {
// stores a new request future for the request
self.inflight_requests.push(GetPooledTxRequestFut::new(
Expand Down Expand Up @@ -1290,6 +1286,8 @@ pub enum VerificationOutcome {
pub struct TransactionFetcherInfo {
/// Max inflight [`GetPooledTransactions`] requests.
pub max_inflight_requests: usize,
/// Max inflight [`GetPooledTransactions`] requests per peer.
pub max_inflight_requests_per_peer: u8,
/// Soft limit for the byte size of the expected [`PooledTransactions`] response, upon packing
/// a [`GetPooledTransactions`] request with hashes (by default less than 2 MiB worth of
/// transactions is requested).
Expand All @@ -1302,12 +1300,14 @@ pub struct TransactionFetcherInfo {
impl TransactionFetcherInfo {
/// Creates a new max
pub const fn new(
max_inflight_requests: usize,
max_inflight_requests: u32,
max_inflight_requests_per_peer: u8,
soft_limit_byte_size_pooled_transactions_response_on_pack_request: usize,
soft_limit_byte_size_pooled_transactions_response: usize,
) -> Self {
Self {
max_inflight_requests,
max_inflight_requests: max_inflight_requests as usize,
max_inflight_requests_per_peer,
soft_limit_byte_size_pooled_transactions_response_on_pack_request,
soft_limit_byte_size_pooled_transactions_response,
}
Expand All @@ -1317,7 +1317,8 @@ impl TransactionFetcherInfo {
impl Default for TransactionFetcherInfo {
fn default() -> Self {
Self::new(
DEFAULT_MAX_COUNT_CONCURRENT_REQUESTS as usize * DEFAULT_MAX_COUNT_CONCURRENT_REQUESTS_PER_PEER as usize,
DEFAULT_MAX_COUNT_CONCURRENT_REQUESTS,
DEFAULT_MAX_COUNT_CONCURRENT_REQUESTS_PER_PEER,
DEFAULT_SOFT_LIMIT_BYTE_SIZE_POOLED_TRANSACTIONS_RESP_ON_PACK_GET_POOLED_TRANSACTIONS_REQ,
SOFT_LIMIT_BYTE_SIZE_POOLED_TRANSACTIONS_RESPONSE
)
Expand Down
31 changes: 24 additions & 7 deletions crates/node/core/src/args/network.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
//! clap [Args](clap::Args) for network related arguments.

use crate::version::P2P_CLIENT_VERSION;
use std::{
net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6},
ops::Not,
path::PathBuf,
sync::Arc,
};

use clap::Args;
use reth_chainspec::ChainSpec;
use reth_config::Config;
Expand All @@ -12,6 +18,9 @@ use reth_discv5::{
use reth_net_nat::NatResolver;
use reth_network::{
transactions::{
constants::tx_fetcher::{
DEFAULT_MAX_COUNT_CONCURRENT_REQUESTS, DEFAULT_MAX_COUNT_CONCURRENT_REQUESTS_PER_PEER,
},
TransactionFetcherConfig, TransactionsManagerConfig,
DEFAULT_SOFT_LIMIT_BYTE_SIZE_POOLED_TRANSACTIONS_RESP_ON_PACK_GET_POOLED_TRANSACTIONS_REQ,
SOFT_LIMIT_BYTE_SIZE_POOLED_TRANSACTIONS_RESPONSE,
Expand All @@ -20,12 +29,8 @@ use reth_network::{
};
use reth_network_peers::{mainnet_nodes, TrustedPeer};
use secp256k1::SecretKey;
use std::{
net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6},
ops::Not,
path::PathBuf,
sync::Arc,
};

use crate::version::P2P_CLIENT_VERSION;

/// Parameters for configuring the network more granularity via CLI
#[derive(Debug, Clone, Args, PartialEq, Eq)]
Expand Down Expand Up @@ -96,6 +101,14 @@ pub struct NetworkArgs {
#[arg(long)]
pub max_inbound_peers: Option<usize>,

/// Max concurrent `GetPooledTransactions` requests.
#[arg(long = "max-tx-reqs", value_name = "MAX_TX_REQS", default_value_t = DEFAULT_MAX_COUNT_CONCURRENT_REQUESTS, verbatim_doc_comment)]
pub max_concurrent_tx_requests: u32,

/// Max concurrent `GetPooledTransactions` requests per peer.
#[arg(long = "max-tx-reqs-peer", value_name = "MAX_TX_REQS_PEER", default_value_t = DEFAULT_MAX_COUNT_CONCURRENT_REQUESTS_PER_PEER, verbatim_doc_comment)]
pub max_concurrent_tx_requests_per_peer: u8,

/// Experimental, for usage in research. Sets the max accumulated byte size of transactions
/// to pack in one response.
/// Spec'd at 2MiB.
Expand Down Expand Up @@ -158,6 +171,8 @@ impl NetworkArgs {
// Configure transactions manager
let transactions_manager_config = TransactionsManagerConfig {
transaction_fetcher_config: TransactionFetcherConfig::new(
self.max_concurrent_tx_requests,
self.max_concurrent_tx_requests_per_peer,
self.soft_limit_byte_size_pooled_transactions_response,
self.soft_limit_byte_size_pooled_transactions_response_on_pack_request,
),
Expand Down Expand Up @@ -258,6 +273,8 @@ impl Default for NetworkArgs {
port: DEFAULT_DISCOVERY_PORT,
max_outbound_peers: None,
max_inbound_peers: None,
max_concurrent_tx_requests: DEFAULT_MAX_COUNT_CONCURRENT_REQUESTS,
max_concurrent_tx_requests_per_peer: DEFAULT_MAX_COUNT_CONCURRENT_REQUESTS_PER_PEER,
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,
Expand Down

0 comments on commit c23c67a

Please sign in to comment.