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() { fn main() {
env_logger::Builder::new() env_logger::Builder::new()
.format(|buf, record| { .format(|buf, record| {
write!( writeln!(
buf, buf,
"{} [{}]: {}\n", "{} [{}]: {}",
Local::now().format("%Y-%m-%dT%H:%M:%S"), Local::now().format("%Y-%m-%dT%H:%M:%S"),
record.level(), record.level(),
record.args() record.args()

View File

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

View File

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

View File

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

View File

@ -1,5 +1,9 @@
#![cfg_attr(feature = "nightly", feature(alloc_system))] #![cfg_attr(feature = "nightly", feature(alloc_system))]
#![cfg_attr(feature = "nightly", feature(proc_macro))] #![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")] #[cfg(feature = "nightly")]
extern crate alloc_system; extern crate alloc_system;
@ -63,7 +67,7 @@ use hbbft::{
crypto::{PublicKey, PublicKeySet}, crypto::{PublicKey, PublicKeySet},
dynamic_honey_badger::{JoinPlan, Message as DhbMessage, DynamicHoneyBadger, Input as DhbInput}, dynamic_honey_badger::{JoinPlan, Message as DhbMessage, DynamicHoneyBadger, Input as DhbInput},
sync_key_gen::{Ack, Part}, sync_key_gen::{Ack, Part},
Step as MessagingStep, DaStep as MessagingStep,
Contribution as HbbftContribution, Contribution as HbbftContribution,
}; };

View File

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