Skip to content

Commit f5aa34d

Browse files
VictorLuxclaude
andcommitted
fix: Resolve 29 Rust 1.93.0 Clippy lints in zipherx-core
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 264abf8 commit f5aa34d

9 files changed

Lines changed: 127 additions & 115 deletions

File tree

crates/zipherx-core/src/async_block_fetch.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ pub async fn fetch_blocks_by_hashes(
7878

7979
let blocks_per_round = (peer_count as u64) * MAX_BLOCKS_PER_PEER;
8080
let total = blocks_to_fetch.len();
81-
let num_rounds = (total + blocks_per_round as usize - 1) / blocks_per_round as usize;
81+
let num_rounds = total.div_ceil(blocks_per_round as usize);
8282

8383
let mut all_blocks: Vec<CompactBlock> = Vec::new();
8484
let mut received_heights: HashSet<u64> = HashSet::new();

crates/zipherx-core/src/async_prover.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ pub async fn ensure_prover_initialized(
115115
/// expected hashes (SPEND_PARAMS_SHA256, OUTPUT_PARAMS_SHA256) ensures
116116
/// content integrity — even if the TLS connection were compromised,
117117
/// the hash mismatch would reject tampered data.
118+
///
118119
/// The hardcoded hashes are the same as those published by the Zcash team.
119120
async fn download_param_if_needed(
120121
path: &str,

crates/zipherx-core/src/async_send.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ pub async fn send_transaction(
151151
if found {
152152
eprintln!("[ZipherX] Anchor OK for note {} (id={})", i, note.id);
153153
} else {
154-
let anchor_hex = hex::encode(&anchor);
154+
let anchor_hex = hex::encode(anchor);
155155
eprintln!(
156156
"[ZipherX] ANCHOR INVALID for note {} (id={}): {} — not in any block header",
157157
i, note.id, anchor_hex
@@ -374,10 +374,7 @@ async fn select_notes_with_witness_check(
374374
.map_err(|e| CoreError::RuntimeError(e.to_string()))?
375375
.map_err(|e| CoreError::Storage(e.to_string()))?;
376376

377-
let spendable: Vec<SpendableNote> = notes
378-
.iter()
379-
.filter_map(|n| send::note_to_spendable(n))
380-
.collect();
377+
let spendable: Vec<SpendableNote> = notes.iter().filter_map(send::note_to_spendable).collect();
381378

382379
let (selected, total_value) =
383380
send::select_notes(&spendable, request.total_needed()).map_err(|_| {

crates/zipherx-core/src/async_sync.rs

Lines changed: 85 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ pub async fn sync_to_tip(
508508
let headers_synced = header_sync
509509
.sync_headers(peer_manager, start_height, None, Some(progress_tx))
510510
.await
511-
.map_err(|e| CoreError::Network(e))?;
511+
.map_err(CoreError::Network)?;
512512

513513
let _ = progress_forwarder.await;
514514

@@ -580,7 +580,7 @@ pub async fn sync_to_tip(
580580

581581
if total_output_blocks > 0 {
582582
let pacing = PacingConfig::default();
583-
let num_chunks = (total_output_blocks + DELTA_CHUNK_SIZE - 1) / DELTA_CHUNK_SIZE;
583+
let num_chunks = total_output_blocks.div_ceil(DELTA_CHUNK_SIZE);
584584
let mut grand_total_cmus: u64 = 0;
585585
let mut grand_total_nullifiers: u64 = 0;
586586
let mut chunks_completed: usize = 0;
@@ -921,8 +921,7 @@ pub async fn sync_to_tip(
921921
.parent()
922922
.map(|p| p.join("BoostCache").join("zipherx_boost_manifest.json"))
923923
.unwrap_or_default()
924-
.to_string_lossy()
925-
.to_string(),
924+
.to_string_lossy(),
926925
) {
927926
let manifest_root_hex = &manifest.tree_root;
928927
let blockchain_root_hex = hex::encode(&blockchain_root);
@@ -1645,7 +1644,7 @@ pub async fn sync_to_tip(
16451644

16461645
let mut scan_offset = tree_height as usize;
16471646
let mut current_tree_position = tree_height;
1648-
let num_scan_chunks = ((unscanned as usize) + SCAN_CHUNK_SIZE - 1) / SCAN_CHUNK_SIZE;
1647+
let num_scan_chunks = (unscanned as usize).div_ceil(SCAN_CHUNK_SIZE);
16491648

16501649
eprintln!(
16511650
"[ZipherX] Scanning in {} chunks of up to {} outputs",
@@ -1687,8 +1686,11 @@ pub async fn sync_to_tip(
16871686
let chunk_nullifiers = delta_store
16881687
.load_nullifiers_for_height_range(first_height, last_height)
16891688
.map_err(|e| CoreError::Storage(e.to_string()))?;
1690-
let mut nullifier_map: std::collections::BTreeMap<u64, Vec<(Vec<u8>, Vec<u8>)>> =
1691-
std::collections::BTreeMap::new();
1689+
#[allow(clippy::type_complexity)]
1690+
let mut nullifier_map: std::collections::BTreeMap<
1691+
u64,
1692+
Vec<(Vec<u8>, Vec<u8>)>,
1693+
> = std::collections::BTreeMap::new();
16921694
for nf in &chunk_nullifiers {
16931695
nullifier_map
16941696
.entry(nf.height as u64)
@@ -2138,7 +2140,7 @@ pub async fn sync_to_tip(
21382140
.map(|n| {
21392141
(
21402142
n.value,
2141-
n.height as u64,
2143+
n.height,
21422144
n.received_txid
21432145
.as_deref()
21442146
.unwrap_or("?")
@@ -2155,7 +2157,7 @@ pub async fn sync_to_tip(
21552157
.map(|n| {
21562158
(
21572159
n.value,
2158-
n.height as u64,
2160+
n.height,
21592161
n.received_txid
21602162
.as_deref()
21612163
.unwrap_or("?")
@@ -2305,6 +2307,7 @@ pub async fn sync_to_tip(
23052307
let db_c = db.clone();
23062308

23072309
// Collect data needed for nullifier recomputation
2310+
#[allow(clippy::type_complexity)]
23082311
let notes_data: Vec<(
23092312
Vec<u8>,
23102313
Option<Vec<u8>>,
@@ -2517,10 +2520,10 @@ pub async fn sync_to_tip(
25172520
);
25182521
// Re-read balance after recovery
25192522
let db_bal = db.clone();
2520-
if let Ok(bal) = tokio::task::spawn_blocking(move || db_bal.get_balance(0)).await {
2521-
if let Ok(spendable) = bal {
2522-
eprintln!("[ZipherX] Post-recovery spendable balance: {}", spendable);
2523-
}
2523+
if let Ok(Ok(spendable)) =
2524+
tokio::task::spawn_blocking(move || db_bal.get_balance(0)).await
2525+
{
2526+
eprintln!("[ZipherX] Post-recovery spendable balance: {}", spendable);
25242527
}
25252528
}
25262529
Ok(Err(e)) => {
@@ -2943,7 +2946,7 @@ pub async fn rebuild_witnesses_if_needed(
29432946
commitment_tree::root().map_err(|e| CoreError::Crypto(format!("Tree root: {e}")))?;
29442947
let rebuilt_size =
29452948
commitment_tree::size().map_err(|e| CoreError::Crypto(format!("Tree size: {e}")))?;
2946-
let root_hex = hex::encode(&rebuilt_root);
2949+
let root_hex = hex::encode(rebuilt_root);
29472950
let root_rev_hex = hex::encode(rebuilt_root.iter().rev().copied().collect::<Vec<u8>>());
29482951
eprintln!(
29492952
"[ZipherX] DIAG witness rebuild: tree_size={}, root={}",
@@ -2964,37 +2967,35 @@ pub async fn rebuild_witnesses_if_needed(
29642967
);
29652968

29662969
// Try to get the actual blockchain root at chain tip for comparison
2967-
if let Ok(tip) = _header_store.get_latest_height() {
2968-
if let Some(tip_height) = tip {
2969-
if let Ok(Some(blockchain_root)) = _header_store.get_sapling_root(tip_height) {
2970-
let blockchain_hex = hex::encode(&blockchain_root);
2971-
let blockchain_rev_hex =
2972-
hex::encode(blockchain_root.iter().rev().copied().collect::<Vec<u8>>());
2973-
eprintln!(
2974-
"[ZipherX] DIAG: blockchain root at tip {}: {}",
2975-
tip_height, blockchain_hex,
2976-
);
2977-
eprintln!(
2978-
"[ZipherX] DIAG: blockchain root reversed: {}",
2979-
blockchain_rev_hex,
2980-
);
2981-
if root_hex == blockchain_hex
2982-
|| root_hex == blockchain_rev_hex
2983-
|| root_rev_hex == blockchain_hex
2984-
|| root_rev_hex == blockchain_rev_hex
2985-
{
2986-
eprintln!("[ZipherX] DIAG: *** ROOT MATCHES (byte order issue in contains_sapling_root) ***");
2987-
} else {
2988-
eprintln!(
2989-
"[ZipherX] DIAG: *** ROOT MISMATCH — delta CMUs incomplete or boost file corrupted ***",
2990-
);
2991-
}
2970+
if let Ok(Some(tip_height)) = _header_store.get_latest_height() {
2971+
if let Ok(Some(blockchain_root)) = _header_store.get_sapling_root(tip_height) {
2972+
let blockchain_hex = hex::encode(&blockchain_root);
2973+
let blockchain_rev_hex =
2974+
hex::encode(blockchain_root.iter().rev().copied().collect::<Vec<u8>>());
2975+
eprintln!(
2976+
"[ZipherX] DIAG: blockchain root at tip {}: {}",
2977+
tip_height, blockchain_hex,
2978+
);
2979+
eprintln!(
2980+
"[ZipherX] DIAG: blockchain root reversed: {}",
2981+
blockchain_rev_hex,
2982+
);
2983+
if root_hex == blockchain_hex
2984+
|| root_hex == blockchain_rev_hex
2985+
|| root_rev_hex == blockchain_hex
2986+
|| root_rev_hex == blockchain_rev_hex
2987+
{
2988+
eprintln!("[ZipherX] DIAG: *** ROOT MATCHES (byte order issue in contains_sapling_root) ***");
29922989
} else {
29932990
eprintln!(
2994-
"[ZipherX] DIAG: no sapling root in header store at tip {}",
2995-
tip_height
2991+
"[ZipherX] DIAG: *** ROOT MISMATCH — delta CMUs incomplete or boost file corrupted ***",
29962992
);
29972993
}
2994+
} else {
2995+
eprintln!(
2996+
"[ZipherX] DIAG: no sapling root in header store at tip {}",
2997+
tip_height
2998+
);
29982999
}
29993000
}
30003001
}
@@ -3613,7 +3614,7 @@ async fn boost_scan_if_needed(
36133614
.unwrap_or(&tree_data_for_validation);
36143615
match commitment_tree::root_from_serialized(tree_stripped) {
36153616
Ok(root_bytes) => {
3616-
let root_hex = hex::encode(&root_bytes);
3617+
let root_hex = hex::encode(root_bytes);
36173618
eprintln!(
36183619
"[ZipherX] DIAG tree root validation: boost tree root = {}",
36193620
root_hex,
@@ -3721,6 +3722,7 @@ async fn post_boost_delta_scan(
37213722
.map_err(|e| CoreError::Storage(e.to_string()))?;
37223723

37233724
// Build height → nullifiers map for CompactBlock reconstruction
3725+
#[allow(clippy::type_complexity)]
37243726
let mut nullifier_map: std::collections::BTreeMap<u64, Vec<(Vec<u8>, Vec<u8>)>> =
37253727
std::collections::BTreeMap::new();
37263728
for nf in &post_boost_nullifiers {
@@ -4207,19 +4209,25 @@ async fn post_boost_full_block_scan(
42074209
// RC-2: Spending key clone — zeroized after nullifier recompute.
42084210
let sk = sk_bytes.to_vec();
42094211
let db_clone = db.clone();
4210-
let notes_data: Vec<(Vec<u8>, Option<Vec<u8>>, u64, Option<Vec<u8>>, Option<u64>)> =
4211-
post_boost_notes
4212-
.iter()
4213-
.map(|n| {
4214-
(
4215-
n.cmu.clone(),
4216-
n.diversifier.clone(),
4217-
n.value,
4218-
n.rcm.clone(),
4219-
n.position,
4220-
)
4221-
})
4222-
.collect();
4212+
#[allow(clippy::type_complexity)]
4213+
let notes_data: Vec<(
4214+
Vec<u8>,
4215+
Option<Vec<u8>>,
4216+
u64,
4217+
Option<Vec<u8>>,
4218+
Option<u64>,
4219+
)> = post_boost_notes
4220+
.iter()
4221+
.map(|n| {
4222+
(
4223+
n.cmu.clone(),
4224+
n.diversifier.clone(),
4225+
n.value,
4226+
n.rcm.clone(),
4227+
n.position,
4228+
)
4229+
})
4230+
.collect();
42234231
let cmu_map = cmu_position_map;
42244232

42254233
let fixed_count = tokio::task::spawn_blocking(move || -> Result<u32, CoreError> {
@@ -4584,7 +4592,7 @@ async fn post_boost_full_block_scan(
45844592
}
45854593

45864594
for (txid_hex, (total_value, height)) in &spends_by_tx {
4587-
let block_ts = ts_map2.get(&(*height as u64)).map(|&t| t as u64);
4595+
let block_ts = ts_map2.get(height).map(|&t| t as u64);
45884596
let _ = db_clone.insert_transaction(
45894597
txid_hex,
45904598
*height,
@@ -4787,7 +4795,7 @@ async fn post_boost_full_block_scan(
47874795
// Get combined root
47884796
let combined_root = commitment_tree::root()
47894797
.map_err(|e| CoreError::Crypto(format!("Tree root: {e}")))?;
4790-
let combined_root_hex = hex::encode(&combined_root);
4798+
let combined_root_hex = hex::encode(combined_root);
47914799

47924800
eprintln!(
47934801
"[ZipherX] Combined tree: size={}, root={}",
@@ -5026,19 +5034,25 @@ async fn post_boost_full_block_scan(
50265034
// RC-2: Spending key clone — zeroized after nullifier recompute.
50275035
let sk = sk_bytes.to_vec();
50285036
let db_clone = db.clone();
5029-
let notes_data: Vec<(Vec<u8>, Option<Vec<u8>>, u64, Option<Vec<u8>>, Option<u64>)> =
5030-
post_boost_unspent
5031-
.iter()
5032-
.map(|n| {
5033-
(
5034-
n.cmu.clone(),
5035-
n.diversifier.clone(),
5036-
n.value,
5037-
n.rcm.clone(),
5038-
n.position,
5039-
)
5040-
})
5041-
.collect();
5037+
#[allow(clippy::type_complexity)]
5038+
let notes_data: Vec<(
5039+
Vec<u8>,
5040+
Option<Vec<u8>>,
5041+
u64,
5042+
Option<Vec<u8>>,
5043+
Option<u64>,
5044+
)> = post_boost_unspent
5045+
.iter()
5046+
.map(|n| {
5047+
(
5048+
n.cmu.clone(),
5049+
n.diversifier.clone(),
5050+
n.value,
5051+
n.rcm.clone(),
5052+
n.position,
5053+
)
5054+
})
5055+
.collect();
50425056
let cmu_map = cmu_position_map;
50435057

50445058
let fixed_count = tokio::task::spawn_blocking(move || -> Result<u32, CoreError> {
@@ -5473,6 +5487,7 @@ async fn scan_blocks_for_pending_txs(
54735487
/// Groups DeltaOutput records by block height and includes nullifier spends
54745488
/// from the height-indexed map. Used by the catch-up scan to feed delta
54755489
/// store data into the block scanner.
5490+
#[allow(clippy::type_complexity)]
54765491
fn reconstruct_compact_blocks(
54775492
outputs: &[DeltaOutput],
54785493
nullifier_map: &std::collections::BTreeMap<u64, Vec<(Vec<u8>, Vec<u8>)>>,

crates/zipherx-core/src/async_wallet.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ impl AsyncWallet {
116116
let mut pm = self.peer_manager.lock().await;
117117
pm.connect_with_counter(Some(&self.connected_peer_count))
118118
.await
119-
.map_err(|e| CoreError::Network(e))?;
119+
.map_err(CoreError::Network)?;
120120
// Final update in case connect_with_counter missed any edge case
121121
self.connected_peer_count
122122
.store(pm.connected_count() as u32, Ordering::Relaxed);

crates/zipherx-core/src/mempool_monitor.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
//! - Peer receives "inv" MSG_TX → sends getdata → receives "tx" response
55
//! - Block listener fires `on_mempool_tx_data` callback with raw TX bytes
66
//! - This module trial-decrypts Sapling outputs and notifies the UI
7+
//!
78
//! No separate task, no channel, no extra TCP connection.
89
910
use std::collections::HashSet;

0 commit comments

Comments
 (0)