Skip to content
12 changes: 10 additions & 2 deletions cmd/ethrex/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ use std::{
use clap::{ArgAction, Parser as ClapParser, Subcommand as ClapSubcommand};
use ethrex_blockchain::{BlockchainOptions, BlockchainType, error::ChainError};
use ethrex_common::types::{Block, Genesis};
use ethrex_p2p::sync::SyncMode;
use ethrex_p2p::types::Node;
use ethrex_p2p::{sync::SyncMode, tx_broadcaster::BROADCAST_INTERVAL_MS, types::Node};
use ethrex_rlp::encode::RLPEncode;
use ethrex_storage::error::StoreError;
use tracing::{Level, info, warn};
Expand Down Expand Up @@ -175,6 +174,14 @@ pub struct Options {
help_heading = "P2P options"
)]
pub discovery_port: String,
#[arg(
long = "p2p.tx-broadcasting-interval",
default_value_t = BROADCAST_INTERVAL_MS,
value_name = "INTERVAL_MS",
help = "Transaction Broadcasting Time Interval (ms) for batching transactions before broadcasting them.",
help_heading = "P2P options"
)]
pub tx_broadcasting_time_interval: u64,
#[arg(
long = "block-producer.extra-data",
default_value = get_minimal_client_version(),
Expand Down Expand Up @@ -248,6 +255,7 @@ impl Default for Options {
dev: Default::default(),
force: false,
mempool_max_size: Default::default(),
tx_broadcasting_time_interval: Default::default(),
Copy link
Collaborator

@mpaulucci mpaulucci Oct 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isnt this 0? Do we actually want the default?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I set the default value with the one that was used previously here and then with this pr when hive launches ethrex I set the interval value to what I tested works.

extra_data: get_minimal_client_version(),
}
}
Expand Down
1 change: 1 addition & 0 deletions cmd/ethrex/initializers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ pub async fn init_network(
blockchain.clone(),
get_client_version(),
based_context,
opts.tx_broadcasting_time_interval,
)
.await
.expect("P2P context could not be created");
Expand Down
15 changes: 10 additions & 5 deletions crates/networking/p2p/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,22 @@ impl P2PContext {
blockchain: Arc<Blockchain>,
client_version: String,
based_context: Option<P2PBasedContext>,
tx_broadcasting_time_interval: u64,
) -> Result<Self, NetworkError> {
let (channel_broadcast_send_end, _) = tokio::sync::broadcast::channel::<(
tokio::task::Id,
Arc<Message>,
)>(MAX_MESSAGES_TO_BROADCAST);

let tx_broadcaster = TxBroadcaster::spawn(peer_table.clone(), blockchain.clone())
.await
.inspect_err(|e| {
error!("Failed to start Tx Broadcaster: {e}");
})?;
let tx_broadcaster = TxBroadcaster::spawn(
peer_table.clone(),
blockchain.clone(),
tx_broadcasting_time_interval,
)
.await
.inspect_err(|e| {
error!("Failed to start Tx Broadcaster: {e}");
})?;

Ok(P2PContext {
local_node,
Expand Down
7 changes: 4 additions & 3 deletions crates/networking/p2p/tx_broadcaster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ const PRUNE_WAIT_TIME_SECS: u64 = 600; // 10 minutes
// Amount of seconds between each prune
const PRUNE_INTERVAL_SECS: u64 = 360; // 6 minutes

// Amount of seconds between each broadcast
const BROADCAST_INTERVAL_SECS: u64 = 1; // 1 second
// Amount of milliseconds between each broadcast
pub const BROADCAST_INTERVAL_MS: u64 = 1000; // 1 second

#[derive(Debug, Clone, Default)]
struct PeerMask {
Expand Down Expand Up @@ -115,6 +115,7 @@ impl TxBroadcaster {
pub async fn spawn(
kademlia: PeerTableHandle,
blockchain: Arc<Blockchain>,
tx_broadcasting_time_interval: u64,
) -> Result<GenServerHandle<TxBroadcaster>, TxBroadcasterError> {
info!("Starting Transaction Broadcaster");

Expand All @@ -129,7 +130,7 @@ impl TxBroadcaster {
let server = state.clone().start();

send_interval(
Duration::from_secs(BROADCAST_INTERVAL_SECS),
Duration::from_millis(tx_broadcasting_time_interval),
server.clone(),
InMessage::BroadcastTxs,
);
Expand Down
5 changes: 5 additions & 0 deletions docs/CLI.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ P2P options:
UDP port for P2P discovery.

[default: 30303]

--p2p.tx-broadcasting-interval <INTERVAL_MS>
Transaction Broadcasting Time Interval (ms) for batching transactions before broadcasting them.

[default: 1000]

RPC options:
--http.addr <ADDRESS>
Expand Down