From 882d26484f7232247bcc8ce1395a6c9f46a070d8 Mon Sep 17 00:00:00 2001 From: Aaryamann Challani <43716372+rymnc@users.noreply.github.com> Date: Thu, 22 Aug 2024 18:31:24 +0530 Subject: [PATCH] chore(p2p_service): remove unnecessary cast to usize (#2123) ## Linked Issues/PRs - #2112 ## Description - Addressing https://github.com/FuelLabs/fuel-core/pull/2112#discussion_r1725069146 A follow up PR will be made to address #2121 ## Checklist - [x] Breaking changes are clearly marked as such in the PR description and changelog - [x] New behavior is reflected in tests - [x] [The specification](https://github.com/FuelLabs/fuel-specs/) matches the implemented behavior (link update PR if changes are needed) ### Before requesting review - [x] I have reviewed the code myself - [x] I have created follow-up issues caused by this PR and linked them here ### After merging, notify other teams [Add or remove entries as needed] - [ ] [Rust SDK](https://github.com/FuelLabs/fuels-rs/) - [ ] [Sway compiler](https://github.com/FuelLabs/sway/) - [ ] [Platform documentation](https://github.com/FuelLabs/devrel-requests/issues/new?assignees=&labels=new+request&projects=&template=NEW-REQUEST.yml&title=%5BRequest%5D%3A+) (for out-of-organization contributors, the person merging the PR will do this) - [ ] Someone else? --- bin/fuel-core/src/cli/run/p2p.rs | 2 +- crates/services/p2p/src/config.rs | 4 ++-- crates/services/p2p/src/service.rs | 12 +++--------- 3 files changed, 6 insertions(+), 12 deletions(-) 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(),