diff --git a/zebra-chain/src/block.rs b/zebra-chain/src/block.rs index a6bc147bd..a9b3b133b 100644 --- a/zebra-chain/src/block.rs +++ b/zebra-chain/src/block.rs @@ -132,24 +132,21 @@ impl Block { pub fn sprout_nullifiers(&self) -> impl Iterator { self.transactions .iter() - .map(|transaction| transaction.sprout_nullifiers()) - .flatten() + .flat_map(|transaction| transaction.sprout_nullifiers()) } /// Access the [`sapling::Nullifier`]s from all transactions in this block. pub fn sapling_nullifiers(&self) -> impl Iterator { self.transactions .iter() - .map(|transaction| transaction.sapling_nullifiers()) - .flatten() + .flat_map(|transaction| transaction.sapling_nullifiers()) } /// Access the [`orchard::Nullifier`]s from all transactions in this block. pub fn orchard_nullifiers(&self) -> impl Iterator { self.transactions .iter() - .map(|transaction| transaction.orchard_nullifiers()) - .flatten() + .flat_map(|transaction| transaction.orchard_nullifiers()) } /// Count how many Sapling transactions exist in a block, diff --git a/zebra-chain/src/block/merkle.rs b/zebra-chain/src/block/merkle.rs index 270c0ae00..6a5f70a90 100644 --- a/zebra-chain/src/block/merkle.rs +++ b/zebra-chain/src/block/merkle.rs @@ -184,7 +184,7 @@ where .map(|tx| { tx.as_ref() .auth_digest() - .unwrap_or_else(|| transaction::AuthDigest([0xFF; 32])) + .unwrap_or(transaction::AuthDigest([0xFF; 32])) }) .collect() } diff --git a/zebra-chain/src/primitives/redpallas/scalar_mul.rs b/zebra-chain/src/primitives/redpallas/scalar_mul.rs index 88581cdf0..b528b4aaf 100644 --- a/zebra-chain/src/primitives/redpallas/scalar_mul.rs +++ b/zebra-chain/src/primitives/redpallas/scalar_mul.rs @@ -92,14 +92,13 @@ impl NonAdjacentForm for pallas::Scalar { // Construct a buffer of bits of the scalar, starting at bit `pos` let u64_idx = pos / 64; let bit_idx = pos % 64; - let bit_buf: u64; - if bit_idx < 64 - w { + let bit_buf: u64 = if bit_idx < 64 - w { // This window's bits are contained in a single u64 - bit_buf = x_u64[u64_idx] >> bit_idx; + x_u64[u64_idx] >> bit_idx } else { // Combine the current u64's bits with the bits from the next u64 - bit_buf = (x_u64[u64_idx] >> bit_idx) | (x_u64[1 + u64_idx] << (64 - bit_idx)); - } + (x_u64[u64_idx] >> bit_idx) | (x_u64[1 + u64_idx] << (64 - bit_idx)) + }; // Add the carry into the current window let window = carry + (bit_buf & window_mask); diff --git a/zebra-chain/src/sapling/commitment.rs b/zebra-chain/src/sapling/commitment.rs index 8d0cc56c7..9c232b3bb 100644 --- a/zebra-chain/src/sapling/commitment.rs +++ b/zebra-chain/src/sapling/commitment.rs @@ -116,12 +116,12 @@ impl NoteCommitment { // // The `TryFrom` impls for the `jubjub::*Point`s handles // calling `DiversifyHash` implicitly. - let g_d_bytes: [u8; 32]; - if let Ok(g_d) = jubjub::AffinePoint::try_from(diversifier) { - g_d_bytes = g_d.to_bytes(); + + let g_d_bytes: [u8; 32] = if let Ok(g_d) = jubjub::AffinePoint::try_from(diversifier) { + g_d.to_bytes() } else { return None; - } + }; let pk_d_bytes = <[u8; 32]>::from(transmission_key); let v_bytes = value.to_bytes(); diff --git a/zebra-chain/src/transaction.rs b/zebra-chain/src/transaction.rs index 2f58e4fe4..dcf433e68 100644 --- a/zebra-chain/src/transaction.rs +++ b/zebra-chain/src/transaction.rs @@ -871,8 +871,7 @@ impl Transaction { pub fn orchard_actions(&self) -> impl Iterator { self.orchard_shielded_data() .into_iter() - .map(orchard::ShieldedData::actions) - .flatten() + .flat_map(orchard::ShieldedData::actions) } /// Access the [`orchard::Nullifier`]s in this transaction, if there are any, @@ -880,8 +879,7 @@ impl Transaction { pub fn orchard_nullifiers(&self) -> impl Iterator { self.orchard_shielded_data() .into_iter() - .map(orchard::ShieldedData::nullifiers) - .flatten() + .flat_map(orchard::ShieldedData::nullifiers) } /// Access the note commitments in this transaction, if there are any, @@ -889,8 +887,7 @@ impl Transaction { pub fn orchard_note_commitments(&self) -> impl Iterator { self.orchard_shielded_data() .into_iter() - .map(orchard::ShieldedData::note_commitments) - .flatten() + .flat_map(orchard::ShieldedData::note_commitments) } /// Access the [`orchard::Flags`] in this transaction, if there is any, diff --git a/zebra-chain/src/transaction/arbitrary.rs b/zebra-chain/src/transaction/arbitrary.rs index b818e19a1..356329fae 100644 --- a/zebra-chain/src/transaction/arbitrary.rs +++ b/zebra-chain/src/transaction/arbitrary.rs @@ -847,8 +847,7 @@ pub fn transaction_to_fake_v5( expiry_height: height, sapling_shielded_data: sapling_shielded_data .clone() - .map(sapling_shielded_v4_to_fake_v5) - .flatten(), + .and_then(sapling_shielded_v4_to_fake_v5), orchard_shielded_data: None, }, v5 @ V5 { .. } => v5.clone(), diff --git a/zebra-chain/src/transaction/memo.rs b/zebra-chain/src/transaction/memo.rs index c5f0a76ee..9048dc33a 100644 --- a/zebra-chain/src/transaction/memo.rs +++ b/zebra-chain/src/transaction/memo.rs @@ -34,15 +34,13 @@ impl<'a> TryFrom<&'a [u8]> for Memo { impl fmt::Debug for Memo { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - let output: String; - // This saves work but if the 'valid utf8 string' is just a // bunch of numbers, it prints them out like // 'Memo("\u{0}\u{0}..")', so. ¯\_(ツ)_/¯ - match std::str::from_utf8(&self.0[..]) { - Ok(memo) => output = String::from(memo), - _ => output = hex::encode(&self.0[..]), - } + let output: String = match std::str::from_utf8(&self.0[..]) { + Ok(memo) => String::from(memo), + _ => hex::encode(&self.0[..]), + }; f.debug_tuple("Memo").field(&output).finish() } diff --git a/zebra-chain/src/transparent/tests/vectors.rs b/zebra-chain/src/transparent/tests/vectors.rs index 1218b796a..fa9fd262c 100644 --- a/zebra-chain/src/transparent/tests/vectors.rs +++ b/zebra-chain/src/transparent/tests/vectors.rs @@ -7,7 +7,7 @@ fn parse_coinbase_height_mins() { // examples with height 1: let case1 = vec![0x51]; - assert!(!parse_coinbase_height(case1.clone()).is_err()); + assert!(parse_coinbase_height(case1.clone()).is_ok()); assert_eq!(parse_coinbase_height(case1).unwrap().0 .0, 1); let case2 = vec![0x01, 0x01]; @@ -25,7 +25,7 @@ fn parse_coinbase_height_mins() { // examples with height 17: let case1 = vec![0x01, 0x11]; - assert!(!parse_coinbase_height(case1.clone()).is_err()); + assert!(parse_coinbase_height(case1.clone()).is_ok()); assert_eq!(parse_coinbase_height(case1).unwrap().0 .0, 17); let case2 = vec![0x02, 0x11, 0x00]; diff --git a/zebra-network/src/meta_addr/tests/prop.rs b/zebra-network/src/meta_addr/tests/prop.rs index 88179c738..1a5174e06 100644 --- a/zebra-network/src/meta_addr/tests/prop.rs +++ b/zebra-network/src/meta_addr/tests/prop.rs @@ -344,9 +344,7 @@ proptest! { // If `change` is invalid for the current MetaAddr state, skip it. // If we've run out of changes for this addr, do nothing. - if let Some(changed_addr) = change - .map(|change| change.apply_to_meta_addr(*addr)) - .flatten() + if let Some(changed_addr) = change.and_then(|change| change.apply_to_meta_addr(*addr)) { prop_assert_eq!(changed_addr.addr, addr.addr); *addr = changed_addr; diff --git a/zebra-state/src/config.rs b/zebra-state/src/config.rs index 009b2789b..59e7c9bb9 100644 --- a/zebra-state/src/config.rs +++ b/zebra-state/src/config.rs @@ -157,13 +157,12 @@ impl Config { } // Try the hard limit or the minimum, whichever is greater - let min_limit = if let Some(hard_limit) = - hard_rlimit.map(TryInto::try_into).map(Result::ok).flatten() - { - std::cmp::max(Config::MIN_OPEN_FILE_LIMIT, hard_limit) - } else { - Config::MIN_OPEN_FILE_LIMIT - }; + let min_limit = + if let Some(hard_limit) = hard_rlimit.map(TryInto::try_into).and_then(Result::ok) { + std::cmp::max(Config::MIN_OPEN_FILE_LIMIT, hard_limit) + } else { + Config::MIN_OPEN_FILE_LIMIT + }; if let Ok(actual_limit) = Config::set_open_file_limit(min_limit, hard_rlimit, old_limit) { tracing::warn!(?actual_limit, ?hard_rlimit, diff --git a/zebra-state/src/service.rs b/zebra-state/src/service.rs index ff0cc883e..14b56535f 100644 --- a/zebra-state/src/service.rs +++ b/zebra-state/src/service.rs @@ -473,7 +473,7 @@ impl StateService { (max_height - 1).expect("max_len is at least 1") }; - let stop_height = stop.map(|hash| self.best_height_by_hash(hash)).flatten(); + let stop_height = stop.and_then(|hash| self.best_height_by_hash(hash)); // Compute the final height, making sure it is: // * at or below our chain tip, and diff --git a/zebra-state/src/service/finalized_state.rs b/zebra-state/src/service/finalized_state.rs index d3e025aeb..7d5b9f18f 100644 --- a/zebra-state/src/service/finalized_state.rs +++ b/zebra-state/src/service/finalized_state.rs @@ -542,8 +542,7 @@ impl FinalizedState { let (finalized, rsp_tx) = queued_block; let result = self.commit_finalized_direct(finalized.clone(), "CommitFinalized request"); - let block_result; - if result.is_ok() { + let block_result = if result.is_ok() { metrics::counter!("state.checkpoint.finalized.block.count", 1); metrics::gauge!( "state.checkpoint.finalized.block.height", @@ -556,7 +555,7 @@ impl FinalizedState { metrics::gauge!("zcash.chain.verified.block.height", finalized.height.0 as _); metrics::counter!("zcash.chain.verified.block.total", 1); - block_result = Ok(finalized); + Ok(finalized) } else { metrics::counter!("state.checkpoint.error.block.count", 1); metrics::gauge!( @@ -564,8 +563,8 @@ impl FinalizedState { finalized.height.0 as _ ); - block_result = Err(()); - } + Err(()) + }; let _ = rsp_tx.send(result.map_err(Into::into));