diff --git a/beacon_node/eth2_libp2p/src/peer_manager/mod.rs b/beacon_node/eth2_libp2p/src/peer_manager/mod.rs index 7fce5f929..60af72464 100644 --- a/beacon_node/eth2_libp2p/src/peer_manager/mod.rs +++ b/beacon_node/eth2_libp2p/src/peer_manager/mod.rs @@ -519,10 +519,7 @@ impl PeerManager { let mut out_list = enr.multiaddr(); out_list.retain(|addr| { addr.iter() - .find(|v| match v { - MProtocol::Udp(_) => true, - _ => false, - }) + .find(|v| matches!(v, MProtocol::Udp(_))) .is_none() }); diff --git a/beacon_node/eth2_libp2p/src/peer_manager/peer_info.rs b/beacon_node/eth2_libp2p/src/peer_manager/peer_info.rs index b62fba504..f0872968e 100644 --- a/beacon_node/eth2_libp2p/src/peer_manager/peer_info.rs +++ b/beacon_node/eth2_libp2p/src/peer_manager/peer_info.rs @@ -228,18 +228,12 @@ impl Default for PeerConnectionStatus { impl PeerConnectionStatus { /// Checks if the status is connected. pub fn is_connected(&self) -> bool { - match self { - PeerConnectionStatus::Connected { .. } => true, - _ => false, - } + matches!(self, PeerConnectionStatus::Connected { .. }) } /// Checks if the status is connected. pub fn is_dialing(&self) -> bool { - match self { - PeerConnectionStatus::Dialing { .. } => true, - _ => false, - } + matches!(self, PeerConnectionStatus::Dialing { .. }) } /// The peer is either connected or in the process of being dialed. @@ -249,18 +243,12 @@ impl PeerConnectionStatus { /// Checks if the status is banned. pub fn is_banned(&self) -> bool { - match self { - PeerConnectionStatus::Banned { .. } => true, - _ => false, - } + matches!(self, PeerConnectionStatus::Banned { .. }) } /// Checks if the status is disconnected. pub fn is_disconnected(&self) -> bool { - match self { - Disconnected { .. } => true, - _ => false, - } + matches!(self, Disconnected { .. }) } /// Modifies the status to Connected and increases the number of ingoing diff --git a/beacon_node/eth2_libp2p/src/peer_manager/peer_sync_status.rs b/beacon_node/eth2_libp2p/src/peer_manager/peer_sync_status.rs index 9d0e6c1cf..d044a9095 100644 --- a/beacon_node/eth2_libp2p/src/peer_manager/peer_sync_status.rs +++ b/beacon_node/eth2_libp2p/src/peer_manager/peer_sync_status.rs @@ -29,26 +29,17 @@ pub struct SyncInfo { impl PeerSyncStatus { /// Returns true if the peer has advanced knowledge of the chain. pub fn is_advanced(&self) -> bool { - match self { - PeerSyncStatus::Advanced { .. } => true, - _ => false, - } + matches!(self, PeerSyncStatus::Advanced { .. }) } /// Returns true if the peer is up to date with the current chain. pub fn is_synced(&self) -> bool { - match self { - PeerSyncStatus::Synced { .. } => true, - _ => false, - } + matches!(self, PeerSyncStatus::Synced { .. }) } /// Returns true if the peer is behind the current chain. pub fn is_behind(&self) -> bool { - match self { - PeerSyncStatus::Behind { .. } => true, - _ => false, - } + matches!(self, PeerSyncStatus::Behind { .. }) } /// Updates the sync state given a fully synced peer. diff --git a/beacon_node/eth2_libp2p/src/peer_manager/peerdb.rs b/beacon_node/eth2_libp2p/src/peer_manager/peerdb.rs index 184baa5b2..9a7914750 100644 --- a/beacon_node/eth2_libp2p/src/peer_manager/peerdb.rs +++ b/beacon_node/eth2_libp2p/src/peer_manager/peerdb.rs @@ -136,20 +136,16 @@ impl PeerDB { /// Returns if the peer is already connected. pub fn is_connected(&self, peer_id: &PeerId) -> bool { - if let Some(PeerConnectionStatus::Connected { .. }) = self.connection_status(peer_id) { - true - } else { - false - } + matches!( + self.connection_status(peer_id), + Some(PeerConnectionStatus::Connected { .. }) + ) } /// If we are connected or currently dialing the peer returns true. pub fn is_connected_or_dialing(&self, peer_id: &PeerId) -> bool { - match self.connection_status(peer_id) { - Some(PeerConnectionStatus::Connected { .. }) - | Some(PeerConnectionStatus::Dialing { .. }) => true, - _ => false, - } + matches!(self.connection_status(peer_id), Some(PeerConnectionStatus::Connected { .. }) + | Some(PeerConnectionStatus::Dialing { .. })) } /// Returns true if the peer is synced at least to our current head. pub fn is_synced(&self, peer_id: &PeerId) -> bool { diff --git a/beacon_node/eth2_libp2p/src/rpc/methods.rs b/beacon_node/eth2_libp2p/src/rpc/methods.rs index f3a239c8d..0fe4d1347 100644 --- a/beacon_node/eth2_libp2p/src/rpc/methods.rs +++ b/beacon_node/eth2_libp2p/src/rpc/methods.rs @@ -277,10 +277,7 @@ impl RPCCodedResponse { /// Tells the codec whether to decode as an RPCResponse or an error. pub fn is_response(response_code: u8) -> bool { - match response_code { - 0 => true, - _ => false, - } + matches!(response_code, 0) } /// Builds an RPCCodedResponse from a response code and an ErrorMessage @@ -311,10 +308,7 @@ impl RPCCodedResponse { /// Returns true if this response always terminates the stream. pub fn close_after(&self) -> bool { - match self { - RPCCodedResponse::Success(_) => false, - _ => true, - } + !matches!(self, RPCCodedResponse::Success(_)) } } diff --git a/beacon_node/eth2_libp2p/src/types/sync_state.rs b/beacon_node/eth2_libp2p/src/types/sync_state.rs index 572d33a31..94e066cff 100644 --- a/beacon_node/eth2_libp2p/src/types/sync_state.rs +++ b/beacon_node/eth2_libp2p/src/types/sync_state.rs @@ -47,10 +47,7 @@ impl SyncState { /// Returns true if the node is synced. pub fn is_synced(&self) -> bool { - match self { - SyncState::Synced => true, - _ => false, - } + matches!(self, SyncState::Synced) } } diff --git a/consensus/merkle_proof/src/lib.rs b/consensus/merkle_proof/src/lib.rs index 4f86cde1f..76acb3c04 100644 --- a/consensus/merkle_proof/src/lib.rs +++ b/consensus/merkle_proof/src/lib.rs @@ -156,10 +156,7 @@ impl MerkleTree { /// Is this Merkle tree a leaf? pub fn is_leaf(&self) -> bool { - match self { - MerkleTree::Leaf(_) => true, - _ => false, - } + matches!(self, MerkleTree::Leaf(_)) } /// Return the leaf at `index` and a Merkle proof of its inclusion. diff --git a/testing/ef_tests/src/error.rs b/testing/ef_tests/src/error.rs index 2adec6dc1..1d1844558 100644 --- a/testing/ef_tests/src/error.rs +++ b/testing/ef_tests/src/error.rs @@ -37,9 +37,6 @@ impl Error { } pub fn is_skipped(&self) -> bool { - match self { - Error::SkippedBls | Error::SkippedKnownFailure => true, - _ => false, - } + matches!(self, Error::SkippedBls | Error::SkippedKnownFailure) } }