Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/ethereum/cli/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ pub enum Commands<C: ChainSpecParser, Ext: clap::Args + fmt::Debug> {
DumpGenesis(dump_genesis::DumpGenesisCommand<C>),
/// Database debugging utilities
#[command(name = "db")]
Db(db::Command<C>),
Db(Box<db::Command<C>>),
/// Download public node snapshots
#[command(name = "download")]
Download(download::DownloadCommand<C>),
Expand All @@ -270,7 +270,7 @@ pub enum Commands<C: ChainSpecParser, Ext: clap::Args + fmt::Debug> {
Stage(stage::Command<C>),
/// P2P Debugging utilities
#[command(name = "p2p")]
P2P(p2p::Command<C>),
P2P(Box<p2p::Command<C>>),
/// Generate Test Vectors
#[cfg(feature = "dev")]
#[command(name = "test-vectors")]
Expand Down
80 changes: 79 additions & 1 deletion crates/net/network/src/transactions/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use crate::transactions::constants::tx_fetcher::{
};
use alloy_primitives::B256;
use derive_more::{Constructor, Display};

use reth_eth_wire::NetworkPrimitives;
use reth_ethereum_primitives::TxType;

Expand Down Expand Up @@ -38,7 +39,7 @@ impl Default for TransactionsManagerConfig {
}

/// Determines how new pending transactions are propagated to other peers in full.
#[derive(Debug, Clone, Default)]
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum TransactionPropagationMode {
/// Send full transactions to sqrt of current peers.
Expand All @@ -60,6 +61,26 @@ impl TransactionPropagationMode {
}
}
}
impl FromStr for TransactionPropagationMode {
type Err = String;

fn from_str(s: &str) -> Result<Self, Self::Err> {
let s = s.to_lowercase();
match s.as_str() {
"sqrt" => Ok(Self::Sqrt),
"all" => Ok(Self::All),
s => {
if let Some(num) = s.strip_prefix("max:") {
num.parse::<usize>()
.map(TransactionPropagationMode::Max)
.map_err(|_| format!("Invalid number for Max variant: {num}"))
} else {
Err(format!("Invalid transaction propagation mode: {s}"))
}
}
}
}
}

/// Configuration for fetching transactions.
#[derive(Debug, Constructor, Clone)]
Expand Down Expand Up @@ -255,3 +276,60 @@ where
/// Type alias for `TypedRelaxedFilter`. This filter accepts known Ethereum transaction types and
/// ignores unknown ones without penalizing the peer.
pub type RelaxedEthAnnouncementFilter = TypedRelaxedFilter<TxType>;

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_transaction_propagation_mode_from_str() {
// Test "sqrt" variant
assert_eq!(
TransactionPropagationMode::from_str("sqrt").unwrap(),
TransactionPropagationMode::Sqrt
);
assert_eq!(
TransactionPropagationMode::from_str("SQRT").unwrap(),
TransactionPropagationMode::Sqrt
);
assert_eq!(
TransactionPropagationMode::from_str("Sqrt").unwrap(),
TransactionPropagationMode::Sqrt
);

// Test "all" variant
assert_eq!(
TransactionPropagationMode::from_str("all").unwrap(),
TransactionPropagationMode::All
);
assert_eq!(
TransactionPropagationMode::from_str("ALL").unwrap(),
TransactionPropagationMode::All
);
assert_eq!(
TransactionPropagationMode::from_str("All").unwrap(),
TransactionPropagationMode::All
);

// Test "max:N" variant
assert_eq!(
TransactionPropagationMode::from_str("max:10").unwrap(),
TransactionPropagationMode::Max(10)
);
assert_eq!(
TransactionPropagationMode::from_str("MAX:42").unwrap(),
TransactionPropagationMode::Max(42)
);
assert_eq!(
TransactionPropagationMode::from_str("Max:100").unwrap(),
TransactionPropagationMode::Max(100)
);

// Test invalid inputs
assert!(TransactionPropagationMode::from_str("invalid").is_err());
assert!(TransactionPropagationMode::from_str("max:not_a_number").is_err());
assert!(TransactionPropagationMode::from_str("max:").is_err());
assert!(TransactionPropagationMode::from_str("max").is_err());
assert!(TransactionPropagationMode::from_str("").is_err());
}
}
18 changes: 15 additions & 3 deletions crates/node/core/src/args/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use reth_network::{
DEFAULT_MAX_COUNT_PENDING_POOL_IMPORTS, DEFAULT_MAX_COUNT_TRANSACTIONS_SEEN_BY_PEER,
},
},
TransactionFetcherConfig, TransactionsManagerConfig,
TransactionFetcherConfig, TransactionPropagationMode, TransactionsManagerConfig,
DEFAULT_SOFT_LIMIT_BYTE_SIZE_POOLED_TRANSACTIONS_RESP_ON_PACK_GET_POOLED_TRANSACTIONS_REQ,
SOFT_LIMIT_BYTE_SIZE_POOLED_TRANSACTIONS_RESPONSE,
},
Expand Down Expand Up @@ -167,6 +167,17 @@ pub struct NetworkArgs {
/// personal nodes, though providers should always opt to enable this flag.
#[arg(long = "disable-tx-gossip")]
pub disable_tx_gossip: bool,

/// Sets the transaction propagation mode by determining how new pending transactions are
/// propagated to other peers in full.
///
/// Examples: sqrt, all, max:10
#[arg(
long = "tx-propagation-mode",
default_value = "sqrt",
help = "Transaction propagation mode (sqrt, all, max:<number>)"
)]
pub propagation_mode: TransactionPropagationMode,
}

