Skip to content

Commit

Permalink
[refactor]: apply new clippy suggestions
Browse files Browse the repository at this point in the history
Signed-off-by: Marin Veršić <[email protected]>
  • Loading branch information
mversic committed Dec 8, 2023
1 parent 2c3a4ce commit d4952bf
Show file tree
Hide file tree
Showing 39 changed files with 127 additions and 139 deletions.
2 changes: 1 addition & 1 deletion cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ impl NetworkRelay {
tokio::select! {
// Receive message from network
Some(msg) = receiver.recv() => self.handle_message(msg).await,
_ = self.shutdown_notify.notified() => {
() = self.shutdown_notify.notified() => {
iroha_logger::info!("NetworkRelay is being shut down.");
break;
}
Expand Down
2 changes: 1 addition & 1 deletion client/tests/integration/transfer_asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ fn simulate_transfer_fixed() {
)
}

#[should_panic]
#[test]
#[ignore = "long"]
#[should_panic(expected = "insufficient funds")]
fn simulate_insufficient_funds() {
simulate_transfer(
Fixed::try_from(20_f64).expect("Valid"),
Expand Down
4 changes: 3 additions & 1 deletion config/base/derive/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,9 @@ pub fn extract_box_generic(box_seg: &mut syn::PathSegment) -> &mut syn::Type {
generics.args.len() == 1,
"`Box` should have exactly one generic argument"
);
let syn::GenericArgument::Type(generic_type) = generics.args.first_mut().expect("Can't be empty") else {
let syn::GenericArgument::Type(generic_type) =
generics.args.first_mut().expect("Can't be empty")
else {
panic!("`Box` should have type as a generic argument")
};

Expand Down
39 changes: 18 additions & 21 deletions config/base/tests/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ use serde::{Deserialize, Serialize};
struct ConfigurationProxy {
/// Inner structure
#[config(inner)]
optional_inner: Option<InnerConfigurationProxy>,
inner: Option<InnerConfigurationProxy>,
#[config(serde_as_str)]
pub optional_string_wrapper: Option<StringWrapper>,
pub optional_string: Option<String>,
pub optional_data: Option<Data>,
pub string_wrapper: Option<StringWrapper>,
pub string: Option<String>,
pub data: Option<Data>,
}

#[derive(Clone, Debug, Deserialize, Serialize, Documented)]
Expand All @@ -33,13 +33,13 @@ struct Configuration {
impl ConfigurationProxy {
fn new_with_placeholders() -> Self {
Self {
optional_inner: Some(InnerConfigurationProxy {
inner: Some(InnerConfigurationProxy {
a: Some("string".to_owned()),
b: Some(42),
}),
optional_string_wrapper: Some(StringWrapper("string".to_owned())),
optional_string: Some("cool string".to_owned()),
optional_data: Some(Data {
string_wrapper: Some(StringWrapper("string".to_owned())),
string: Some("cool string".to_owned()),
data: Some(Data {
key: "key".to_owned(),
value: 34,
}),
Expand All @@ -48,10 +48,10 @@ impl ConfigurationProxy {

fn new_with_none() -> Self {
Self {
optional_inner: None,
optional_string_wrapper: None,
optional_string: None,
optional_data: None,
inner: None,
string_wrapper: None,
string: None,
data: None,
}
}
}
Expand Down Expand Up @@ -157,13 +157,10 @@ fn test_env_factory() -> TestEnv {
fn test_proxy_load_from_env() {
let config = ConfigurationProxy::new_with_placeholders();
let env_config = ConfigurationProxy::from_env(&test_env_factory()).expect("valid env");
assert_eq!(&env_config.optional_data, &config.optional_data);
assert_eq!(
&env_config.optional_string_wrapper,
&config.optional_string_wrapper
);
assert_eq!(&env_config.optional_string, &config.optional_string);
assert_eq!(&env_config.optional_inner, &config.optional_inner);
assert_eq!(&env_config.data, &config.data);
assert_eq!(&env_config.string_wrapper, &config.string_wrapper);
assert_eq!(&env_config.string, &config.string);
assert_eq!(&env_config.inner, &config.inner);
}

#[test]
Expand All @@ -172,15 +169,15 @@ fn test_can_load_inner_without_the_wrapping_config() {
env.remove_var("CONF_OPTIONAL_INNER");
let config = ConfigurationProxy::new_with_placeholders();
let env_config = ConfigurationProxy::from_env(&env).expect("valid env");
assert_eq!(&env_config.optional_inner, &config.optional_inner);
assert_eq!(&env_config.inner, &config.inner);
}

#[test]
fn test_proxy_combine_does_not_overload_with_none() {
let config = ConfigurationProxy::new_with_none();
let env_config = ConfigurationProxy::from_env(&test_env_factory()).expect("valid env");
let combine_config = env_config.clone().override_with(config);
assert_eq!(&env_config.optional_data, &combine_config.optional_data);
assert_eq!(&env_config.data, &combine_config.data);
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion config/src/iroha.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ mod tests {
}

#[test]
#[should_panic]
#[should_panic(expected = "Failed to parse Trusted Peers: ")]
fn parse_trusted_peers_fail_duplicate_peer_id() {
let trusted_peers_string = r#"[{"address":"127.0.0.1:1337", "public_key": "ed0120954C83A4220FAFFB2C1D23FC5225B3E7952D53ACBB2A065FF30C631E5E1D6B10"}, {"address":"127.0.0.1:1337", "public_key": "ed0120954C83A4220FAFFB2C1D23FC5225B3E7952D53ACBB2A065FF30C631E5E1D6B10"}, {"address":"localhost:1338", "public_key": "ed0120954C83A4220FAFFB2C1D23FC5225B3E7952D53ACBB2A065FF30C631E5E1D6B10"}, {"address": "195.162.0.1:23", "public_key": "ed0120954C83A4220FAFFB2C1D23FC5225B3E7952D53ACBB2A065FF30C631E5E1D6B10"}]"#;
let _result: TrustedPeers =
Expand Down
Binary file modified configs/peer/executor.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion core/benches/blocks/apply_blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl WsvApplyBlocks {
.map(|instructions| {
let block =
create_block(&mut wsv, instructions, account_id.clone(), key_pair.clone());
wsv.apply_without_execution(&block).map(|_| block)
wsv.apply_without_execution(&block).map(|()| block)
})
.collect::<Result<Vec<_>, _>>()?
};
Expand Down
2 changes: 1 addition & 1 deletion core/src/block_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl BlockSynchronizer {
loop {
tokio::select! {
_ = gossip_period.tick() => self.request_block().await,
_ = self.sumeragi.wsv_updated() => {
() = self.sumeragi.wsv_updated() => {
let (latest_hash, previous_hash) = self
.sumeragi
.apply_wsv(|wsv| (wsv.latest_block_hash(), wsv.previous_block_hash()));
Expand Down
4 changes: 2 additions & 2 deletions core/src/gossiper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl TransactionGossiper {
loop {
tokio::select! {
_ = gossip_period.tick() => self.gossip_transactions(),
_ = self.sumeragi.wsv_updated() => {
() = self.sumeragi.wsv_updated() => {
self.wsv = self.sumeragi.wsv_clone();
}
transaction_gossip = message_receiver.recv() => {
Expand Down Expand Up @@ -118,7 +118,7 @@ impl TransactionGossiper {

match AcceptedTransaction::accept(tx, transaction_limits) {
Ok(tx) => match self.queue.push(tx, &self.wsv) {
Ok(_) => {}
Ok(()) => {}
Err(crate::queue::Failure {
tx,
err: crate::queue::Error::InBlockchain,
Expand Down
8 changes: 4 additions & 4 deletions core/src/kura.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ impl Kura {
let mut block_data_buffer = vec![0_u8; block.length.try_into()?];

match block_store.read_block_data(block.start, &mut block_data_buffer) {
Ok(_) => match SignedBlock::decode_all_versioned(&block_data_buffer) {
Ok(()) => match SignedBlock::decode_all_versioned(&block_data_buffer) {
Ok(decoded_block) => {
if previous_block_hash != decoded_block.payload().header.previous_block_hash
{
Expand Down Expand Up @@ -416,7 +416,7 @@ impl BlockStore {
.map_err(|e| Error::MkDir(e, store_path.to_path_buf()))
{
Err(e) => Err(e),
Ok(_) => {
Ok(()) => {
if let Err(e) = fs::File::options()
.read(true)
.write(true)
Expand Down Expand Up @@ -560,7 +560,7 @@ impl BlockStore {
hashes_file
.read_exact(&mut buffer)
.add_err_context(&path)
.and_then(|_| HashOf::decode_all(&mut buffer.as_slice()).map_err(Error::Codec))
.and_then(|()| HashOf::decode_all(&mut buffer.as_slice()).map_err(Error::Codec))
})
.collect()
}
Expand Down Expand Up @@ -1036,7 +1036,7 @@ mod tests {
}

#[test]
#[should_panic]
#[should_panic(expected = "Kura must be able to lock the blockstore: ")]
fn concurrent_lock() {
let dir = tempfile::tempdir().unwrap();
let _store = BlockStore::new(dir.path(), LockStatus::Unlocked);
Expand Down
13 changes: 2 additions & 11 deletions core/src/query/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,7 @@ impl<I: IntoIterator + FromIterator<I::Item>> Batched<I> {

self.cursor = if let Some(cursor) = self.cursor {
if batch_size >= self.batch_size.get() {
let batch_size = self
.batch_size
.get()
.try_into()
.expect("usize should fit in u64");
let batch_size = self.batch_size.get().into();
Some(
cursor
.checked_add(batch_size)
Expand All @@ -76,12 +72,7 @@ impl<I: IntoIterator + FromIterator<I::Item>> Batched<I> {
None
}
} else if batch_size >= self.batch_size.get() {
Some(
self.batch_size
.get()
.try_into()
.expect("usize should fit in u64"),
)
Some(self.batch_size.get().into())
} else {
None
};
Expand Down
12 changes: 9 additions & 3 deletions core/src/query/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,13 +326,19 @@ mod tests {
.handle_query_output(query_output, &sorting, pagination, fetch_size)
.unwrap()
.into();
let Value::Vec(v) = batch else { panic!("not expected result") };
let Value::Vec(v) = batch else {
panic!("not expected result")
};
counter += v.len();

while cursor.cursor.is_some() {
let Ok(batched) = query_store_handle.handle_query_cursor(cursor) else { break };
let Ok(batched) = query_store_handle.handle_query_cursor(cursor) else {
break;
};
let (batch, new_cursor) = batched.into();
let Value::Vec(v) = batch else { panic!("not expected result") };
let Value::Vec(v) = batch else {
panic!("not expected result")
};
counter += v.len();

cursor = new_cursor;
Expand Down
42 changes: 21 additions & 21 deletions core/src/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ impl AcceptedTransaction {
#[derive(Debug)]
pub struct Queue {
/// The queue for transactions
queue: ArrayQueue<HashOf<TransactionPayload>>,
tx_hashes: ArrayQueue<HashOf<TransactionPayload>>,
/// [`AcceptedTransaction`]s addressed by `Hash`
txs: DashMap<HashOf<TransactionPayload>, AcceptedTransaction>,
accepted_txs: DashMap<HashOf<TransactionPayload>, AcceptedTransaction>,
/// Amount of transactions per user in the queue
txs_per_user: DashMap<AccountId, usize>,
/// The maximum number of transactions in the queue
Expand Down Expand Up @@ -99,8 +99,8 @@ impl Queue {
/// Makes queue from configuration
pub fn from_configuration(cfg: &Configuration) -> Self {
Self {
queue: ArrayQueue::new(cfg.max_transactions_in_queue as usize),
txs: DashMap::new(),
tx_hashes: ArrayQueue::new(cfg.max_transactions_in_queue as usize),
accepted_txs: DashMap::new(),
txs_per_user: DashMap::new(),
max_txs: cfg.max_transactions_in_queue as usize,
max_txs_per_user: cfg.max_transactions_in_queue_per_user as usize,
Expand Down Expand Up @@ -140,7 +140,7 @@ impl Queue {
&'wsv self,
wsv: &'wsv WorldStateView,
) -> impl Iterator<Item = AcceptedTransaction> + 'wsv {
self.txs.iter().filter_map(|tx| {
self.accepted_txs.iter().filter_map(|tx| {
if self.is_pending(tx.value(), wsv) {
return Some(tx.value().clone());
}
Expand All @@ -151,7 +151,7 @@ impl Queue {

/// Returns `n` randomly selected transaction from the queue.
pub fn n_random_transactions(&self, n: u32, wsv: &WorldStateView) -> Vec<AcceptedTransaction> {
self.txs
self.accepted_txs
.iter()
.filter(|e| self.is_pending(e.value(), wsv))
.map(|e| e.value().clone())
Expand Down Expand Up @@ -193,9 +193,9 @@ impl Queue {
}

// Get `txs_len` before entry to avoid deadlock
let txs_len = self.txs.len();
let txs_len = self.accepted_txs.len();
let hash = tx.payload().hash();
let entry = match self.txs.entry(hash) {
let entry = match self.accepted_txs.entry(hash) {
Entry::Occupied(mut old_tx) => {
// MST case
let signatures_amount_before = old_tx.get().signatures().len();
Expand Down Expand Up @@ -226,10 +226,10 @@ impl Queue {

// Insert entry first so that the `tx` popped from `queue` will always have a `(hash, tx)` record in `txs`.
entry.insert(tx);
self.queue.push(hash).map_err(|err_hash| {
self.tx_hashes.push(hash).map_err(|err_hash| {
warn!("Queue is full");
let (_, err_tx) = self
.txs
.accepted_txs
.remove(&err_hash)
.expect("Inserted just before match");
self.decrease_per_user_tx_count(&err_tx.payload().authority);
Expand All @@ -238,7 +238,7 @@ impl Queue {
err: Error::Full,
}
})?;
trace!("Transaction queue length = {}", self.queue.len(),);
trace!("Transaction queue length = {}", self.tx_hashes.len(),);
Ok(())
}

Expand All @@ -250,10 +250,10 @@ impl Queue {
expired_transactions: &mut Vec<AcceptedTransaction>,
) -> Option<AcceptedTransaction> {
loop {
let Some(hash) = self.queue.pop() else {
let Some(hash) = self.tx_hashes.pop() else {
return None;
};
let entry = match self.txs.entry(hash) {
let entry = match self.accepted_txs.entry(hash) {
Entry::Occupied(entry) => entry,
// FIXME: Reachable under high load. Investigate, see if it's a problem.
// As practice shows this code is not `unreachable!()`.
Expand Down Expand Up @@ -288,7 +288,7 @@ impl Queue {

/// Return the number of transactions in the queue.
pub fn tx_len(&self) -> usize {
self.txs.len()
self.accepted_txs.len()
}

/// Gets transactions till they fill whole block or till the end of queue.
Expand Down Expand Up @@ -335,7 +335,7 @@ impl Queue {

seen_queue
.into_iter()
.try_for_each(|hash| self.queue.push(hash))
.try_for_each(|hash| self.tx_hashes.push(hash))
.expect("Exceeded the number of transactions pending");
expired_transactions.extend(expired_transactions_queue);
}
Expand Down Expand Up @@ -623,7 +623,7 @@ mod tests {
..
})
));
assert_eq!(queue.txs.len(), 0);
assert_eq!(queue.accepted_txs.len(), 0);
}

#[test]
Expand Down Expand Up @@ -653,7 +653,7 @@ mod tests {
.len(),
0
);
assert_eq!(queue.txs.len(), 0);
assert_eq!(queue.accepted_txs.len(), 0);
}

#[test]
Expand Down Expand Up @@ -850,11 +850,11 @@ mod tests {
get_txs_handle.join().unwrap();

// Validate the queue state.
let array_queue: Vec<_> = core::iter::from_fn(|| queue.queue.pop()).collect();
let array_queue: Vec<_> = core::iter::from_fn(|| queue.tx_hashes.pop()).collect();

assert_eq!(array_queue.len(), queue.txs.len());
assert_eq!(array_queue.len(), queue.accepted_txs.len());
for tx in array_queue {
assert!(queue.txs.contains_key(&tx));
assert!(queue.accepted_txs.contains_key(&tx));
}
}

Expand Down Expand Up @@ -889,7 +889,7 @@ mod tests {
..
})
));
assert_eq!(queue.txs.len(), 1);
assert_eq!(queue.accepted_txs.len(), 1);
}

#[test]
Expand Down
Loading

0 comments on commit d4952bf

Please sign in to comment.