Skip to content

Commit

Permalink
chore(p2p_service): remove unnecessary cast to usize (#2123)
Browse files Browse the repository at this point in the history
## Linked Issues/PRs
<!-- List of related issues/PRs -->
- #2112

## Description
<!-- List of detailed changes -->
- Addressing
#2112 (comment)

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?
  • Loading branch information
rymnc authored Aug 22, 2024
1 parent de14e0d commit 882d264
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 12 deletions.
2 changes: 1 addition & 1 deletion bin/fuel-core/src/cli/run/p2p.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
4 changes: 2 additions & 2 deletions crates/services/p2p/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<State = Initialized> {
Expand All @@ -71,7 +71,7 @@ pub struct Config<State = Initialized> {

/// 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<Multiaddr>,
Expand Down
12 changes: 3 additions & 9 deletions crates/services/p2p/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ pub struct Task<P, V, B> {
request_sender: mpsc::Sender<TaskRequest>,
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,
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
Expand Down

0 comments on commit 882d264

Please sign in to comment.