impl NetworkArgs {
Expand Down Expand Up @@ -198,7 +209,7 @@ impl NetworkArgs {
})
}
/// Configures and returns a `TransactionsManagerConfig` based on the current settings.
pub fn transactions_manager_config(&self) -> TransactionsManagerConfig {
pub const fn transactions_manager_config(&self) -> TransactionsManagerConfig {
TransactionsManagerConfig {
transaction_fetcher_config: TransactionFetcherConfig::new(
self.max_concurrent_tx_requests,
Expand All @@ -208,7 +219,7 @@ impl NetworkArgs {
self.max_capacity_cache_txns_pending_fetch,
),
max_transactions_seen_by_peer_history: self.max_seen_tx_history,
propagation_mode: Default::default(),
propagation_mode: self.propagation_mode,
}
}

Expand Down Expand Up @@ -351,6 +362,7 @@ impl Default for NetworkArgs {
net_if: None,
tx_propagation_policy: TransactionPropagationKind::default(),
disable_tx_gossip: false,
propagation_mode: TransactionPropagationMode::Sqrt,
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/optimism/cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub enum Commands<Spec: ChainSpecParser = OpChainSpecParser, Ext: clap::Args + f
Stage(Box<stage::Command<Spec>>),
/// P2P Debugging utilities
#[command(name = "p2p")]
P2P(p2p::Command<Spec>),
P2P(Box<p2p::Command<Spec>>),
/// Write config to stdout
#[command(name = "config")]
Config(config_cmd::Command),
Expand Down
7 changes: 7 additions & 0 deletions docs/vocs/docs/pages/cli/reth/node.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,13 @@ Networking:

Disables gossiping of transactions in the mempool to peers. This can be omitted for personal nodes, though providers should always opt to enable this flag.

--tx-propagation-mode <PROPAGATION_MODE>
Sets the transaction propagation mode by determining how new pending transactions are propagated to other peers in full.

Examples: sqrt, all, max:10

[default: sqrt]

RPC:
--http
Enable the HTTP-RPC server
Expand Down
7 changes: 7 additions & 0 deletions docs/vocs/docs/pages/cli/reth/p2p/body.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,13 @@ Networking:

Disables gossiping of transactions in the mempool to peers. This can be omitted for personal nodes, though providers should always opt to enable this flag.

--tx-propagation-mode <PROPAGATION_MODE>
Sets the transaction propagation mode by determining how new pending transactions are propagated to other peers in full.

Examples: sqrt, all, max:10

[default: sqrt]

Datadir:
--datadir <DATA_DIR>
The path to the data dir for all reth files and subdirectories.
Expand Down
7 changes: 7 additions & 0 deletions docs/vocs/docs/pages/cli/reth/p2p/header.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,13 @@ Networking:

Disables gossiping of transactions in the mempool to peers. This can be omitted for personal nodes, though providers should always opt to enable this flag.

--tx-propagation-mode <PROPAGATION_MODE>
Sets the transaction propagation mode by determining how new pending transactions are propagated to other peers in full.

Examples: sqrt, all, max:10

[default: sqrt]

Datadir:
--datadir <DATA_DIR>
The path to the data dir for all reth files and subdirectories.
Expand Down
7 changes: 7 additions & 0 deletions docs/vocs/docs/pages/cli/reth/stage/run.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,13 @@ Networking:

Disables gossiping of transactions in the mempool to peers. This can be omitted for personal nodes, though providers should always opt to enable this flag.

--tx-propagation-mode <PROPAGATION_MODE>
Sets the transaction propagation mode by determining how new pending transactions are propagated to other peers in full.

Examples: sqrt, all, max:10

[default: sqrt]

Logging:
--log.stdout.format <FORMAT>
The format to use for logs written to stdout
Expand Down
Loading