Apply clippy suggestions

This commit is contained in:
Age Manning 2019-03-19 23:20:39 +11:00
parent e7f87112fb
commit 4b57d32b60
No known key found for this signature in database
GPG Key ID: 05EED64B79E06A93
9 changed files with 30 additions and 43 deletions

View File

@ -66,9 +66,9 @@ impl<TClientType: ClientTypes> Client<TClientType> {
config,
beacon_chain,
exit,
exit_signal: exit_signal,
exit_signal,
log,
network: network,
network,
phantom: PhantomData,
})
}

View File

@ -13,7 +13,7 @@ use libp2p::core::swarm::{
use libp2p::{Multiaddr, PeerId};
pub use methods::{HelloMessage, RPCMethod, RPCRequest, RPCResponse};
pub use protocol::{RPCEvent, RPCProtocol};
use slog::{debug, o};
use slog::o;
use std::marker::PhantomData;
use tokio::io::{AsyncRead, AsyncWrite};
@ -65,7 +65,7 @@ where
fn inject_connected(&mut self, peer_id: PeerId, connected_point: ConnectedPoint) {
// if initialised the connection, report this upwards to send the HELLO request
if let ConnectedPoint::Dialer { address } = connected_point {
if let ConnectedPoint::Dialer { address: _ } = connected_point {
self.events.push(NetworkBehaviourAction::GenerateEvent(
RPCMessage::PeerDialed(peer_id),
));

View File

@ -84,11 +84,11 @@ fn decode(packet: Vec<u8>) -> Result<RPCEvent, DecodeError> {
RPCMethod::Unknown => return Err(DecodeError::UnknownRPCMethod),
};
return Ok(RPCEvent::Request {
Ok(RPCEvent::Request {
id,
method_id,
body,
});
})
}
// we have received a response
else {
@ -99,11 +99,11 @@ fn decode(packet: Vec<u8>) -> Result<RPCEvent, DecodeError> {
}
RPCMethod::Unknown => return Err(DecodeError::UnknownRPCMethod),
};
return Ok(RPCEvent::Response {
Ok(RPCEvent::Response {
id,
method_id,
result,
});
})
}
}

View File

@ -73,13 +73,12 @@ impl Service {
let mut subscribed_topics = vec![];
for topic in config.topics {
let t = TopicBuilder::new(topic.to_string()).build();
match swarm.subscribe(t) {
true => {
trace!(log, "Subscribed to topic: {:?}", topic);
subscribed_topics.push(topic);
}
false => warn!(log, "Could not subscribe to topic: {:?}", topic),
};
if swarm.subscribe(t) {
trace!(log, "Subscribed to topic: {:?}", topic);
subscribed_topics.push(topic);
} else {
warn!(log, "Could not subscribe to topic: {:?}", topic)
}
}
info!(log, "Subscribed to topics: {:?}", subscribed_topics);

View File

@ -48,7 +48,7 @@ pub enum HandlerMessage {
impl MessageHandler {
/// Initializes and runs the MessageHandler.
pub fn new(
pub fn spawn(
beacon_chain: Arc<BeaconChain>,
network_send: crossbeam_channel::Sender<NetworkMessage>,
executor: &tokio::runtime::TaskExecutor,
@ -108,16 +108,9 @@ impl MessageHandler {
/// Handle RPC messages
fn handle_rpc_message(&mut self, peer_id: PeerId, rpc_message: RPCEvent) {
match rpc_message {
RPCEvent::Request {
id,
method_id: _, // TODO: Clean up RPC Message types, have a cleaner type by this point.
body,
RPCEvent::Request { id, body, .. // TODO: Clean up RPC Message types, have a cleaner type by this point.
} => self.handle_rpc_request(peer_id, id, body),
RPCEvent::Response {
id,
method_id: _,
result,
} => self.handle_rpc_response(peer_id, id, result),
RPCEvent::Response { id, result, .. } => self.handle_rpc_response(peer_id, id, result),
}
}
@ -134,11 +127,7 @@ impl MessageHandler {
// we match on id and ignore responses past the timeout.
fn handle_rpc_response(&mut self, peer_id: PeerId, id: u64, response: RPCResponse) {
// if response id is related to a request, ignore (likely RPC timeout)
if self
.requests
.remove(&(peer_id.clone(), id.clone()))
.is_none()
{
if self.requests.remove(&(peer_id.clone(), id)).is_none() {
debug!(self.log, "Unrecognized response from peer: {:?}", peer_id);
return;
}
@ -193,18 +182,19 @@ impl MessageHandler {
/// Sends a HELLO RPC request or response to a newly connected peer.
//TODO: The boolean determines if sending request/respond, will be cleaner in the RPC re-write
fn send_hello(&mut self, peer_id: PeerId, id: u64, request: bool) {
let rpc_event = match request {
true => RPCEvent::Request {
fn send_hello(&mut self, peer_id: PeerId, id: u64, is_request: bool) {
let rpc_event = if is_request {
RPCEvent::Request {
id,
method_id: RPCMethod::Hello.into(),
body: RPCRequest::Hello(self.sync.generate_hello()),
},
false => RPCEvent::Response {
}
} else {
RPCEvent::Response {
id,
method_id: RPCMethod::Hello.into(),
result: RPCResponse::Hello(self.sync.generate_hello()),
},
}
};
// send the hello request to the network

View File

@ -33,7 +33,7 @@ impl Service {
let (network_send, network_recv) = channel::<NetworkMessage>();
// launch message handler thread
let message_handler_log = log.new(o!("Service" => "MessageHandler"));
let message_handler_send = MessageHandler::new(
let message_handler_send = MessageHandler::spawn(
beacon_chain,
network_send.clone(),
executor,

View File

@ -66,7 +66,7 @@ impl SimpleSync {
//TODO: Paul to verify the logic of these fields.
HelloMessage {
network_id: self.network_id,
latest_finalized_root: state.finalized_root.clone(),
latest_finalized_root: state.finalized_root,
latest_finalized_epoch: state.finalized_epoch,
best_root: state.latest_block_roots[0], //TODO: build correct value as a beacon chain function
best_slot: state.slot - 1,

View File

@ -6,7 +6,7 @@ extern crate target_info;
use target_info::Target;
const TRACK: &'static str = "unstable";
const TRACK: &str = "unstable";
/// Provides the current platform
pub fn platform() -> String {

View File

@ -219,10 +219,8 @@ impl<T: ClientDB + Sized> ForkChoice for SlowLMDGhost<T> {
head_vote_count = vote_count;
}
// resolve ties - choose smaller hash
else if vote_count == head_vote_count {
if *child_hash < head_hash {
head_hash = *child_hash;
}
else if vote_count == head_vote_count && *child_hash < head_hash {
head_hash = *child_hash;
}
}
}