diff --git a/zebra-chain/src/block/height.rs b/zebra-chain/src/block/height.rs index 70bc17e8..1b5b3408 100644 --- a/zebra-chain/src/block/height.rs +++ b/zebra-chain/src/block/height.rs @@ -82,7 +82,11 @@ impl TryFrom for Height { /// Checks that the `height` is within the valid [`Height`] range. fn try_from(height: u32) -> Result { // Check the bounds. - if Height::MIN.0 <= height && height <= Height::MAX.0 { + // + // Clippy warns that `height >= Height::MIN.0` is always true. + assert_eq!(Height::MIN.0, 0); + + if height <= Height::MAX.0 { Ok(Height(height)) } else { Err("heights must be less than or equal to Height::MAX") diff --git a/zebra-chain/src/block/merkle.rs b/zebra-chain/src/block/merkle.rs index 9f1ef0d4..42762bbe 100644 --- a/zebra-chain/src/block/merkle.rs +++ b/zebra-chain/src/block/merkle.rs @@ -486,7 +486,7 @@ mod tests { // Compute the AuthDataRoot with a single [0xFF; 32] digest. // Since ZIP-244 specifies that this value must be used as the auth digest of // pre-V5 transactions, then the roots must match. - let expect_auth_root = vec![AuthDigest([0xFF; 32])] + let expect_auth_root = [AuthDigest([0xFF; 32])] .iter() .copied() .collect::(); diff --git a/zebra-chain/src/orchard/note/ciphertexts.rs b/zebra-chain/src/orchard/note/ciphertexts.rs index 72cfeb98..8f857cf1 100644 --- a/zebra-chain/src/orchard/note/ciphertexts.rs +++ b/zebra-chain/src/orchard/note/ciphertexts.rs @@ -1,3 +1,5 @@ +//! Encrypted parts of Orchard notes. + use std::{fmt, io}; use serde_big_array::BigArray; @@ -17,9 +19,7 @@ impl Copy for EncryptedNote {} impl Clone for EncryptedNote { fn clone(&self) -> Self { - let mut bytes = [0; 580]; - bytes[..].copy_from_slice(&self.0[..]); - Self(bytes) + *self } } @@ -86,9 +86,7 @@ impl Copy for WrappedNoteKey {} impl Clone for WrappedNoteKey { fn clone(&self) -> Self { - let mut bytes = [0; 80]; - bytes[..].copy_from_slice(&self.0[..]); - Self(bytes) + *self } } diff --git a/zebra-chain/src/primitives/proofs/bctv14.rs b/zebra-chain/src/primitives/proofs/bctv14.rs index abef3853..ac1f6d5f 100644 --- a/zebra-chain/src/primitives/proofs/bctv14.rs +++ b/zebra-chain/src/primitives/proofs/bctv14.rs @@ -25,9 +25,7 @@ impl Copy for Bctv14Proof {} impl Clone for Bctv14Proof { fn clone(&self) -> Self { - let mut bytes = [0; 296]; - bytes[..].copy_from_slice(&self.0[..]); - Self(bytes) + *self } } diff --git a/zebra-chain/src/primitives/proofs/groth16.rs b/zebra-chain/src/primitives/proofs/groth16.rs index 8153b2fb..43f661a3 100644 --- a/zebra-chain/src/primitives/proofs/groth16.rs +++ b/zebra-chain/src/primitives/proofs/groth16.rs @@ -25,9 +25,7 @@ impl Copy for Groth16Proof {} impl Clone for Groth16Proof { fn clone(&self) -> Self { - let mut bytes = [0; 192]; - bytes[..].copy_from_slice(&self.0[..]); - Self(bytes) + *self } } diff --git a/zebra-chain/src/sapling/note/ciphertexts.rs b/zebra-chain/src/sapling/note/ciphertexts.rs index 47fe5606..472dbfb0 100644 --- a/zebra-chain/src/sapling/note/ciphertexts.rs +++ b/zebra-chain/src/sapling/note/ciphertexts.rs @@ -1,3 +1,5 @@ +//! Encrypted parts of Sapling notes. + use std::{fmt, io}; use serde_big_array::BigArray; @@ -24,9 +26,7 @@ impl Copy for EncryptedNote {} impl Clone for EncryptedNote { fn clone(&self) -> Self { - let mut bytes = [0; 580]; - bytes[..].copy_from_slice(&self.0[..]); - Self(bytes) + *self } } @@ -73,9 +73,7 @@ impl Copy for WrappedNoteKey {} impl Clone for WrappedNoteKey { fn clone(&self) -> Self { - let mut bytes = [0; 80]; - bytes[..].copy_from_slice(&self.0[..]); - Self(bytes) + *self } } diff --git a/zebra-chain/src/sprout/note/ciphertexts.rs b/zebra-chain/src/sprout/note/ciphertexts.rs index 37628c2c..7fd3bb42 100644 --- a/zebra-chain/src/sprout/note/ciphertexts.rs +++ b/zebra-chain/src/sprout/note/ciphertexts.rs @@ -1,3 +1,5 @@ +//! Encrypted parts of Sprout notes. + use std::{fmt, io}; use serde::{Deserialize, Serialize}; @@ -25,9 +27,7 @@ impl Copy for EncryptedNote {} impl Clone for EncryptedNote { fn clone(&self) -> Self { - let mut bytes = [0; 601]; - bytes[..].copy_from_slice(&self.0[..]); - Self(bytes) + *self } } diff --git a/zebra-chain/src/transaction/serialize.rs b/zebra-chain/src/transaction/serialize.rs index f79244da..e083921b 100644 --- a/zebra-chain/src/transaction/serialize.rs +++ b/zebra-chain/src/transaction/serialize.rs @@ -268,15 +268,15 @@ impl ZcashDeserialize for Option> { // Create shielded spends from deserialized parts let spends: Vec<_> = spend_prefixes .into_iter() - .zip(spend_proofs.into_iter()) - .zip(spend_sigs.into_iter()) + .zip(spend_proofs) + .zip(spend_sigs) .map(|((prefix, proof), sig)| Spend::::from_v5_parts(prefix, proof, sig)) .collect(); // Create shielded outputs from deserialized parts let outputs = output_prefixes .into_iter() - .zip(output_proofs.into_iter()) + .zip(output_proofs) .map(|(prefix, proof)| Output::from_v5_parts(prefix, proof)) .collect(); @@ -427,7 +427,7 @@ impl ZcashDeserialize for Option { // Create the AuthorizedAction from deserialized parts let authorized_actions: Vec = actions .into_iter() - .zip(sigs.into_iter()) + .zip(sigs) .map(|(action, spend_auth_sig)| { orchard::AuthorizedAction::from_parts(action, spend_auth_sig) }) diff --git a/zebra-chain/src/value_balance/tests/prop.rs b/zebra-chain/src/value_balance/tests/prop.rs index 9ee2fb1e..24882415 100644 --- a/zebra-chain/src/value_balance/tests/prop.rs +++ b/zebra-chain/src/value_balance/tests/prop.rs @@ -79,7 +79,7 @@ proptest! { ) { let _init_guard = zebra_test::init(); - let collection = vec![value_balance1, value_balance2]; + let collection = [value_balance1, value_balance2]; let transparent = value_balance1.transparent + value_balance2.transparent; let sprout = value_balance1.sprout + value_balance2.sprout; diff --git a/zebra-chain/src/work/equihash.rs b/zebra-chain/src/work/equihash.rs index 731d9497..e8b73b16 100644 --- a/zebra-chain/src/work/equihash.rs +++ b/zebra-chain/src/work/equihash.rs @@ -87,9 +87,7 @@ impl Copy for Solution {} impl Clone for Solution { fn clone(&self) -> Self { - let mut bytes = [0; SOLUTION_SIZE]; - bytes[..].copy_from_slice(&self.0[..]); - Self(bytes) + *self } } diff --git a/zebra-consensus/src/checkpoint/list/tests.rs b/zebra-consensus/src/checkpoint/list/tests.rs index 9ad1febe..da07c689 100644 --- a/zebra-consensus/src/checkpoint/list/tests.rs +++ b/zebra-consensus/src/checkpoint/list/tests.rs @@ -103,7 +103,7 @@ fn checkpoint_list_no_genesis_fail() -> Result<(), BoxError> { fn checkpoint_list_null_hash_fail() -> Result<(), BoxError> { let _init_guard = zebra_test::init(); - let checkpoint_data = vec![(block::Height(0), block::Hash([0; 32]))]; + let checkpoint_data = [(block::Height(0), block::Hash([0; 32]))]; // Make a checkpoint list containing the non-genesis block let checkpoint_list: BTreeMap = @@ -119,7 +119,7 @@ fn checkpoint_list_null_hash_fail() -> Result<(), BoxError> { fn checkpoint_list_bad_height_fail() -> Result<(), BoxError> { let _init_guard = zebra_test::init(); - let checkpoint_data = vec![( + let checkpoint_data = [( block::Height(block::Height::MAX.0 + 1), block::Hash([1; 32]), )]; @@ -131,7 +131,7 @@ fn checkpoint_list_bad_height_fail() -> Result<(), BoxError> { "a checkpoint list with an invalid block height (block::Height::MAX + 1) should fail", ); - let checkpoint_data = vec![(block::Height(u32::MAX), block::Hash([1; 32]))]; + let checkpoint_data = [(block::Height(u32::MAX), block::Hash([1; 32]))]; // Make a checkpoint list containing the non-genesis block let checkpoint_list: BTreeMap = diff --git a/zebra-consensus/src/checkpoint/tests.rs b/zebra-consensus/src/checkpoint/tests.rs index 2dbefab1..9fb29048 100644 --- a/zebra-consensus/src/checkpoint/tests.rs +++ b/zebra-consensus/src/checkpoint/tests.rs @@ -254,7 +254,7 @@ async fn continuous_blockchain( // - checkpoints start at genesis // - checkpoints end at the end of the range (there's no point in having extra blocks) let expected_max_height = block::Height((blockchain_len - 1).try_into().unwrap()); - let checkpoint_list = vec![ + let checkpoint_list = [ &blockchain[0], &blockchain[blockchain_len / 3], &blockchain[blockchain_len / 2], diff --git a/zebra-consensus/src/transaction/tests.rs b/zebra-consensus/src/transaction/tests.rs index aad20783..87ce0f7e 100644 --- a/zebra-consensus/src/transaction/tests.rs +++ b/zebra-consensus/src/transaction/tests.rs @@ -782,7 +782,9 @@ async fn state_error_converted_correctly() { "expected matching state and transaction errors" ); - let TransactionError::ValidateContextError(propagated_validate_context_error) = transaction_error else { + let TransactionError::ValidateContextError(propagated_validate_context_error) = + transaction_error + else { panic!("should be a ValidateContextError variant"); }; diff --git a/zebra-network/src/config.rs b/zebra-network/src/config.rs index 49798137..15922f81 100644 --- a/zebra-network/src/config.rs +++ b/zebra-network/src/config.rs @@ -228,10 +228,7 @@ impl Config { // Ignore disk errors because the cache is optional and the method already logs them. let disk_peers = self.load_peer_cache().await.unwrap_or_default(); - dns_peers - .into_iter() - .chain(disk_peers.into_iter()) - .collect() + dns_peers.into_iter().chain(disk_peers).collect() } /// Concurrently resolves `peers` into zero or more IP addresses, with a diff --git a/zebra-network/src/peer/connection.rs b/zebra-network/src/peer/connection.rs index 71838366..22660858 100644 --- a/zebra-network/src/peer/connection.rs +++ b/zebra-network/src/peer/connection.rs @@ -1531,8 +1531,8 @@ where /// to be disconnected. fn overload_drop_connection_probability(now: Instant, prev: Option) -> f32 { let Some(prev) = prev else { - return MIN_OVERLOAD_DROP_PROBABILITY; - }; + return MIN_OVERLOAD_DROP_PROBABILITY; + }; let protection_fraction_since_last_overload = (now - prev).as_secs_f32() / OVERLOAD_PROTECTION_INTERVAL.as_secs_f32(); diff --git a/zebra-network/src/peer/handshake.rs b/zebra-network/src/peer/handshake.rs index 01cfe98e..692c9f56 100644 --- a/zebra-network/src/peer/handshake.rs +++ b/zebra-network/src/peer/handshake.rs @@ -1160,7 +1160,7 @@ pub(crate) async fn register_inventory_status( let _ = inv_collector .send(InventoryChange::new_available(*advertised, transient_addr)); } - [advertised @ ..] => { + advertised => { let advertised = advertised .iter() .filter(|advertised| advertised.unmined_tx_id().is_some()); diff --git a/zebra-network/src/protocol/external/codec/tests/vectors.rs b/zebra-network/src/protocol/external/codec/tests/vectors.rs index 89c6b08f..74f46ec7 100644 --- a/zebra-network/src/protocol/external/codec/tests/vectors.rs +++ b/zebra-network/src/protocol/external/codec/tests/vectors.rs @@ -467,12 +467,13 @@ fn version_user_agent_size_limits() { // Encode the rest of the message onto `bytes` (relay should be optional) { let Message::Version(VersionMessage { - user_agent, - start_height, - .. - }) = invalid_version_message else { - unreachable!("version_message is a version"); - }; + user_agent, + start_height, + .. + }) = invalid_version_message + else { + unreachable!("version_message is a version"); + }; user_agent .zcash_serialize(&mut writer) @@ -553,7 +554,8 @@ fn reject_command_and_reason_size_limits() { ccode, reason, data, - } = invalid_reject_message else { + } = invalid_reject_message + else { unreachable!("invalid_reject_message is a reject"); }; diff --git a/zebra-rpc/src/methods/get_block_template_rpcs.rs b/zebra-rpc/src/methods/get_block_template_rpcs.rs index 5f0ff5ce..ca861e54 100644 --- a/zebra-rpc/src/methods/get_block_template_rpcs.rs +++ b/zebra-rpc/src/methods/get_block_template_rpcs.rs @@ -521,15 +521,15 @@ where // // Optional TODO: // - add a `MempoolChange` type with an `async changed()` method (like `ChainTip`) - let Some(mempool_txs) = - fetch_mempool_transactions(mempool.clone(), tip_hash) - .await? - // If the mempool and state responses are out of sync: - // - if we are not long polling, omit mempool transactions from the template, - // - if we are long polling, continue to the next iteration of the loop to make fresh state and mempool requests. - .or_else(|| client_long_poll_id.is_none().then(Vec::new)) else { - continue; - }; + let Some(mempool_txs) = fetch_mempool_transactions(mempool.clone(), tip_hash) + .await? + // If the mempool and state responses are out of sync: + // - if we are not long polling, omit mempool transactions from the template, + // - if we are long polling, continue to the next iteration of the loop to make fresh state and mempool requests. + .or_else(|| client_long_poll_id.is_none().then(Vec::new)) + else { + continue; + }; // - Long poll ID calculation let server_long_poll_id = LongPollInput::new( diff --git a/zebra-rpc/src/methods/get_block_template_rpcs/get_block_template.rs b/zebra-rpc/src/methods/get_block_template_rpcs/get_block_template.rs index 04a3fa9c..0e496ad3 100644 --- a/zebra-rpc/src/methods/get_block_template_rpcs/get_block_template.rs +++ b/zebra-rpc/src/methods/get_block_template_rpcs/get_block_template.rs @@ -39,8 +39,8 @@ pub use crate::methods::get_block_template_rpcs::types::get_block_template::*; /// Returns an error if there's a mismatch between the mode and whether `data` is provided. pub fn check_parameters(parameters: &Option) -> Result<()> { let Some(parameters) = parameters else { - return Ok(()) - }; + return Ok(()); + }; match parameters { JsonParameters { @@ -267,7 +267,8 @@ where let mempool::Response::FullTransactions { transactions, last_seen_tip_hash, - } = response else { + } = response + else { unreachable!("unmatched response to a mempool::FullTransactions request") }; diff --git a/zebra-rpc/src/methods/tests/snapshot/get_block_template_rpcs.rs b/zebra-rpc/src/methods/tests/snapshot/get_block_template_rpcs.rs index f941b7e2..ab57b7b1 100644 --- a/zebra-rpc/src/methods/tests/snapshot/get_block_template_rpcs.rs +++ b/zebra-rpc/src/methods/tests/snapshot/get_block_template_rpcs.rs @@ -286,10 +286,11 @@ pub async fn test_responses( mock_read_state_request_handler, ); - let get_block_template::Response::TemplateMode(get_block_template) = get_block_template - .expect("unexpected error in getblocktemplate RPC call") else { - panic!("this getblocktemplate call without parameters should return the `TemplateMode` variant of the response") - }; + let get_block_template::Response::TemplateMode(get_block_template) = + get_block_template.expect("unexpected error in getblocktemplate RPC call") + else { + panic!("this getblocktemplate call without parameters should return the `TemplateMode` variant of the response") + }; let coinbase_tx: Transaction = get_block_template .coinbase_txn @@ -330,10 +331,11 @@ pub async fn test_responses( mock_read_state_request_handler, ); - let get_block_template::Response::TemplateMode(get_block_template) = get_block_template - .expect("unexpected error in getblocktemplate RPC call") else { - panic!("this getblocktemplate call without parameters should return the `TemplateMode` variant of the response") - }; + let get_block_template::Response::TemplateMode(get_block_template) = + get_block_template.expect("unexpected error in getblocktemplate RPC call") + else { + panic!("this getblocktemplate call without parameters should return the `TemplateMode` variant of the response") + }; let coinbase_tx: Transaction = get_block_template .coinbase_txn diff --git a/zebra-rpc/src/methods/tests/vectors.rs b/zebra-rpc/src/methods/tests/vectors.rs index 255acafd..b5892a35 100644 --- a/zebra-rpc/src/methods/tests/vectors.rs +++ b/zebra-rpc/src/methods/tests/vectors.rs @@ -457,7 +457,12 @@ async fn rpc_getrawtransaction() { } let (response, _) = futures::join!(get_tx_verbose_1_req, make_mempool_req(tx_hash)); - let GetRawTransaction::Object { hex, height, confirmations } = response.expect("We should have a GetRawTransaction struct") else { + let GetRawTransaction::Object { + hex, + height, + confirmations, + } = response.expect("We should have a GetRawTransaction struct") + else { unreachable!("Should return a Raw enum") }; @@ -1291,10 +1296,11 @@ async fn rpc_getblocktemplate_mining_address(use_p2pkh: bool) { make_mock_read_state_request_handler(), ); - let get_block_template::Response::TemplateMode(get_block_template) = get_block_template - .expect("unexpected error in getblocktemplate RPC call") else { - panic!("this getblocktemplate call without parameters should return the `TemplateMode` variant of the response") - }; + let get_block_template::Response::TemplateMode(get_block_template) = + get_block_template.expect("unexpected error in getblocktemplate RPC call") + else { + panic!("this getblocktemplate call without parameters should return the `TemplateMode` variant of the response") + }; assert_eq!( get_block_template.capabilities, @@ -1456,10 +1462,11 @@ async fn rpc_getblocktemplate_mining_address(use_p2pkh: bool) { make_mock_read_state_request_handler(), ); - let get_block_template::Response::TemplateMode(get_block_template) = get_block_template - .expect("unexpected error in getblocktemplate RPC call") else { - panic!("this getblocktemplate call without parameters should return the `TemplateMode` variant of the response") - }; + let get_block_template::Response::TemplateMode(get_block_template) = + get_block_template.expect("unexpected error in getblocktemplate RPC call") + else { + panic!("this getblocktemplate call without parameters should return the `TemplateMode` variant of the response") + }; // mempool transactions should be omitted if the tip hash in the GetChainInfo response from the state // does not match the `last_seen_tip_hash` in the FullTransactions response from the mempool. diff --git a/zebra-state/src/service/read/address/tx_id.rs b/zebra-state/src/service/read/address/tx_id.rs index 560f7b10..27b9a9b3 100644 --- a/zebra-state/src/service/read/address/tx_id.rs +++ b/zebra-state/src/service/read/address/tx_id.rs @@ -276,8 +276,5 @@ fn apply_tx_id_changes( ) -> BTreeMap { // Correctness: compensate for inconsistent tx IDs finalized blocks across multiple addresses, // by combining them with overlapping non-finalized block tx IDs. - finalized_tx_ids - .into_iter() - .chain(chain_tx_ids.into_iter()) - .collect() + finalized_tx_ids.into_iter().chain(chain_tx_ids).collect() } diff --git a/zebra-state/src/service/read/address/utxo.rs b/zebra-state/src/service/read/address/utxo.rs index 7ee5cb4f..30bcad2c 100644 --- a/zebra-state/src/service/read/address/utxo.rs +++ b/zebra-state/src/service/read/address/utxo.rs @@ -370,7 +370,7 @@ fn apply_utxo_changes( // to compensate for overlapping finalized and non-finalized blocks. finalized_utxos .into_iter() - .chain(created_chain_utxos.into_iter()) + .chain(created_chain_utxos) .filter(|(utxo_location, _output)| !spent_chain_utxos.contains(utxo_location)) .collect() } diff --git a/zebra-test/src/mock_service.rs b/zebra-test/src/mock_service.rs index d92e6f8b..25f37903 100644 --- a/zebra-test/src/mock_service.rs +++ b/zebra-test/src/mock_service.rs @@ -146,6 +146,7 @@ pub struct ResponseSender { impl Service for MockService where + Request: Send + 'static, Response: Send + 'static, Error: Send + 'static, { diff --git a/zebra-utils/src/bin/search-issue-refs/main.rs b/zebra-utils/src/bin/search-issue-refs/main.rs index 2af6a707..cc71ee19 100644 --- a/zebra-utils/src/bin/search-issue-refs/main.rs +++ b/zebra-utils/src/bin/search-issue-refs/main.rs @@ -288,11 +288,7 @@ to create a github token." let mut num_closed_issues = 0; while let Some(res) = github_api_requests.join_next().await { - let Ok(( - res, - id, - issue_refs, - )) = res else { + let Ok((res, id, issue_refs)) = res else { println!("warning: failed to join api request thread/task"); continue; }; diff --git a/zebrad/tests/common/checkpoints.rs b/zebrad/tests/common/checkpoints.rs index b083d212..cc5e6be4 100644 --- a/zebrad/tests/common/checkpoints.rs +++ b/zebrad/tests/common/checkpoints.rs @@ -303,7 +303,7 @@ impl ZebraCheckpointsTestDirExt for TempDir { let zebra_checkpoints = self.spawn_child_with_command(zebra_checkpoints_path, args.clone()); - let Err(system_path_error) = zebra_checkpoints else { + let Err(system_path_error) = zebra_checkpoints else { return zebra_checkpoints; };