Fix some Clippy lints; migrate to new hbbft API.

This fixes the build with the modified hbbft `Step` type, and addresses
some uncontroversial Clippy warnings. Other Clippy lints are disabled.
This commit is contained in:
Andreas Fackler 2018-11-08 15:49:02 +01:00 committed by Nick Sanders
parent 2c99344c66
commit 72203fe4c9
7 changed files with 41 additions and 41 deletions

View File

@ -104,9 +104,9 @@ impl Transaction {
fn main() {
env_logger::Builder::new()
.format(|buf, record| {
write!(
writeln!(
buf,
"{} [{}]: {}\n",
"{} [{}]: {}",
Local::now().format("%Y-%m-%dT%H:%M:%S"),
record.level(),
record.args()

View File

@ -133,7 +133,7 @@ impl Block {
/// Returns this block's hash.
pub fn hash(&self) -> Option<Sha256Hash> {
self.hash.clone()
self.hash
}
/// Returns this block's hash.

View File

@ -514,7 +514,7 @@ impl<T: Contribution> Handler<T> {
}
State::AwaitingMorePeersForKeyGeneration { .. } => {
// info!("Removing peer ({}: '{}') from await list.",
// src_out_addr, src_uid.clone().unwrap());
// src_out_addr, src_uid.unwrap());
// state.peer_connection_dropped(&*self.hdb.peers());
}
State::GeneratingKeys { .. } => {
@ -575,7 +575,7 @@ impl<T: Contribution> Handler<T> {
.unwrap()
.tx()
.unbounded_send(WireMessage::welcome_received_change_add(
self.hdb.uid().clone(),
*self.hdb.uid(),
self.hdb.secret_key().public_key(),
net_state,
))
@ -613,7 +613,7 @@ impl<T: Contribution> Handler<T> {
}
InternalMessageKind::PeerDisconnect => {
let dropped_src_uid = src_uid.clone().unwrap();
let dropped_src_uid = src_uid.unwrap();
info!(
"Peer disconnected: ({}: '{}').",
src_out_addr, dropped_src_uid
@ -637,7 +637,7 @@ impl<T: Contribution> Handler<T> {
match peers
.establish_validator(src_out_addr, (src_uid_new, src_in_addr, src_pk))
{
true => debug_assert!(src_uid_new == src_uid.clone().unwrap()),
true => debug_assert!(src_uid_new == src_uid.unwrap()),
false => debug_assert!(src_uid.is_none()),
}
@ -648,7 +648,7 @@ impl<T: Contribution> Handler<T> {
// New outgoing connection:
WireMessageKind::WelcomeReceivedChangeAdd(src_uid_new, src_pk, net_state) => {
debug!("Received NetworkState: \n{:?}", net_state);
assert!(src_uid_new == src_uid.clone().unwrap());
assert!(src_uid_new == src_uid.unwrap());
let mut peers = self.hdb.peers_mut();
// Set new (outgoing-connection) peer's public info:
@ -691,7 +691,7 @@ impl<T: Contribution> Handler<T> {
self.handle_join_plan(jp, state, &peers)?;
}
wm @ _ => warn!(
wm => warn!(
"hydrabadger::Handler::handle_internal_message: Unhandled wire message: \
\n{:?}",
wm,

View File

@ -196,8 +196,7 @@ impl<T: Contribution> Hydrabadger<T> {
/// Returns a mutable reference to the inner state.
pub(crate) fn state_mut(&self) -> RwLockWriteGuard<State<T>> {
let state = self.inner.state.write();
state
self.inner.state.write()
}
/// Sets the publicly visible state discriminant and returns the previous value.
@ -359,7 +358,7 @@ impl<T: Contribution> Hydrabadger<T> {
pub_info: Option<(Uid, InAddr, PublicKey)>,
is_optimistic: bool,
) -> impl Future<Item = (), Error = ()> {
let uid = self.inner.uid.clone();
let uid = self.inner.uid;
let in_addr = self.inner.addr;
info!("Initiating outgoing connection to: {}", remote_addr);
@ -409,25 +408,22 @@ impl<T: Contribution> Hydrabadger<T> {
.for_each(move |_epoch_no| {
let hdb = self.clone();
match hdb.state_info_stale().0 {
StateDsct::Validator => {
info!(
"Generating and inputting {} random transactions...",
self.inner.config.txn_gen_count
);
// Send some random transactions to our internal HB instance.
let txns = gen_txns(
self.inner.config.txn_gen_count,
self.inner.config.txn_gen_bytes,
);
if let StateDsct::Validator = hdb.state_info_stale().0 {
info!(
"Generating and inputting {} random transactions...",
self.inner.config.txn_gen_count
);
// Send some random transactions to our internal HB instance.
let txns = gen_txns(
self.inner.config.txn_gen_count,
self.inner.config.txn_gen_bytes,
);
hdb.send_internal(InternalMessage::hb_input(
hdb.inner.uid,
OutAddr(*hdb.inner.addr),
DhbInput::User(txns),
));
}
_ => {}
hdb.send_internal(InternalMessage::hb_input(
hdb.inner.uid,
OutAddr(*hdb.inner.addr),
DhbInput::User(txns),
));
}
Ok(())
})
@ -489,7 +485,7 @@ impl<T: Contribution> Hydrabadger<T> {
let socket = TcpListener::bind(&self.inner.addr).unwrap();
info!("Listening on: {}", self.inner.addr);
let remotes = remotes.unwrap_or(HashSet::new());
let remotes = remotes.unwrap_or_default();
let hdb = self.clone();
let listen = socket
@ -570,4 +566,4 @@ impl<T: Contribution> HydrabadgerWeak<T> {
})
})
}
}
}

View File

@ -398,11 +398,11 @@ impl<T: Contribution> State<T> {
State::GeneratingKeys { .. } => {
panic!("FIXME: RESTART KEY GENERATION PROCESS AFTER PEER DISCONNECTS.");
}
State::Observer { dhb: _, .. } => {
State::Observer { .. } => {
debug!("Ignoring peer disconnection when `State::Observer`.");
return;
}
State::Validator { dhb: _, .. } => {
State::Validator { .. } => {
debug!("Ignoring peer disconnection when `State::Validator`.");
return;
}

View File

@ -1,5 +1,9 @@
#![cfg_attr(feature = "nightly", feature(alloc_system))]
#![cfg_attr(feature = "nightly", feature(proc_macro))]
#![cfg_attr(feature = "cargo-clippy",
allow(large_enum_variant, new_without_default_derive, expect_fun_call, or_fun_call,
useless_format, cyclomatic_complexity, needless_pass_by_value, module_inception,
match_bool))]
#[cfg(feature = "nightly")]
extern crate alloc_system;
@ -63,7 +67,7 @@ use hbbft::{
crypto::{PublicKey, PublicKeySet},
dynamic_honey_badger::{JoinPlan, Message as DhbMessage, DynamicHoneyBadger, Input as DhbInput},
sync_key_gen::{Ack, Part},
Step as MessagingStep,
DaStep as MessagingStep,
Contribution as HbbftContribution,
};

View File

@ -53,7 +53,7 @@ impl<T: Contribution> PeerHandler<T> {
// Create a channel for this peer
let (tx, rx) = mpsc::unbounded();
let uid = pub_info.as_ref().map(|(uid, _, _)| uid.clone());
let uid = pub_info.as_ref().map(|(uid, _, _)| *uid);
// Add an entry for this `Peer` in the shared state map.
hdb.peers_mut().add(out_addr, tx, pub_info);
@ -150,7 +150,7 @@ impl<T: Contribution> Future for PeerHandler<T> {
))
}
kind => self.hdb.send_internal(InternalMessage::wire(
self.uid.clone(),
self.uid,
self.out_addr,
kind.into(),
)),
@ -170,16 +170,16 @@ impl<T: Contribution> Drop for PeerHandler<T> {
debug!(
"Removing peer ({}: '{}') from the list of peers.",
self.out_addr,
self.uid.clone().unwrap()
self.uid.unwrap()
);
// Remove peer transmitter from the lists:
self.hdb.peers_mut().remove(&self.out_addr);
if let Some(uid) = self.uid.clone() {
if let Some(uid) = self.uid {
debug!(
"Sending peer ({}: '{}') disconnect internal message.",
self.out_addr,
self.uid.clone().unwrap()
self.uid.unwrap()
);
self.hdb
@ -281,7 +281,7 @@ impl<T: Contribution> Peer<T> {
}
},
State::EstablishedObserver { uid, in_addr, pk } => {
if let Some(_) = pub_info {
if pub_info.is_some() {
panic!(
"Peer::establish_validator: `pub_info` must be `None` \
when upgrading an observer node."