From 895d1a8504a436904ac3f06b009137e480c21a09 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Mon, 21 Jun 2021 18:48:51 +0000 Subject: [PATCH] [peer_handler] Drop unused return from get_peer_for_forwarding!() This avoids a now-unnecessary SocketDescriptor clone() call in addition to cleaning up the callsite code somewhat. --- lightning/src/ln/peer_handler.rs | 51 ++++++++++++++++---------------- 1 file changed, 25 insertions(+), 26 deletions(-) diff --git a/lightning/src/ln/peer_handler.rs b/lightning/src/ln/peer_handler.rs index ac6cef292..2eb9b2e78 100644 --- a/lightning/src/ln/peer_handler.rs +++ b/lightning/src/ln/peer_handler.rs @@ -1094,20 +1094,19 @@ impl PeerManager { { - let descriptor = match peers.node_id_to_descriptor.get($node_id) { - Some(descriptor) => descriptor.clone(), + match peers.node_id_to_descriptor.get($node_id) { + Some(descriptor) => match peers.peers.get_mut(&descriptor) { + Some(peer) => { + if peer.their_features.is_none() { + continue; + } + peer + }, + None => panic!("Inconsistent peers set state!"), + }, None => { continue; }, - }; - match peers.peers.get_mut(&descriptor) { - Some(peer) => { - if peer.their_features.is_none() { - continue; - } - (descriptor, peer) - }, - None => panic!("Inconsistent peers set state!"), } } } @@ -1117,14 +1116,14 @@ impl PeerManager { log_trace!(self.logger, "Handling SendOpenChannel event in peer_handler for node {} for channel {}", log_pubkey!(node_id), log_bytes!(msg.temporary_channel_id)); - let (_, peer) = get_peer_for_forwarding!(node_id); + let peer = get_peer_for_forwarding!(node_id); peer.pending_outbound_buffer.push_back(peer.channel_encryptor.encrypt_message(&encode_msg!(msg))); }, MessageSendEvent::SendFundingCreated { ref node_id, ref msg } => { @@ -1134,28 +1133,28 @@ impl PeerManager { log_trace!(self.logger, "Handling SendFundingSigned event in peer_handler for node {} for channel {}", log_pubkey!(node_id), log_bytes!(msg.channel_id)); - let (_, peer) = get_peer_for_forwarding!(node_id); + let peer = get_peer_for_forwarding!(node_id); peer.pending_outbound_buffer.push_back(peer.channel_encryptor.encrypt_message(&encode_msg!(msg))); }, MessageSendEvent::SendFundingLocked { ref node_id, ref msg } => { log_trace!(self.logger, "Handling SendFundingLocked event in peer_handler for node {} for channel {}", log_pubkey!(node_id), log_bytes!(msg.channel_id)); - let (_, peer) = get_peer_for_forwarding!(node_id); + let peer = get_peer_for_forwarding!(node_id); peer.pending_outbound_buffer.push_back(peer.channel_encryptor.encrypt_message(&encode_msg!(msg))); }, MessageSendEvent::SendAnnouncementSignatures { ref node_id, ref msg } => { log_trace!(self.logger, "Handling SendAnnouncementSignatures event in peer_handler for node {} for channel {})", log_pubkey!(node_id), log_bytes!(msg.channel_id)); - let (_, peer) = get_peer_for_forwarding!(node_id); + let peer = get_peer_for_forwarding!(node_id); peer.pending_outbound_buffer.push_back(peer.channel_encryptor.encrypt_message(&encode_msg!(msg))); }, MessageSendEvent::UpdateHTLCs { ref node_id, updates: msgs::CommitmentUpdate { ref update_add_htlcs, ref update_fulfill_htlcs, ref update_fail_htlcs, ref update_fail_malformed_htlcs, ref update_fee, ref commitment_signed } } => { @@ -1165,7 +1164,7 @@ impl PeerManager PeerManager { log_trace!(self.logger, "Handling SendClosingSigned event in peer_handler for node {} for channel {}", log_pubkey!(node_id), log_bytes!(msg.channel_id)); - let (_, peer) = get_peer_for_forwarding!(node_id); + let peer = get_peer_for_forwarding!(node_id); peer.pending_outbound_buffer.push_back(peer.channel_encryptor.encrypt_message(&encode_msg!(msg))); }, MessageSendEvent::SendShutdown { ref node_id, ref msg } => { log_trace!(self.logger, "Handling Shutdown event in peer_handler for node {} for channel {}", log_pubkey!(node_id), log_bytes!(msg.channel_id)); - let (_, peer) = get_peer_for_forwarding!(node_id); + let peer = get_peer_for_forwarding!(node_id); peer.pending_outbound_buffer.push_back(peer.channel_encryptor.encrypt_message(&encode_msg!(msg))); }, MessageSendEvent::SendChannelReestablish { ref node_id, ref msg } => { log_trace!(self.logger, "Handling SendChannelReestablish event in peer_handler for node {} for channel {}", log_pubkey!(node_id), log_bytes!(msg.channel_id)); - let (_, peer) = get_peer_for_forwarding!(node_id); + let peer = get_peer_for_forwarding!(node_id); peer.pending_outbound_buffer.push_back(peer.channel_encryptor.encrypt_message(&encode_msg!(msg))); }, MessageSendEvent::BroadcastChannelAnnouncement { msg, update_msg } => { @@ -1259,17 +1258,17 @@ impl PeerManager { - let (_, peer) = get_peer_for_forwarding!(node_id); + let peer = get_peer_for_forwarding!(node_id); peer.pending_outbound_buffer.push_back(peer.channel_encryptor.encrypt_message(&encode_msg!(msg))); }, MessageSendEvent::SendShortIdsQuery { ref node_id, ref msg } => { - let (_, peer) = get_peer_for_forwarding!(node_id); + let peer = get_peer_for_forwarding!(node_id); peer.pending_outbound_buffer.push_back(peer.channel_encryptor.encrypt_message(&encode_msg!(msg))); } MessageSendEvent::SendReplyChannelRange { ref node_id, ref msg } => { @@ -1279,7 +1278,7 @@ impl PeerManager