From: Valentine Wallace Date: Fri, 2 Sep 2022 17:41:41 +0000 (-0400) Subject: Don't construct OnionMessage while holding peer lock X-Git-Tag: v0.0.111~20^2~1 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=04f467342851691d368df1eb318bcfaf6c58a607;p=rust-lightning Don't construct OnionMessage while holding peer lock --- 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); } };