From 04f467342851691d368df1eb318bcfaf6c58a607 Mon Sep 17 00:00:00 2001 From: Valentine Wallace Date: Fri, 2 Sep 2022 13:41:41 -0400 Subject: [PATCH] Don't construct OnionMessage while holding peer lock --- lightning/src/onion_message/messenger.rs | 47 ++++++++++++------------ 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/lightning/src/onion_message/messenger.rs b/lightning/src/onion_message/messenger.rs index b9da9246c..a3320f10d 100644 --- a/lightning/src/onion_message/messenger.rs +++ b/lightning/src/onion_message/messenger.rs @@ -255,6 +255,28 @@ impl OnionMessageHandler for OnionMessenger blinding_point, + None => { + let blinding_factor = { + let mut sha = Sha256::engine(); + sha.input(&msg.blinding_point.serialize()[..]); + sha.input(control_tlvs_ss.as_ref()); + Sha256::from_engine(sha).into_inner() + }; + let next_blinding_point = msg.blinding_point; + match next_blinding_point.mul_tweak(&self.secp_ctx, &Scalar::from_be_bytes(blinding_factor).unwrap()) { + Ok(bp) => bp, + Err(e) => { + log_trace!(self.logger, "Failed to compute next blinding point: {}", e); + return + } + } + }, + }, + onion_routing_packet: outgoing_packet, + }; let mut pending_per_peer_msgs = self.pending_messages.lock().unwrap(); @@ -267,30 +289,7 @@ impl OnionMessageHandler for OnionMessenger { - e.get_mut().push_back( - msgs::OnionMessage { - blinding_point: match next_blinding_override { - Some(blinding_point) => blinding_point, - None => { - let blinding_factor = { - let mut sha = Sha256::engine(); - sha.input(&msg.blinding_point.serialize()[..]); - sha.input(control_tlvs_ss.as_ref()); - Sha256::from_engine(sha).into_inner() - }; - let next_blinding_point = msg.blinding_point; - match next_blinding_point.mul_tweak(&self.secp_ctx, &Scalar::from_be_bytes(blinding_factor).unwrap()) { - Ok(bp) => bp, - Err(e) => { - log_trace!(self.logger, "Failed to compute next blinding point: {}", e); - return - } - } - }, - }, - onion_routing_packet: outgoing_packet, - }, - ); + e.get_mut().push_back(onion_message); log_trace!(self.logger, "Forwarding an onion message to peer {}", next_node_id); } }; -- 2.39.5