From bf1efc399ea47280d2dd38d8946a5e18021ebe47 Mon Sep 17 00:00:00 2001 From: Joseph Livesey Date: Sun, 17 Sep 2023 10:44:18 -0400 Subject: [PATCH 1/7] Fix 'derivable_impls' clippy warning Signed-off-by: Joseph Livesey --- validator/src/journal/block_wrapper.rs | 9 ++------- validator/src/metrics/mod.rs | 9 ++------- 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/validator/src/journal/block_wrapper.rs b/validator/src/journal/block_wrapper.rs index e2911de315..55269b7eb5 100644 --- a/validator/src/journal/block_wrapper.rs +++ b/validator/src/journal/block_wrapper.rs @@ -21,8 +21,9 @@ use std::fmt; use cpython::{self, ObjectProtocol, PyClone, PyObject}; -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Default, Clone, PartialEq, Eq)] pub enum BlockStatus { + #[default] Unknown = 0, Invalid = 1, Valid = 2, @@ -30,12 +31,6 @@ pub enum BlockStatus { InValidation = 5, } -impl Default for BlockStatus { - fn default() -> Self { - BlockStatus::Unknown - } -} - #[derive(Debug)] pub struct BlockWrapper { pub(super) py_block_wrapper: PyObject, diff --git a/validator/src/metrics/mod.rs b/validator/src/metrics/mod.rs index f212a61338..b3913ae522 100644 --- a/validator/src/metrics/mod.rs +++ b/validator/src/metrics/mod.rs @@ -32,17 +32,12 @@ pub fn get_collector>(name: S) -> MetricsCollectorHandle { } } -#[derive(Copy, Clone)] +#[derive(Copy, Clone, Default)] pub enum Level { + #[default] Info, } -impl Default for Level { - fn default() -> Self { - Level::Info - } -} - fn into_level_str(level: Level) -> &'static str { use self::Level::*; match level { From 480b5386dba9c852f6e6c452c8b19c8c62269f50 Mon Sep 17 00:00:00 2001 From: Joseph Livesey Date: Sun, 17 Sep 2023 10:54:57 -0400 Subject: [PATCH 2/7] Fix 'useless_conversion' clippy warning Signed-off-by: Joseph Livesey --- validator/src/journal/block_manager.rs | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/validator/src/journal/block_manager.rs b/validator/src/journal/block_manager.rs index 713ad089f4..8b046d9157 100644 --- a/validator/src/journal/block_manager.rs +++ b/validator/src/journal/block_manager.rs @@ -653,18 +653,13 @@ impl BlockManager { } fn block_contains_any_transaction(&self, block: &Block, ids: &[&String]) -> Option { - let transaction_ids: HashSet<&String> = HashSet::from_iter( - block - .batches - .iter() - .fold(vec![], |mut arr, b| { - for transaction in &b.transactions { - arr.push(&transaction.header_signature) - } - arr - }) - .into_iter(), - ); + let transaction_ids: HashSet<&String> = + HashSet::from_iter(block.batches.iter().fold(vec![], |mut arr, b| { + for transaction in &b.transactions { + arr.push(&transaction.header_signature) + } + arr + })); let comparison_transaction_ids: HashSet<&String> = HashSet::from_iter(ids.iter().cloned()); transaction_ids .intersection(&comparison_transaction_ids) From 43f1069c00e459b766549e4472847de88030089a Mon Sep 17 00:00:00 2001 From: Joseph Livesey Date: Sun, 17 Sep 2023 10:55:34 -0400 Subject: [PATCH 3/7] Fix 'needless_return' clippy warning Signed-off-by: Joseph Livesey --- validator/src/permissions/state_source.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/validator/src/permissions/state_source.rs b/validator/src/permissions/state_source.rs index de670b616e..81aedb91d0 100644 --- a/validator/src/permissions/state_source.rs +++ b/validator/src/permissions/state_source.rs @@ -41,12 +41,10 @@ impl IdentitySource for IdentityView { .map(|mut entry| match entry.get_field_type() { Policy_EntryType::PERMIT_KEY => Ok(Permission::PermitKey(entry.take_key())), Policy_EntryType::DENY_KEY => Ok(Permission::DenyKey(entry.take_key())), - Policy_EntryType::ENTRY_TYPE_UNSET => { - return Err(IdentityError::ReadError(format!( - "policy {} is contains invalid type", - entry.get_key() - ))) - } + Policy_EntryType::ENTRY_TYPE_UNSET => Err(IdentityError::ReadError(format!( + "policy {} is contains invalid type", + entry.get_key() + ))), }) .collect(); From f4c129bdd8d34afedeefae35e3223110e6335bd7 Mon Sep 17 00:00:00 2001 From: Joseph Livesey Date: Sun, 17 Sep 2023 10:56:07 -0400 Subject: [PATCH 4/7] Fix 'useless_vec' clippy warning Signed-off-by: Joseph Livesey --- validator/src/state/merkle.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/validator/src/state/merkle.rs b/validator/src/state/merkle.rs index 76f00bc476..c8ef6b57ba 100644 --- a/validator/src/state/merkle.rs +++ b/validator/src/state/merkle.rs @@ -1041,8 +1041,7 @@ mod tests { run_test(|merkle_path| { let mut merkle_db = make_db(merkle_path); let init_root = merkle_db.get_merkle_root(); - let key_hashes = vec![ - // matching prefix e55420 + let key_hashes = [ ( "asdfg", "e5542002d3e2892516fa461cde69e05880609fbad3d38ab69435a189e126de672b620c", @@ -1133,7 +1132,7 @@ mod tests { run_test(|merkle_path| { let mut merkle_db = make_db(merkle_path); let init_root = merkle_db.get_merkle_root(); - let key_hashes = vec![ + let key_hashes = [ ( "qwert", "c946ee72d38b8c51328f1a5f31eb5bd3300362ad0ca69dab54eff996775c7069216bda", @@ -1165,7 +1164,7 @@ mod tests { assert_ne!(init_root, merkle_db.get_merkle_root()); // matching prefix e55420, however this will be newly added and not set already in trie - let key_hash_to_be_inserted = vec![( + let key_hash_to_be_inserted = [( "asdfg", "e5542002d3e2892516fa461cde69e05880609fbad3d38ab69435a189e126de672b620c", )]; @@ -1517,7 +1516,7 @@ mod tests { ); } - let addresses = vec!["ab0000", "aba001", "abff02"]; + let addresses = ["ab0000", "aba001", "abff02"]; for (i, key) in addresses.iter().enumerate() { let new_root = merkle_db .set(key, format!("{:04x}", i * 10).as_bytes()) From 03a8e0fd01854847a406f6b0fd7a776b641a1f92 Mon Sep 17 00:00:00 2001 From: Joseph Livesey Date: Tue, 10 Oct 2023 11:26:40 -0400 Subject: [PATCH 5/7] Remove redundant imports Signed-off-by: Joseph Livesey --- perf/sawtooth_perf/src/workload.rs | 2 -- perf/smallbank_workload/src/playlist.rs | 1 - perf/smallbank_workload/src/smallbank_transformer.rs | 2 +- 3 files changed, 1 insertion(+), 4 deletions(-) diff --git a/perf/sawtooth_perf/src/workload.rs b/perf/sawtooth_perf/src/workload.rs index 3a20f32f3f..12a8a89505 100644 --- a/perf/sawtooth_perf/src/workload.rs +++ b/perf/sawtooth_perf/src/workload.rs @@ -27,7 +27,6 @@ use std::sync::atomic::{AtomicUsize, Ordering}; use std::time; use std::vec::IntoIter; -use chrono; use futures::Future; use hyper::client::{Client, HttpConnector, Request, Response}; use hyper::error::UriError; @@ -36,7 +35,6 @@ use hyper::Error as HyperError; use hyper::Method; use hyper::StatusCode; use hyper::Uri; -use protobuf; use protobuf::Message; use tokio_core::reactor::Handle; diff --git a/perf/smallbank_workload/src/playlist.rs b/perf/smallbank_workload/src/playlist.rs index ab2fe9cbd8..1fb77cf6ba 100644 --- a/perf/smallbank_workload/src/playlist.rs +++ b/perf/smallbank_workload/src/playlist.rs @@ -40,7 +40,6 @@ use crate::protos::smallbank; use crate::protos::smallbank::SmallbankTransactionPayload; use crate::protos::smallbank::SmallbankTransactionPayload_PayloadType as SBPayloadType; -use protobuf; use protobuf::Message; use sawtooth_sdk::messages::transaction::Transaction; diff --git a/perf/smallbank_workload/src/smallbank_transformer.rs b/perf/smallbank_workload/src/smallbank_transformer.rs index b54768b666..13647fb9c7 100644 --- a/perf/smallbank_workload/src/smallbank_transformer.rs +++ b/perf/smallbank_workload/src/smallbank_transformer.rs @@ -23,7 +23,7 @@ use std::time::Instant; use crypto::digest::Digest; use crypto::sha2::Sha512; -use protobuf; + use protobuf::Message; use sawtooth_sdk::messages::transaction::{Transaction, TransactionHeader}; From e15b94252844964397c76d5f3b5240c5d4210202 Mon Sep 17 00:00:00 2001 From: Joseph Livesey Date: Tue, 10 Oct 2023 11:37:36 -0400 Subject: [PATCH 6/7] Fix use of default to create a unit struct compiler error Signed-off-by: Joseph Livesey --- perf/smallbank_workload/src/playlist.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/perf/smallbank_workload/src/playlist.rs b/perf/smallbank_workload/src/playlist.rs index 1fb77cf6ba..d1468c70b0 100644 --- a/perf/smallbank_workload/src/playlist.rs +++ b/perf/smallbank_workload/src/playlist.rs @@ -613,7 +613,7 @@ impl<'a> FmtWriter<'a> { impl<'a> fmt::Write for FmtWriter<'a> { fn write_str(&mut self, s: &str) -> Result<(), fmt::Error> { let w = &mut *self.writer; - w.write_all(s.as_bytes()).map_err(|_| fmt::Error::default()) + w.write_all(s.as_bytes()).map_err(|_| fmt::Error) } } From b62668da6d786007e5d9415f32ed0e88b0270b78 Mon Sep 17 00:00:00 2001 From: Joseph Livesey Date: Tue, 10 Oct 2023 11:52:16 -0400 Subject: [PATCH 7/7] Fix useless use of vec! compiler error Signed-off-by: Joseph Livesey --- families/battleship/src/game.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/families/battleship/src/game.rs b/families/battleship/src/game.rs index d7ef8a3d1f..3bd50d9f09 100644 --- a/families/battleship/src/game.rs +++ b/families/battleship/src/game.rs @@ -41,7 +41,7 @@ pub fn get_battleship_name_hash(name: &str) -> String { /// Get a state address for a given game of battleship pub fn get_battleship_address(name: &str) -> String { - vec![get_battleship_prefix(), get_battleship_name_hash(name)].join("") + [get_battleship_prefix(), get_battleship_name_hash(name)].join("") } /// Hash the value and nonce for a revealed space