-
Notifications
You must be signed in to change notification settings - Fork 214
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix clippy warnings #500
base: master
Are you sure you want to change the base?
Fix clippy warnings #500
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,4 +68,8 @@ impl RecvMessage { | |
RecvMessage::Text(s) => s.len(), | ||
} | ||
} | ||
|
||
pub fn is_empty(&self) -> bool { | ||
self.len() == 0 | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,13 +55,13 @@ pub enum FromShardWebsocket { | |
Add { | ||
local_id: ShardNodeId, | ||
ip: std::net::IpAddr, | ||
node: common::node_types::NodeDetails, | ||
node: Box<common::node_types::NodeDetails>, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I think that is small enough to avoid to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, but enum variant is around 369 bytes:
|
||
genesis_hash: common::node_types::BlockHash, | ||
}, | ||
/// Update/pass through details about a node. | ||
Update { | ||
local_id: ShardNodeId, | ||
payload: node_message::Payload, | ||
payload: Box<node_message::Payload>, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Clippy seems to use 200 as default, https://rust-lang.github.io/rust-clippy/master/#large_enum_variant |
||
}, | ||
/// Tell the aggregator that a node has been removed when it disconnects. | ||
Remove { local_id: ShardNodeId }, | ||
|
@@ -327,7 +327,7 @@ impl InnerLoop { | |
} => { | ||
// Conditionally modify the node's details to include the IP address. | ||
node.ip = self.expose_node_ips.then_some(ip.to_string().into()); | ||
match self.node_state.add_node(genesis_hash, node) { | ||
match self.node_state.add_node(genesis_hash, *node) { | ||
state::AddNodeResult::ChainOnDenyList => { | ||
if let Some(shard_conn) = self.shard_channels.get_mut(&shard_conn_id) { | ||
let _ = shard_conn.send(ToShardWebsocket::Mute { | ||
|
@@ -411,7 +411,7 @@ impl InnerLoop { | |
|
||
let mut feed_message_serializer = FeedMessageSerializer::new(); | ||
self.node_state | ||
.update_node(node_id, payload, &mut feed_message_serializer); | ||
.update_node(node_id, *payload, &mut feed_message_serializer); | ||
|
||
if let Some(chain) = self.node_state.get_chain_by_node_id(node_id) { | ||
let genesis_hash = chain.genesis_hash(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ use common::node_types::BlockHash; | |
use common::node_types::{Block, Timestamp}; | ||
use common::{id_type, time, DenseMap, MostSeen, NumStats}; | ||
use once_cell::sync::Lazy; | ||
use std::cmp::Ordering; | ||
use std::collections::HashSet; | ||
use std::str::FromStr; | ||
use std::time::{Duration, Instant}; | ||
|
@@ -252,30 +253,34 @@ impl Chain { | |
}; | ||
|
||
if node.update_block(*block) { | ||
if block.height > self.best.height { | ||
self.best = *block; | ||
log::debug!( | ||
"[{}] [nodes={}] new best block={}/{:?}", | ||
self.labels.best(), | ||
nodes_len, | ||
self.best.height, | ||
self.best.hash, | ||
); | ||
if let Some(timestamp) = self.timestamp { | ||
self.block_times.push(now.saturating_sub(timestamp)); | ||
self.average_block_time = Some(self.block_times.average()); | ||
match block.height.cmp(&self.best.height) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not a fan of this change if think the old code was easier to read. which clippy lint is this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
Ordering::Greater => { | ||
self.best = *block; | ||
log::debug!( | ||
"[{}] [nodes={}] new best block={}/{:?}", | ||
self.labels.best(), | ||
nodes_len, | ||
self.best.height, | ||
self.best.hash, | ||
); | ||
if let Some(timestamp) = self.timestamp { | ||
self.block_times.push(now.saturating_sub(timestamp)); | ||
self.average_block_time = Some(self.block_times.average()); | ||
} | ||
self.timestamp = Some(now); | ||
feed.push(feed_message::BestBlock( | ||
self.best.height, | ||
now, | ||
self.average_block_time, | ||
)); | ||
propagation_time = Some(0); | ||
} | ||
self.timestamp = Some(now); | ||
feed.push(feed_message::BestBlock( | ||
self.best.height, | ||
now, | ||
self.average_block_time, | ||
)); | ||
propagation_time = Some(0); | ||
} else if block.height == self.best.height { | ||
if let Some(timestamp) = self.timestamp { | ||
propagation_time = Some(now.saturating_sub(timestamp)); | ||
Ordering::Equal => { | ||
if let Some(timestamp) = self.timestamp { | ||
propagation_time = Some(now.saturating_sub(timestamp)) | ||
} | ||
} | ||
Ordering::Less => (), | ||
} | ||
|
||
if let Some(details) = node.update_details(now, propagation_time) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess
#[derive(Default)]
didn't work? I'd prefer that if possible :)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BiMap
doesn't impl Default