Apply clippy suggestions
This commit is contained in:
parent
e7f87112fb
commit
4b57d32b60
@ -66,9 +66,9 @@ impl<TClientType: ClientTypes> Client<TClientType> {
|
|||||||
config,
|
config,
|
||||||
beacon_chain,
|
beacon_chain,
|
||||||
exit,
|
exit,
|
||||||
exit_signal: exit_signal,
|
exit_signal,
|
||||||
log,
|
log,
|
||||||
network: network,
|
network,
|
||||||
phantom: PhantomData,
|
phantom: PhantomData,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ use libp2p::core::swarm::{
|
|||||||
use libp2p::{Multiaddr, PeerId};
|
use libp2p::{Multiaddr, PeerId};
|
||||||
pub use methods::{HelloMessage, RPCMethod, RPCRequest, RPCResponse};
|
pub use methods::{HelloMessage, RPCMethod, RPCRequest, RPCResponse};
|
||||||
pub use protocol::{RPCEvent, RPCProtocol};
|
pub use protocol::{RPCEvent, RPCProtocol};
|
||||||
use slog::{debug, o};
|
use slog::o;
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
use tokio::io::{AsyncRead, AsyncWrite};
|
use tokio::io::{AsyncRead, AsyncWrite};
|
||||||
|
|
||||||
@ -65,7 +65,7 @@ where
|
|||||||
|
|
||||||
fn inject_connected(&mut self, peer_id: PeerId, connected_point: ConnectedPoint) {
|
fn inject_connected(&mut self, peer_id: PeerId, connected_point: ConnectedPoint) {
|
||||||
// if initialised the connection, report this upwards to send the HELLO request
|
// 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(
|
self.events.push(NetworkBehaviourAction::GenerateEvent(
|
||||||
RPCMessage::PeerDialed(peer_id),
|
RPCMessage::PeerDialed(peer_id),
|
||||||
));
|
));
|
||||||
|
@ -84,11 +84,11 @@ fn decode(packet: Vec<u8>) -> Result<RPCEvent, DecodeError> {
|
|||||||
RPCMethod::Unknown => return Err(DecodeError::UnknownRPCMethod),
|
RPCMethod::Unknown => return Err(DecodeError::UnknownRPCMethod),
|
||||||
};
|
};
|
||||||
|
|
||||||
return Ok(RPCEvent::Request {
|
Ok(RPCEvent::Request {
|
||||||
id,
|
id,
|
||||||
method_id,
|
method_id,
|
||||||
body,
|
body,
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
// we have received a response
|
// we have received a response
|
||||||
else {
|
else {
|
||||||
@ -99,11 +99,11 @@ fn decode(packet: Vec<u8>) -> Result<RPCEvent, DecodeError> {
|
|||||||
}
|
}
|
||||||
RPCMethod::Unknown => return Err(DecodeError::UnknownRPCMethod),
|
RPCMethod::Unknown => return Err(DecodeError::UnknownRPCMethod),
|
||||||
};
|
};
|
||||||
return Ok(RPCEvent::Response {
|
Ok(RPCEvent::Response {
|
||||||
id,
|
id,
|
||||||
method_id,
|
method_id,
|
||||||
result,
|
result,
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,13 +73,12 @@ impl Service {
|
|||||||
let mut subscribed_topics = vec![];
|
let mut subscribed_topics = vec![];
|
||||||
for topic in config.topics {
|
for topic in config.topics {
|
||||||
let t = TopicBuilder::new(topic.to_string()).build();
|
let t = TopicBuilder::new(topic.to_string()).build();
|
||||||
match swarm.subscribe(t) {
|
if swarm.subscribe(t) {
|
||||||
true => {
|
trace!(log, "Subscribed to topic: {:?}", topic);
|
||||||
trace!(log, "Subscribed to topic: {:?}", topic);
|
subscribed_topics.push(topic);
|
||||||
subscribed_topics.push(topic);
|
} else {
|
||||||
}
|
warn!(log, "Could not subscribe to topic: {:?}", topic)
|
||||||
false => warn!(log, "Could not subscribe to topic: {:?}", topic),
|
}
|
||||||
};
|
|
||||||
}
|
}
|
||||||
info!(log, "Subscribed to topics: {:?}", subscribed_topics);
|
info!(log, "Subscribed to topics: {:?}", subscribed_topics);
|
||||||
|
|
||||||
|
@ -48,7 +48,7 @@ pub enum HandlerMessage {
|
|||||||
|
|
||||||
impl MessageHandler {
|
impl MessageHandler {
|
||||||
/// Initializes and runs the MessageHandler.
|
/// Initializes and runs the MessageHandler.
|
||||||
pub fn new(
|
pub fn spawn(
|
||||||
beacon_chain: Arc<BeaconChain>,
|
beacon_chain: Arc<BeaconChain>,
|
||||||
network_send: crossbeam_channel::Sender<NetworkMessage>,
|
network_send: crossbeam_channel::Sender<NetworkMessage>,
|
||||||
executor: &tokio::runtime::TaskExecutor,
|
executor: &tokio::runtime::TaskExecutor,
|
||||||
@ -108,16 +108,9 @@ impl MessageHandler {
|
|||||||
/// Handle RPC messages
|
/// Handle RPC messages
|
||||||
fn handle_rpc_message(&mut self, peer_id: PeerId, rpc_message: RPCEvent) {
|
fn handle_rpc_message(&mut self, peer_id: PeerId, rpc_message: RPCEvent) {
|
||||||
match rpc_message {
|
match rpc_message {
|
||||||
RPCEvent::Request {
|
RPCEvent::Request { id, body, .. // TODO: Clean up RPC Message types, have a cleaner type by this point.
|
||||||
id,
|
|
||||||
method_id: _, // TODO: Clean up RPC Message types, have a cleaner type by this point.
|
|
||||||
body,
|
|
||||||
} => self.handle_rpc_request(peer_id, id, body),
|
} => self.handle_rpc_request(peer_id, id, body),
|
||||||
RPCEvent::Response {
|
RPCEvent::Response { id, result, .. } => self.handle_rpc_response(peer_id, id, result),
|
||||||
id,
|
|
||||||
method_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.
|
// we match on id and ignore responses past the timeout.
|
||||||
fn handle_rpc_response(&mut self, peer_id: PeerId, id: u64, response: RPCResponse) {
|
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 response id is related to a request, ignore (likely RPC timeout)
|
||||||
if self
|
if self.requests.remove(&(peer_id.clone(), id)).is_none() {
|
||||||
.requests
|
|
||||||
.remove(&(peer_id.clone(), id.clone()))
|
|
||||||
.is_none()
|
|
||||||
{
|
|
||||||
debug!(self.log, "Unrecognized response from peer: {:?}", peer_id);
|
debug!(self.log, "Unrecognized response from peer: {:?}", peer_id);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -193,18 +182,19 @@ impl MessageHandler {
|
|||||||
|
|
||||||
/// Sends a HELLO RPC request or response to a newly connected peer.
|
/// 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
|
//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) {
|
fn send_hello(&mut self, peer_id: PeerId, id: u64, is_request: bool) {
|
||||||
let rpc_event = match request {
|
let rpc_event = if is_request {
|
||||||
true => RPCEvent::Request {
|
RPCEvent::Request {
|
||||||
id,
|
id,
|
||||||
method_id: RPCMethod::Hello.into(),
|
method_id: RPCMethod::Hello.into(),
|
||||||
body: RPCRequest::Hello(self.sync.generate_hello()),
|
body: RPCRequest::Hello(self.sync.generate_hello()),
|
||||||
},
|
}
|
||||||
false => RPCEvent::Response {
|
} else {
|
||||||
|
RPCEvent::Response {
|
||||||
id,
|
id,
|
||||||
method_id: RPCMethod::Hello.into(),
|
method_id: RPCMethod::Hello.into(),
|
||||||
result: RPCResponse::Hello(self.sync.generate_hello()),
|
result: RPCResponse::Hello(self.sync.generate_hello()),
|
||||||
},
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// send the hello request to the network
|
// send the hello request to the network
|
||||||
|
@ -33,7 +33,7 @@ impl Service {
|
|||||||
let (network_send, network_recv) = channel::<NetworkMessage>();
|
let (network_send, network_recv) = channel::<NetworkMessage>();
|
||||||
// launch message handler thread
|
// launch message handler thread
|
||||||
let message_handler_log = log.new(o!("Service" => "MessageHandler"));
|
let message_handler_log = log.new(o!("Service" => "MessageHandler"));
|
||||||
let message_handler_send = MessageHandler::new(
|
let message_handler_send = MessageHandler::spawn(
|
||||||
beacon_chain,
|
beacon_chain,
|
||||||
network_send.clone(),
|
network_send.clone(),
|
||||||
executor,
|
executor,
|
||||||
|
@ -66,7 +66,7 @@ impl SimpleSync {
|
|||||||
//TODO: Paul to verify the logic of these fields.
|
//TODO: Paul to verify the logic of these fields.
|
||||||
HelloMessage {
|
HelloMessage {
|
||||||
network_id: self.network_id,
|
network_id: self.network_id,
|
||||||
latest_finalized_root: state.finalized_root.clone(),
|
latest_finalized_root: state.finalized_root,
|
||||||
latest_finalized_epoch: state.finalized_epoch,
|
latest_finalized_epoch: state.finalized_epoch,
|
||||||
best_root: state.latest_block_roots[0], //TODO: build correct value as a beacon chain function
|
best_root: state.latest_block_roots[0], //TODO: build correct value as a beacon chain function
|
||||||
best_slot: state.slot - 1,
|
best_slot: state.slot - 1,
|
||||||
|
@ -6,7 +6,7 @@ extern crate target_info;
|
|||||||
|
|
||||||
use target_info::Target;
|
use target_info::Target;
|
||||||
|
|
||||||
const TRACK: &'static str = "unstable";
|
const TRACK: &str = "unstable";
|
||||||
|
|
||||||
/// Provides the current platform
|
/// Provides the current platform
|
||||||
pub fn platform() -> String {
|
pub fn platform() -> String {
|
||||||
|
@ -219,10 +219,8 @@ impl<T: ClientDB + Sized> ForkChoice for SlowLMDGhost<T> {
|
|||||||
head_vote_count = vote_count;
|
head_vote_count = vote_count;
|
||||||
}
|
}
|
||||||
// resolve ties - choose smaller hash
|
// resolve ties - choose smaller hash
|
||||||
else if vote_count == head_vote_count {
|
else if vote_count == head_vote_count && *child_hash < head_hash {
|
||||||
if *child_hash < head_hash {
|
head_hash = *child_hash;
|
||||||
head_hash = *child_hash;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user