diff --git a/Makefile b/Makefile index 7dc9ae5326b..ac0202f1e72 100644 --- a/Makefile +++ b/Makefile @@ -86,7 +86,7 @@ setup-hive: ## 🐝 Set up Hive testing framework git pull origin $(HIVE_BRANCH) && \ go build .; \ else \ - git clone --branch $(HIVE_BRANCH) https://github.com/lambdaclass/hive && \ + git clone --branch $(HIVE_BRANCH) https://github.com/ethereum/hive && \ cd hive && \ git checkout $(HIVE_BRANCH) && \ go build .; \ diff --git a/cmd/ethrex/cli.rs b/cmd/ethrex/cli.rs index d3abd007e6b..443d5b5a6b7 100644 --- a/cmd/ethrex/cli.rs +++ b/cmd/ethrex/cli.rs @@ -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}; @@ -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(), @@ -248,6 +255,7 @@ impl Default for Options { dev: Default::default(), force: false, mempool_max_size: Default::default(), + tx_broadcasting_time_interval: Default::default(), extra_data: get_minimal_client_version(), } } diff --git a/cmd/ethrex/initializers.rs b/cmd/ethrex/initializers.rs index 77c264b2ccf..ab6dee336d4 100644 --- a/cmd/ethrex/initializers.rs +++ b/cmd/ethrex/initializers.rs @@ -214,6 +214,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"); diff --git a/crates/networking/p2p/network.rs b/crates/networking/p2p/network.rs index 45affd8f231..382ef5858f5 100644 --- a/crates/networking/p2p/network.rs +++ b/crates/networking/p2p/network.rs @@ -60,17 +60,22 @@ impl P2PContext { blockchain: Arc, client_version: String, based_context: Option, + tx_broadcasting_time_interval: u64, ) -> Result { let (channel_broadcast_send_end, _) = tokio::sync::broadcast::channel::<( tokio::task::Id, Arc, )>(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, diff --git a/crates/networking/p2p/tx_broadcaster.rs b/crates/networking/p2p/tx_broadcaster.rs index eeb1799510f..0c9a219386d 100644 --- a/crates/networking/p2p/tx_broadcaster.rs +++ b/crates/networking/p2p/tx_broadcaster.rs @@ -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 { @@ -115,6 +115,7 @@ impl TxBroadcaster { pub async fn spawn( kademlia: PeerTable, blockchain: Arc, + tx_broadcasting_time_interval: u64, ) -> Result, TxBroadcasterError> { info!("Starting Transaction Broadcaster"); @@ -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, ); diff --git a/docs/CLI.md b/docs/CLI.md index 3e5025211db..4c091d4f4d5 100644 --- a/docs/CLI.md +++ b/docs/CLI.md @@ -83,6 +83,11 @@ P2P options: UDP port for P2P discovery. [default: 30303] + + --p2p.tx-broadcasting-interval + Transaction Broadcasting Time Interval (ms) for batching transactions before broadcasting them. + + [default: 1000] RPC options: --http.addr