diff --git a/bin/fuel-core/src/cli/run/p2p.rs b/bin/fuel-core/src/cli/run/p2p.rs index 5ebeb312de1..47b107f8312 100644 --- a/bin/fuel-core/src/cli/run/p2p.rs +++ b/bin/fuel-core/src/cli/run/p2p.rs @@ -64,7 +64,7 @@ pub struct P2PArgs { /// Max number of blocks/headers in a single headers request response #[clap(long = "max-headers-per-request", default_value = "100", env)] - pub max_headers_per_request: u32, + pub max_headers_per_request: usize, /// Addresses of the bootstrap nodes /// They should contain PeerId within their `Multiaddr` diff --git a/crates/services/p2p/src/config.rs b/crates/services/p2p/src/config.rs index 355e9e70db0..a807f79be33 100644 --- a/crates/services/p2p/src/config.rs +++ b/crates/services/p2p/src/config.rs @@ -47,7 +47,7 @@ const REQ_RES_TIMEOUT: Duration = Duration::from_secs(20); pub const MAX_RESPONSE_SIZE: usize = 18 * 1024 * 1024; /// Maximum number of blocks per request. -pub const MAX_HEADERS_PER_REQUEST: u32 = 100; +pub const MAX_HEADERS_PER_REQUEST: usize = 100; #[derive(Clone, Debug)] pub struct Config { @@ -71,7 +71,7 @@ pub struct Config { /// Max Size of a Block in bytes pub max_block_size: usize, - pub max_headers_per_request: u32, + pub max_headers_per_request: usize, // `DiscoveryBehaviour` related fields pub bootstrap_nodes: Vec, diff --git a/crates/services/p2p/src/service.rs b/crates/services/p2p/src/service.rs index 7d1dd9b8ae6..0589b889f3e 100644 --- a/crates/services/p2p/src/service.rs +++ b/crates/services/p2p/src/service.rs @@ -327,7 +327,7 @@ pub struct Task { request_sender: mpsc::Sender, database_processor: HeavyTaskProcessor, broadcast: B, - max_headers_per_request: u32, + max_headers_per_request: usize, // milliseconds wait time between peer heartbeat reputation checks heartbeat_check_interval: Duration, heartbeat_max_avg_interval: Duration, @@ -435,12 +435,10 @@ where let instant = Instant::now(); let timeout = self.response_timeout; let response_channel = self.request_sender.clone(); + let max_len = self.max_headers_per_request; + match request_message { RequestMessage::Transactions(range) => { - let max_len = self - .max_headers_per_request - .try_into() - .expect("u32 should always fit into usize"); if range.len() > max_len { tracing::error!( requested_length = range.len(), @@ -492,10 +490,6 @@ where } } RequestMessage::SealedHeaders(range) => { - let max_len = self - .max_headers_per_request - .try_into() - .expect("u32 should always fit into usize"); if range.len() > max_len { tracing::error!( requested_length = range.len(),