Skip to content

Commit

Permalink
fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ma2bd committed Apr 28, 2020
1 parent 4a276cb commit 5c6e9c3
Show file tree
Hide file tree
Showing 19 changed files with 138 additions and 138 deletions.
14 changes: 7 additions & 7 deletions rust/fastpay/src/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl ClientServerBenchmark {
for i in 0..self.num_shards {
let state = AuthorityState::new_shard(
committee.clone(),
public_auth0.clone(),
public_auth0,
secret_auth0.copy(),
i as u32,
self.num_shards,
Expand Down Expand Up @@ -126,7 +126,7 @@ impl ClientServerBenchmark {
let mut next_recipient = get_key_pair().0;
for (pubx, secx) in account_keys.iter() {
let transfer = Transfer {
sender: pubx.clone(),
sender: *pubx,
recipient: Address::FastPay(next_recipient),
amount: Amount::from(50),
sequence_number: SequenceNumber::from(0),
Expand All @@ -138,7 +138,7 @@ impl ClientServerBenchmark {

// Serialize order
let bufx = serialize_transfer_order(&order);
assert!(bufx.len() > 0);
assert!(!bufx.is_empty());

// Make certificate
let mut certificate = CertifiedTransferOrder {
Expand All @@ -152,7 +152,7 @@ impl ClientServerBenchmark {
}

let bufx2 = serialize_cert(&certificate);
assert!(bufx2.len() > 0);
assert!(!bufx2.is_empty());

orders.push((shard, bufx2.into()));
orders.push((shard, bufx.into()));
Expand Down Expand Up @@ -197,7 +197,7 @@ impl ClientServerBenchmark {
for (shard, buf) in orders.iter().rev() {
sharded_requests
.entry(*shard)
.or_insert(Vec::new())
.or_insert_with(Vec::new)
.push(buf.clone());
}
let responses = mass_client.run(sharded_requests).concat().await;
Expand All @@ -214,7 +214,7 @@ impl ClientServerBenchmark {
self.recv_timeout,
);

while orders.len() > 0 {
while !orders.is_empty() {
if orders.len() % 1000 == 0 {
info!("Process message {}...", orders.len());
}
Expand All @@ -236,7 +236,7 @@ impl ClientServerBenchmark {
"Total time: {}ms, items: {}, tx/sec: {}",
time_total,
items_number,
1000000.0 * (items_number as f64) / (time_total as f64)
1_000_000.0 * (items_number as f64) / (time_total as f64)
);
}

Expand Down
10 changes: 5 additions & 5 deletions rust/fastpay/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ async fn mass_broadcast_orders(
let shard = AuthorityState::get_shard(num_shards, address);
sharded_requests
.entry(shard)
.or_insert(Vec::new())
.or_insert_with(Vec::new)
.push(buf.clone());
}
streams.push(client.run(sharded_requests));
Expand All @@ -240,7 +240,7 @@ async fn mass_broadcast_orders(
);
warn!(
"Estimated server throughput: {} {} orders per sec",
(orders.len() as u128) * 1000000 / time_elapsed.as_micros(),
(orders.len() as u128) * 1_000_000 / time_elapsed.as_micros(),
phase
);
responses
Expand All @@ -252,14 +252,14 @@ fn mass_update_recipients(
) {
for (_sender, buf) in certificates {
if let Ok(SerializedMessage::Cert(certificate)) = deserialize_message(&buf[..]) {
accounts_config.update_for_received_transfer(certificate);
accounts_config.update_for_received_transfer(*certificate);
}
}
}

fn deserialize_response(response: &[u8]) -> Option<AccountInfoResponse> {
match deserialize_message(response) {
Ok(SerializedMessage::InfoResp(info)) => Some(info),
Ok(SerializedMessage::InfoResp(info)) => Some(*info),
Ok(SerializedMessage::Error(error)) => {
error!("Received error value: {}", error);
None
Expand Down Expand Up @@ -447,7 +447,7 @@ fn main() {
.value_of("max_orders")
.unwrap()
.parse()
.unwrap_or(accounts_config.num_accounts());
.unwrap_or_else(|_| accounts_config.num_accounts());
let server_configs = if subm.is_present("server_configs") {
let files: Vec<_> = subm.values_of("server_configs").unwrap().collect();
Some(files)
Expand Down
2 changes: 1 addition & 1 deletion rust/fastpay/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ impl AccountsConfig {
.received_certificates
.binary_search_by_key(&certificate.key(), CertifiedTransferOrder::key)
{
config.balance = config.balance.add(transfer.amount.into()).unwrap();
config.balance = config.balance.try_add(transfer.amount.into()).unwrap();
config.received_certificates.insert(position, certificate)
}
}
Expand Down
24 changes: 11 additions & 13 deletions rust/fastpay/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,11 @@ impl MessageHandler for RunningServerState {
SerializedMessage::Order(message) => self
.server
.state
.handle_transfer_order(message)
.handle_transfer_order(*message)
.map(|info| Some(serialize_info_response(&info))),
SerializedMessage::Cert(message) => {
let confirmation_order = ConfirmationOrder {
transfer_certificate: message.clone(),
transfer_certificate: message.as_ref().clone(),
};
match self
.server
Expand Down Expand Up @@ -181,13 +181,13 @@ impl MessageHandler for RunningServerState {
SerializedMessage::InfoReq(message) => self
.server
.state
.handle_account_info_request(message)
.handle_account_info_request(*message)
.map(|info| Some(serialize_info_response(&info))),
SerializedMessage::CrossShard(message) => {
match self
.server
.state
.handle_cross_shard_recipient_commit(message)
.handle_cross_shard_recipient_commit(*message)
{
Ok(_) => Ok(None), // Nothing to reply
Err(error) => {
Expand Down Expand Up @@ -280,16 +280,14 @@ impl Client {
buf: Vec<u8>,
) -> Result<AccountInfoResponse, FastPayError> {
match self.send_recv_bytes_internal(shard, buf).await {
Err(error) => {
return Err(FastPayError::ClientIOError {
error: format!("{}", error),
});
}
Err(error) => Err(FastPayError::ClientIOError {
error: format!("{}", error),
}),
Ok(response) => {
// Parse reply
match deserialize_message(&response[..]) {
Ok(SerializedMessage::InfoResp(resp)) => Ok(resp),
Ok(SerializedMessage::Error(error)) => Err(error),
Ok(SerializedMessage::InfoResp(resp)) => Ok(*resp),
Ok(SerializedMessage::Error(error)) => Err(*error),
Err(_) => Err(FastPayError::InvalidDecoding),
_ => Err(FastPayError::UnexpectedMessage),
}
Expand Down Expand Up @@ -445,7 +443,7 @@ impl MassClient {
let responses = client
.run_shard(shard, requests)
.await
.unwrap_or(Vec::new());
.unwrap_or_else(|_| Vec::new());
info!(
"Done sending {} requests to {}:{} (shard {})",
client.network_protocol,
Expand All @@ -455,7 +453,7 @@ impl MassClient {
);
responses
})
.then(|x| async { x.unwrap_or(Vec::new()) }),
.then(|x| async { x.unwrap_or_else(|_| Vec::new()) }),
);
}
handles
Expand Down
3 changes: 2 additions & 1 deletion rust/fastpay/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use futures::future::join_all;
use log::*;
use tokio::runtime::Runtime;

#[allow(clippy::too_many_arguments)]
fn make_shard_server(
local_ip_addr: &str,
server_config_path: &str,
Expand All @@ -41,7 +42,7 @@ fn make_shard_server(
let num_shards = server_config.authority.num_shards;

let mut state = AuthorityState::new_shard(
committee.clone(),
committee,
server_config.authority.address,
server_config.key.copy(),
shard,
Expand Down
20 changes: 10 additions & 10 deletions rust/fastpay/src/transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use tokio::prelude::*;
mod transport_tests;

/// Suggested buffer size
pub const DEFAULT_MAX_DATAGRAM_SIZE: &'static str = "65507";
pub const DEFAULT_MAX_DATAGRAM_SIZE: &str = "65507";

// Supported transport protocols.
arg_enum! {
Expand All @@ -43,7 +43,7 @@ pub trait DataStreamPool: Send {
fn send_data_to<'a>(
&'a mut self,
buffer: &'a [u8],
address: &'a String,
address: &'a str,
) -> future::BoxFuture<'a, Result<(), io::Error>>;
}

Expand Down Expand Up @@ -76,7 +76,7 @@ impl SpawnedServer {
impl NetworkProtocol {
/// Create a DataStream for this protocol.
pub async fn connect(
&self,
self,
address: String,
max_data_size: usize,
) -> Result<Box<dyn DataStream>, std::io::Error> {
Expand All @@ -89,7 +89,7 @@ impl NetworkProtocol {

/// Create a DataStreamPool for this protocol.
pub async fn make_outgoing_connection_pool(
&self,
self,
) -> Result<Box<dyn DataStreamPool>, std::io::Error> {
let pool: Box<dyn DataStreamPool> = match self {
Self::Udp => Box::new(UdpDataStreamPool::new().await?),
Expand All @@ -100,8 +100,8 @@ impl NetworkProtocol {

/// Run a server for this protocol and the given message handler.
pub async fn spawn_server<S>(
&self,
address: &String,
self,
address: &str,
state: S,
buffer_size: usize,
) -> Result<SpawnedServer, std::io::Error>
Expand Down Expand Up @@ -177,7 +177,7 @@ impl DataStreamPool for UdpDataStreamPool {
fn send_data_to<'a>(
&'a mut self,
buffer: &'a [u8],
address: &'a String,
address: &'a str,
) -> future::BoxFuture<'a, Result<(), std::io::Error>> {
Box::pin(async move {
self.socket.send_to(buffer, address).await?;
Expand Down Expand Up @@ -293,11 +293,11 @@ impl TcpDataStreamPool {
Ok(Self { streams })
}

async fn get_stream(&mut self, address: &String) -> Result<&mut TcpStream, io::Error> {
async fn get_stream(&mut self, address: &str) -> Result<&mut TcpStream, io::Error> {
if !self.streams.contains_key(address) {
match TcpStream::connect(address).await {
Ok(s) => {
self.streams.insert(address.clone(), s);
self.streams.insert(address.to_string(), s);
}
Err(error) => {
error!("Failed to open connection to {}: {}", address, error);
Expand All @@ -313,7 +313,7 @@ impl DataStreamPool for TcpDataStreamPool {
fn send_data_to<'a>(
&'a mut self,
buffer: &'a [u8],
address: &'a String,
address: &'a str,
) -> future::BoxFuture<'a, Result<(), std::io::Error>> {
Box::pin(async move {
let stream = self.get_stream(address).await?;
Expand Down
5 changes: 2 additions & 3 deletions rust/fastpay/src/unit_tests/transport_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// SPDX-License-Identifier: Apache-2.0

use super::*;
use net2;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::time::Duration;
use tokio::runtime::Runtime;
Expand Down Expand Up @@ -58,7 +57,7 @@ async fn test_server(protocol: NetworkProtocol) -> Result<(usize, usize), std::i
// Try to read data on the first connection (should fail).
received += timeout(Duration::from_millis(500), client.read_data())
.await
.unwrap_or(Ok(Vec::new()))?
.unwrap_or_else(|_| Ok(Vec::new()))?
.len();

// Attempt to gracefully kill server.
Expand All @@ -69,7 +68,7 @@ async fn test_server(protocol: NetworkProtocol) -> Result<(usize, usize), std::i
.unwrap_or(Ok(()))?;
received += timeout(Duration::from_millis(500), client.read_data())
.await
.unwrap_or(Ok(Vec::new()))?
.unwrap_or_else(|_| Ok(Vec::new()))?
.len();

Ok((counter.load(Ordering::Relaxed), received))
Expand Down
Loading

0 comments on commit 5c6e9c3

Please sign in to comment.