diff --git a/beacon_node/client/src/lib.rs b/beacon_node/client/src/lib.rs index 327e433af..beba6f4de 100644 --- a/beacon_node/client/src/lib.rs +++ b/beacon_node/client/src/lib.rs @@ -66,9 +66,9 @@ impl Client { config, beacon_chain, exit, - exit_signal: exit_signal, + exit_signal, log, - network: network, + network, phantom: PhantomData, }) } diff --git a/beacon_node/libp2p/src/rpc/mod.rs b/beacon_node/libp2p/src/rpc/mod.rs index e06f4effc..a1cfadafe 100644 --- a/beacon_node/libp2p/src/rpc/mod.rs +++ b/beacon_node/libp2p/src/rpc/mod.rs @@ -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), )); diff --git a/beacon_node/libp2p/src/rpc/protocol.rs b/beacon_node/libp2p/src/rpc/protocol.rs index dce714429..6cebb7fd2 100644 --- a/beacon_node/libp2p/src/rpc/protocol.rs +++ b/beacon_node/libp2p/src/rpc/protocol.rs @@ -84,11 +84,11 @@ fn decode(packet: Vec) -> Result { 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) -> Result { } RPCMethod::Unknown => return Err(DecodeError::UnknownRPCMethod), }; - return Ok(RPCEvent::Response { + Ok(RPCEvent::Response { id, method_id, result, - }); + }) } } diff --git a/beacon_node/libp2p/src/service.rs b/beacon_node/libp2p/src/service.rs index 92e6e8897..e378cd634 100644 --- a/beacon_node/libp2p/src/service.rs +++ b/beacon_node/libp2p/src/service.rs @@ -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); diff --git a/beacon_node/network/src/message_handler.rs b/beacon_node/network/src/message_handler.rs index bcea28ff8..2a3f38bc1 100644 --- a/beacon_node/network/src/message_handler.rs +++ b/beacon_node/network/src/message_handler.rs @@ -48,7 +48,7 @@ pub enum HandlerMessage { impl MessageHandler { /// Initializes and runs the MessageHandler. - pub fn new( + pub fn spawn( beacon_chain: Arc, network_send: crossbeam_channel::Sender, 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 diff --git a/beacon_node/network/src/service.rs b/beacon_node/network/src/service.rs index 4e79a92fe..c3045d280 100644 --- a/beacon_node/network/src/service.rs +++ b/beacon_node/network/src/service.rs @@ -33,7 +33,7 @@ impl Service { let (network_send, network_recv) = channel::(); // 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, diff --git a/beacon_node/network/src/sync/simple_sync.rs b/beacon_node/network/src/sync/simple_sync.rs index a3cd9044c..95c7092c3 100644 --- a/beacon_node/network/src/sync/simple_sync.rs +++ b/beacon_node/network/src/sync/simple_sync.rs @@ -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, diff --git a/beacon_node/version/src/lib.rs b/beacon_node/version/src/lib.rs index 628186aa0..3dcd57bef 100644 --- a/beacon_node/version/src/lib.rs +++ b/beacon_node/version/src/lib.rs @@ -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 { diff --git a/eth2/fork_choice/src/slow_lmd_ghost.rs b/eth2/fork_choice/src/slow_lmd_ghost.rs index af58aa7b8..0788ac171 100644 --- a/eth2/fork_choice/src/slow_lmd_ghost.rs +++ b/eth2/fork_choice/src/slow_lmd_ghost.rs @@ -219,10 +219,8 @@ impl ForkChoice for SlowLMDGhost { 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; } } }