Skip to content

Commit d75dc98

Browse files
authored
refactor(l1): remove unneeded usize casts (#4342)
**Motivation** Remove cases where we using `as usize` to cast `u64` values when not needed <!-- Why does this pull request exist? What are its goals? --> **Description** <!-- A clear and concise general description of the changes this PR introduces --> <!-- Link to issues: Resolves #111, Resolves #222 --> Contributes to #4081
1 parent a1e7ca8 commit d75dc98

File tree

4 files changed

+11
-15
lines changed

4 files changed

+11
-15
lines changed

crates/common/types/blobs_bundle.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ impl BlobsBundle {
116116
let max_blobs = max_blobs_per_block(fork);
117117
let blob_count = self.blobs.len();
118118

119-
if blob_count > max_blobs as usize {
119+
if blob_count > max_blobs {
120120
return Err(BlobsBundleError::MaxBlobsExceeded);
121121
}
122122

@@ -196,10 +196,10 @@ impl AddAssign for BlobsBundle {
196196
}
197197
}
198198

199-
const MAX_BLOB_COUNT: u64 = 6;
200-
const MAX_BLOB_COUNT_ELECTRA: u64 = 9;
199+
const MAX_BLOB_COUNT: usize = 6;
200+
const MAX_BLOB_COUNT_ELECTRA: usize = 9;
201201

202-
fn max_blobs_per_block(fork: Fork) -> u64 {
202+
fn max_blobs_per_block(fork: Fork) -> usize {
203203
if fork >= Fork::Prague {
204204
MAX_BLOB_COUNT_ELECTRA
205205
} else {
@@ -378,8 +378,7 @@ mod tests {
378378
fn transaction_with_too_many_blobs_should_fail() {
379379
let blob = blobs_bundle::blob_from_bytes("Im a Blob".as_bytes().into())
380380
.expect("Failed to create blob");
381-
let blobs =
382-
std::iter::repeat_n(blob, MAX_BLOB_COUNT_ELECTRA as usize + 1).collect::<Vec<_>>();
381+
let blobs = std::iter::repeat_n(blob, MAX_BLOB_COUNT_ELECTRA + 1).collect::<Vec<_>>();
383382

384383
let blobs_bundle =
385384
BlobsBundle::create_from_blobs(&blobs).expect("Failed to create blobs bundle");

crates/networking/p2p/peer_handler.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ pub const MAX_HEADER_CHUNK: u64 = 500_000;
5252
// How much we store in memory of request_account_range and request_storage_ranges
5353
// before we dump it into the file. This tunes how much memory ethrex uses during
5454
// the first steps of snap sync
55-
pub const RANGE_FILE_CHUNK_SIZE: u64 = 1024 * 1024 * 512; // 512MB
55+
pub const RANGE_FILE_CHUNK_SIZE: usize = 1024 * 1024 * 512; // 512MB
5656
pub const SNAP_LIMIT: usize = 128;
5757

5858
// Request as many as 128 block bodies per request
@@ -730,9 +730,7 @@ impl PeerHandler {
730730
let mut last_update: SystemTime = SystemTime::now();
731731

732732
loop {
733-
if all_accounts_state.len() * size_of::<AccountState>()
734-
>= RANGE_FILE_CHUNK_SIZE as usize
735-
{
733+
if all_accounts_state.len() * size_of::<AccountState>() >= RANGE_FILE_CHUNK_SIZE {
736734
let current_account_hashes = std::mem::take(&mut all_account_hashes);
737735
let current_account_states = std::mem::take(&mut all_accounts_state);
738736

@@ -1315,8 +1313,7 @@ impl PeerHandler {
13151313
let mut last_update = SystemTime::now();
13161314
debug!("Starting request_storage_ranges loop");
13171315
loop {
1318-
if all_account_storages.iter().map(Vec::len).sum::<usize>() * 64
1319-
> RANGE_FILE_CHUNK_SIZE as usize
1316+
if all_account_storages.iter().map(Vec::len).sum::<usize>() * 64 > RANGE_FILE_CHUNK_SIZE
13201317
{
13211318
let current_account_storages = std::mem::take(&mut all_account_storages);
13221319
all_account_storages =

crates/networking/rpc/authentication.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,6 @@ fn invalid_issued_at_claim(token_data: TokenData<Claims>) -> Result<bool, Authen
6161
let now = SystemTime::now()
6262
.duration_since(UNIX_EPOCH)
6363
.map_err(|_| AuthenticationError::InvalidIssuedAtClaim)?
64-
.as_secs() as usize;
65-
Ok((now as isize - token_data.claims.iat as isize).abs() > 60)
64+
.as_secs();
65+
Ok((now as i64 - token_data.claims.iat as i64).abs() > 60)
6666
}

crates/networking/rpc/clients/auth/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ impl EngineClient {
158158
// Header
159159
let header = jsonwebtoken::Header::default();
160160
// Claims
161-
let valid_iat = SystemTime::now().duration_since(UNIX_EPOCH)?.as_secs() as usize;
161+
let valid_iat = SystemTime::now().duration_since(UNIX_EPOCH)?.as_secs();
162162
let claims = json!({"iat": valid_iat});
163163
let encoding_key = jsonwebtoken::EncodingKey::from_secret(&self.secret);
164164
// JWT Token

0 commit comments

Comments
 (0)