diff --git a/Cargo.toml b/Cargo.toml index 1685fa97e802..a54a81ec2e22 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -365,6 +365,7 @@ rustdoc-args = ["--document-private-items"] [workspace.lints.clippy] ref_option = "deny" ref_option_ref = "deny" +cast_lossless = "deny" [workspace] members = ["interop-tests"] diff --git a/src/chain_sync/sync_status.rs b/src/chain_sync/sync_status.rs index ea6e0d3beadd..12fb5f7530ad 100644 --- a/src/chain_sync/sync_status.rs +++ b/src/chain_sync/sync_status.rs @@ -171,7 +171,7 @@ impl SyncStatusReport { let status = match stateless_mode { true => NodeSyncStatus::Offline, false => { - if time_diff < seconds_per_epoch as u64 * SYNCED_EPOCH_THRESHOLD { + if time_diff < u64::from(seconds_per_epoch) * SYNCED_EPOCH_THRESHOLD { NodeSyncStatus::Synced } else { NodeSyncStatus::Syncing diff --git a/src/chain_sync/validation.rs b/src/chain_sync/validation.rs index b279f6bfcab9..a55c84ae0503 100644 --- a/src/chain_sync/validation.rs +++ b/src/chain_sync/validation.rs @@ -94,7 +94,7 @@ impl TipsetValidator<'_> { .unwrap() .as_secs(); let max_epoch = - ((now - genesis_tipset.min_timestamp()) / block_delay as u64) + MAX_HEIGHT_DRIFT; + ((now - genesis_tipset.min_timestamp()) / u64::from(block_delay)) + MAX_HEIGHT_DRIFT; let too_far_ahead_in_time = self.0.epoch() as u64 > max_epoch; if too_far_ahead_in_time { Err(TipsetValidationError::EpochTooLarge) diff --git a/src/db/car/forest/index/hash.rs b/src/db/car/forest/index/hash.rs index fbab54396ba2..aa1ca9a50431 100644 --- a/src/db/car/forest/index/hash.rs +++ b/src/db/car/forest/index/hash.rs @@ -31,7 +31,7 @@ pub fn ideal_slot_ix(hash: NonMaximalU64, num_buckets: NonZeroUsize) -> usize { // break 0..=u64::MAX into 'buckets' chunks and map each chunk to 0..len. // if buckets=2, 0..(u64::MAX/2) maps to 0, and (u64::MAX/2)..=u64::MAX maps to 1. - usize::try_from((hash.get() as u128 * num_buckets.get() as u128) >> 64).unwrap() + usize::try_from((u128::from(hash.get()) * num_buckets.get() as u128) >> 64).unwrap() } /// Reverse engineer hashes which will be mapped to `ideal`. diff --git a/src/db/car/forest/index/mod.rs b/src/db/car/forest/index/mod.rs index 9dbf4ae93f57..a8642e685f9f 100644 --- a/src/db/car/forest/index/mod.rs +++ b/src/db/car/forest/index/mod.rs @@ -208,7 +208,7 @@ impl ZstdSkipFramesEncodedDataReader { .read_u32_at::(offset + ZSTD_SKIPPABLE_FRAME_MAGIC_HEADER.len() as u64) { skip_frame_header_offsets.push(offset); - offset += ZSTD_SKIP_FRAME_LEN + data_len as u64; + offset += ZSTD_SKIP_FRAME_LEN + u64::from(data_len); } Ok(Self { reader, diff --git a/src/db/car/plain.rs b/src/db/car/plain.rs index fedd044f0ff6..0f36b1eb90b4 100644 --- a/src/db/car/plain.rs +++ b/src/db/car/plain.rs @@ -234,7 +234,7 @@ impl PlainCar { .read() .get(&k) .map(|UncompressedBlockDataLocation { offset, length }| { - positioned_io::Cursor::new_pos(&self.reader, *offset).take(*length as u64) + positioned_io::Cursor::new_pos(&self.reader, *offset).take(u64::from(*length)) }) } } diff --git a/src/fil_cns/validation.rs b/src/fil_cns/validation.rs index 7cfe8f1f8a30..b30614c83b64 100644 --- a/src/fil_cns/validation.rs +++ b/src/fil_cns/validation.rs @@ -206,7 +206,8 @@ fn block_timestamp_checks( // Timestamp checks let block_delay = chain_config.block_delay_secs; let nulls = header.epoch - (base_tipset.epoch() + 1); - let target_timestamp = base_tipset.min_timestamp() + block_delay as u64 * (nulls + 1) as u64; + let target_timestamp = + base_tipset.min_timestamp() + u64::from(block_delay) * (nulls + 1) as u64; if target_timestamp != header.timestamp { return Err(FilecoinConsensusError::UnequalBlockTimestamps( header.timestamp, diff --git a/src/libp2p/behaviour.rs b/src/libp2p/behaviour.rs index ce3754012e49..d44c50dedf0d 100644 --- a/src/libp2p/behaviour.rs +++ b/src/libp2p/behaviour.rs @@ -130,7 +130,7 @@ impl ForestBehaviour { .with_kademlia(config.kademlia) .with_user_defined(config.bootstrap_peers.clone()) .await? - .target_peer_count(config.target_peer_count as u64) + .target_peer_count(u64::from(config.target_peer_count)) .finish()?; let connection_limits = connection_limits::Behaviour::new( diff --git a/src/libp2p_bitswap/bitswap_pb.rs b/src/libp2p_bitswap/bitswap_pb.rs index fa925d4c3857..f997d0017bf0 100644 --- a/src/libp2p_bitswap/bitswap_pb.rs +++ b/src/libp2p_bitswap/bitswap_pb.rs @@ -94,7 +94,7 @@ impl MessageWrite for Wantlist { fn get_size(&self) -> usize { 0 + self.entries.iter().map(|s| 1 + sizeof_len((s).get_size())).sum::() - + if self.full == false { 0 } else { 1 + sizeof_varint(*(&self.full) as u64) } + + if self.full == false { 0 } else { 1 + sizeof_varint(u64::from(*(&self.full))) } } fn write_message(&self, w: &mut Writer) -> Result<()> { @@ -141,9 +141,9 @@ impl MessageWrite for Entry { 0 + if self.block.is_empty() { 0 } else { 1 + sizeof_len((&self.block).len()) } + if self.priority == 0i32 { 0 } else { 1 + sizeof_varint(*(&self.priority) as u64) } - + if self.cancel == false { 0 } else { 1 + sizeof_varint(*(&self.cancel) as u64) } + + if self.cancel == false { 0 } else { 1 + sizeof_varint(u64::from(*(&self.cancel))) } + if self.wantType == bitswap_pb::mod_Message::mod_Wantlist::WantType::Block { 0 } else { 1 + sizeof_varint(*(&self.wantType) as u64) } - + if self.sendDontHave == false { 0 } else { 1 + sizeof_varint(*(&self.sendDontHave) as u64) } + + if self.sendDontHave == false { 0 } else { 1 + sizeof_varint(u64::from(*(&self.sendDontHave))) } } fn write_message(&self, w: &mut Writer) -> Result<()> { diff --git a/src/message_pool/block_prob.rs b/src/message_pool/block_prob.rs index 1fbb7eeab820..c5d917bb25be 100644 --- a/src/message_pool/block_prob.rs +++ b/src/message_pool/block_prob.rs @@ -121,6 +121,6 @@ fn test_winner_probability() { } } - let avg = sum / (n as f64); + let avg = sum / (f64::from(n)); assert!((avg - 5.0).abs() > 0.01, "Average too far off "); } diff --git a/src/message_pool/msgpool/msg_pool.rs b/src/message_pool/msgpool/msg_pool.rs index 427cd989705d..8a68edc85ab3 100644 --- a/src/message_pool/msgpool/msg_pool.rs +++ b/src/message_pool/msgpool/msg_pool.rs @@ -590,7 +590,7 @@ where let republished = mp.republished.clone(); let local_addrs = mp.local_addrs.clone(); let network_sender = Arc::new(mp.network_sender.clone()); - let republish_interval = (10 * block_delay + chain_config.propagation_delay_secs) as u64; + let republish_interval = u64::from(10 * block_delay + chain_config.propagation_delay_secs); // Reacts to republishing requests services.spawn(async move { let mut repub_trigger_rx = repub_trigger_rx.stream(); diff --git a/src/networks/metrics.rs b/src/networks/metrics.rs index 41bd781fb694..333b8c5125c7 100644 --- a/src/networks/metrics.rs +++ b/src/networks/metrics.rs @@ -89,7 +89,7 @@ where { let network_version = self.chain_config.network_version(epoch); let nv_gauge: Gauge = Default::default(); - nv_gauge.set(u32::from(network_version) as _); + nv_gauge.set(i64::from(u32::from(network_version))); let metric_encoder = encoder.encode_descriptor( "network_version", "Network version of the current chain head", diff --git a/src/networks/mod.rs b/src/networks/mod.rs index 51c39de3325e..1c4dfcfe65d2 100644 --- a/src/networks/mod.rs +++ b/src/networks/mod.rs @@ -495,7 +495,7 @@ impl ChainConfig { .map(|dc| { BeaconPoint::new( dc.height, - DrandBeacon::new(genesis_ts, self.block_delay_secs as u64, dc.config), + DrandBeacon::new(genesis_ts, u64::from(self.block_delay_secs), dc.config), ) }) .collect(), @@ -629,7 +629,7 @@ pub fn calculate_expected_epoch( genesis_timestamp: u64, block_delay_secs: u32, ) -> i64 { - (now_timestamp.saturating_sub(genesis_timestamp) / block_delay_secs as u64) as i64 + (now_timestamp.saturating_sub(genesis_timestamp) / u64::from(block_delay_secs)) as i64 } #[cfg(test)] @@ -735,7 +735,7 @@ mod tests { assert_eq!( 0, calculate_expected_epoch( - mainnet_genesis + mainnet_block_delay as u64 - 1, + mainnet_genesis + u64::from(mainnet_block_delay) - 1, mainnet_genesis, mainnet_block_delay ) @@ -744,7 +744,7 @@ mod tests { assert_eq!( 1, calculate_expected_epoch( - mainnet_genesis + mainnet_block_delay as u64, + mainnet_genesis + u64::from(mainnet_block_delay), mainnet_genesis, mainnet_block_delay ) diff --git a/src/rpc/auth_layer.rs b/src/rpc/auth_layer.rs index 5d33cb48c67f..b0cf4952800c 100644 --- a/src/rpc/auth_layer.rs +++ b/src/rpc/auth_layer.rs @@ -83,7 +83,7 @@ impl Auth { Ok(false) => { tracing::warn!("Unauthorized access attempt for method {method_name}"); Err(ErrorObject::borrowed( - http::StatusCode::UNAUTHORIZED.as_u16() as _, + i32::from(http::StatusCode::UNAUTHORIZED.as_u16()), "Unauthorized", None, )) diff --git a/src/rpc/filter_layer.rs b/src/rpc/filter_layer.rs index 7d8175a6c65d..a6f4e7b470fd 100644 --- a/src/rpc/filter_layer.rs +++ b/src/rpc/filter_layer.rs @@ -50,7 +50,7 @@ impl Filtering { Ok(()) } else { Err(ErrorObject::borrowed( - http::StatusCode::FORBIDDEN.as_u16() as _, + i32::from(http::StatusCode::FORBIDDEN.as_u16()), "Forbidden", None, )) diff --git a/src/rpc/methods/eth.rs b/src/rpc/methods/eth.rs index a2f7987cc8ad..44ec2f76a49d 100644 --- a/src/rpc/methods/eth.rs +++ b/src/rpc/methods/eth.rs @@ -1246,7 +1246,7 @@ async fn new_eth_tx_receipt( block_hash: tx.block_hash, block_number: tx.block_number, r#type: tx.r#type, - status: (msg_receipt.exit_code().is_success() as u64).into(), + status: u64::from(msg_receipt.exit_code().is_success()).into(), gas_used: msg_receipt.gas_used().into(), ..EthTxReceipt::new() }; diff --git a/src/rpc/methods/gas.rs b/src/rpc/methods/gas.rs index eaccf607de64..9c0a64c0bbe8 100644 --- a/src/rpc/methods/gas.rs +++ b/src/rpc/methods/gas.rs @@ -64,7 +64,7 @@ fn estimate_fee_cap( (1.0 + (BASE_FEE_MAX_CHANGE_DENOM as f64).recip()).powf(max_queue_blks as f64); let fee_in_future = parent_base_fee - * BigInt::from_f64(increase_factor * (1 << 8) as f64) + * BigInt::from_f64(increase_factor * f64::from(1_i32 << 8)) .context("failed to convert fee_in_future f64 to bigint")?; let out = fee_in_future.div_floor(1 << 8).add(msg.gas_premium()); Ok(out) diff --git a/src/rpc/methods/state.rs b/src/rpc/methods/state.rs index e55384ae7ce9..8f0f191d8b3b 100644 --- a/src/rpc/methods/state.rs +++ b/src/rpc/methods/state.rs @@ -1627,7 +1627,7 @@ impl RpcMethod<3> for StateCompute { msg: ctx.message.message().clone(), msg_rct: Some(ctx.apply_ret.msg_receipt()), error: ctx.apply_ret.failure_info().unwrap_or_default(), - duration: ctx.duration.as_nanos().clamp(0, u64::MAX as u128) as u64, + duration: ctx.duration.as_nanos().clamp(0, u128::from(u64::MAX)) as u64, gas_cost: MessageGasCost::new(ctx.message.message(), ctx.apply_ret)?, execution_trace: structured::parse_events(ctx.apply_ret.exec_trace()) .unwrap_or_default(), @@ -2116,7 +2116,7 @@ impl RpcMethod<1> for StateGetBeaconEntry { ) -> Result { { let genesis_timestamp = ctx.chain_store().genesis_block_header().timestamp as i64; - let block_delay = ctx.chain_config().block_delay_secs as i64; + let block_delay = i64::from(ctx.chain_config().block_delay_secs); // Give it a 1s clock drift buffer let epoch_timestamp = genesis_timestamp + block_delay * epoch + 1; let now_timestamp = chrono::Utc::now().timestamp(); @@ -3081,7 +3081,7 @@ impl RpcMethod<0> for StateGetNetworkParams { let params = NetworkParams { network_name, - block_delay_secs: config.block_delay_secs as u64, + block_delay_secs: u64::from(config.block_delay_secs), consensus_miner_min_power: policy.minimum_consensus_power.clone(), pre_commit_challenge_delay: policy.pre_commit_challenge_delay, fork_upgrade_params: ForkUpgradeParams::try_from(config) diff --git a/src/shim/gas.rs b/src/shim/gas.rs index e3de4d163be7..35cfdc6d2500 100644 --- a/src/shim/gas.rs +++ b/src/shim/gas.rs @@ -70,7 +70,7 @@ impl Gas { impl GasDuration { pub fn as_nanos(&self) -> u64 { if let Some(duration) = self.0.get() { - duration.as_nanos().clamp(0, u64::MAX as u128) as u64 + duration.as_nanos().clamp(0, u128::from(u64::MAX)) as u64 } else { 0 } diff --git a/src/state_manager/mod.rs b/src/state_manager/mod.rs index b8ac499e75ae..ffff5decb28c 100644 --- a/src/state_manager/mod.rs +++ b/src/state_manager/mod.rs @@ -651,7 +651,7 @@ where msg_rct: Some(apply_ret.msg_receipt()), msg_cid: msg.cid(), error: apply_ret.failure_info().unwrap_or_default(), - duration: duration.as_nanos().clamp(0, u64::MAX as u128) as u64, + duration: duration.as_nanos().clamp(0, u128::from(u64::MAX)) as u64, gas_cost: MessageGasCost::default(), execution_trace: structured::parse_events(apply_ret.exec_trace()).unwrap_or_default(), }) @@ -723,7 +723,7 @@ where msg, msg_rct: Some(apply_ret.msg_receipt()), error: apply_ret.failure_info().unwrap_or_default(), - duration: duration.as_nanos().clamp(0, u64::MAX as u128) as u64, + duration: duration.as_nanos().clamp(0, u128::from(u64::MAX)) as u64, gas_cost: MessageGasCost::default(), execution_trace: structured::parse_events(apply_ret.exec_trace()) .unwrap_or_default(), @@ -830,7 +830,7 @@ where msg: ctx.message.message().clone(), msg_rct: Some(ctx.apply_ret.msg_receipt()), error: ctx.apply_ret.failure_info().unwrap_or_default(), - duration: ctx.duration.as_nanos().clamp(0, u64::MAX as u128) as u64, + duration: ctx.duration.as_nanos().clamp(0, u128::from(u64::MAX)) as u64, gas_cost: MessageGasCost::new(ctx.message.message(), ctx.apply_ret)?, execution_trace: structured::parse_events(ctx.apply_ret.exec_trace()) .unwrap_or_default(), @@ -1748,7 +1748,7 @@ where msg: ctx.message.message().clone(), msg_rct: Some(ctx.apply_ret.msg_receipt()), error: ctx.apply_ret.failure_info().unwrap_or_default(), - duration: ctx.duration.as_nanos().clamp(0, u64::MAX as u128) as u64, + duration: ctx.duration.as_nanos().clamp(0, u128::from(u64::MAX)) as u64, gas_cost: MessageGasCost::new(ctx.message.message(), ctx.apply_ret)?, execution_trace: structured::parse_events(ctx.apply_ret.exec_trace()) .unwrap_or_default(), diff --git a/src/tool/subcommands/api_cmd/api_compare_tests.rs b/src/tool/subcommands/api_cmd/api_compare_tests.rs index 3648e6ef7c98..950ff4d524cf 100644 --- a/src/tool/subcommands/api_cmd/api_compare_tests.rs +++ b/src/tool/subcommands/api_cmd/api_compare_tests.rs @@ -958,22 +958,22 @@ fn state_tests_with_tipset( RpcTest::identity(StateMarketDeals::request((tipset.key().into(),))?), RpcTest::identity(StateSectorPreCommitInfo::request(( Default::default(), // invalid address - u16::MAX as _, + u64::from(u16::MAX), tipset.key().into(), ))?) .policy_on_rejected(PolicyOnRejected::Pass), RpcTest::identity(StateSectorGetInfo::request(( - Default::default(), // invalid address - u16::MAX as _, // invalid sector number + Default::default(), // invalid address + u64::from(u16::MAX), // invalid sector number tipset.key().into(), ))?) .policy_on_rejected(PolicyOnRejected::Pass), RpcTest::identity(StateGetAllocationIdForPendingDeal::request(( - u16::MAX as _, // Invalid deal id + u64::from(u16::MAX), // Invalid deal id tipset.key().into(), ))?), RpcTest::identity(StateGetAllocationForPendingDeal::request(( - u16::MAX as _, // Invalid deal id + u64::from(u16::MAX), // Invalid deal id tipset.key().into(), ))?), RpcTest::identity(StateCompute::request(( @@ -1104,13 +1104,13 @@ fn state_tests_with_tipset( RpcTest::identity(StateGetAllAllocations::request((tipset.key().into(),))?), RpcTest::identity(StateSectorPreCommitInfo::request(( block.miner_address, - u16::MAX as _, // invalid sector number + u64::from(u16::MAX), // invalid sector number tipset.key().into(), ))?) .policy_on_rejected(PolicyOnRejected::PassWithIdenticalError), RpcTest::identity(StateSectorGetInfo::request(( block.miner_address, - u16::MAX as _, // invalid sector number + u64::from(u16::MAX), // invalid sector number tipset.key().into(), ))?) .policy_on_rejected(PolicyOnRejected::PassWithIdenticalError), diff --git a/src/tool/subcommands/snapshot_cmd.rs b/src/tool/subcommands/snapshot_cmd.rs index f45a0cd3f010..ae9ab0a4eccf 100644 --- a/src/tool/subcommands/snapshot_cmd.rs +++ b/src/tool/subcommands/snapshot_cmd.rs @@ -333,7 +333,7 @@ async fn validate_ipld_links(ts: Tipset, db: &DB, epochs: u32) -> anyhow::Re where DB: Blockstore + Send + Sync, { - let epoch_limit = ts.epoch() - epochs as i64; + let epoch_limit = ts.epoch() - i64::from(epochs); let pb = validation_spinner("Checking IPLD integrity:").with_finish( indicatif::ProgressFinish::AbandonWithMessage("❌ Invalid IPLD data!".into()), @@ -412,7 +412,7 @@ where // Fix off-by-1 bug: prevent validating more epochs than available in the snapshot. // Without +1, specifying --check-stateroots=900 would validate 901 epochs, // causing out-of-bounds errors when the snapshot contains only 900 recent state roots. - let last_epoch = ts.epoch() - epochs as i64 + 1; + let last_epoch = ts.epoch() - i64::from(epochs) + 1; // Set proof parameter data dir before downloading proofs. crate::utils::proofs_api::maybe_set_proofs_parameter_cache_dir_env( @@ -574,7 +574,7 @@ mod structured { "TotalCost": (chain_message.message().required_funds() - &apply_ret.refund()).into_lotus_json(), }, "ExecutionTrace": structured::parse_events(apply_ret.exec_trace())?.into_lotus_json(), - "Duration": duration.as_nanos().clamp(0, u64::MAX as u128) as u64, + "Duration": duration.as_nanos().clamp(0, u128::from(u64::MAX)) as u64, })) } }