Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add lints to p2p-sync #1844

Merged
merged 1 commit into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions crates/papyrus_p2p_sync/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,6 @@ tokio = { workspace = true, features = ["test-util"] }
# The `metrics` crate is used by `latency_histogram` proc macro, which is used in this crate.
[package.metadata.cargo-machete]
ignored = ["metrics"]

[lints]
workspace = true
16 changes: 7 additions & 9 deletions crates/papyrus_p2p_sync/src/server/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@ pub(crate) fn calculate_block_number(
Direction::Backward => -1,
};
// TODO(shahak): Fix this code.
let blocks_delta: i128 = direction_factor * (query.step * read_blocks_counter) as i128;
let block_number: i128 = start_block as i128 + blocks_delta;
if block_number < 0 || block_number > u64::MAX as i128 {
return Err(P2PSyncServerError::BlockNumberOutOfRange {
query: query.clone(),
counter: read_blocks_counter,
});
}
Ok(block_number as u64)
let blocks_delta: i128 = direction_factor * i128::from(query.step * read_blocks_counter);
let block_number: i128 = i128::from(start_block) + blocks_delta;

u64::try_from(block_number).map_err(|_| P2PSyncServerError::BlockNumberOutOfRange {
query: query.clone(),
counter: read_blocks_counter,
})
}
Loading