Skip to content

Commit 04f4673

Browse files
Don't construct OnionMessage while holding peer lock
1 parent b9b02b4 commit 04f4673

File tree

1 file changed

+23
-24
lines changed

1 file changed

+23
-24
lines changed

lightning/src/onion_message/messenger.rs

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,28 @@ impl<Signer: Sign, K: Deref, L: Deref> OnionMessageHandler for OnionMessenger<Si
255255
hop_data: new_packet_bytes,
256256
hmac: next_hop_hmac,
257257
};
258+
let onion_message = msgs::OnionMessage {
259+
blinding_point: match next_blinding_override {
260+
Some(blinding_point) => blinding_point,
261+
None => {
262+
let blinding_factor = {
263+
let mut sha = Sha256::engine();
264+
sha.input(&msg.blinding_point.serialize()[..]);
265+
sha.input(control_tlvs_ss.as_ref());
266+
Sha256::from_engine(sha).into_inner()
267+
};
268+
let next_blinding_point = msg.blinding_point;
269+
match next_blinding_point.mul_tweak(&self.secp_ctx, &Scalar::from_be_bytes(blinding_factor).unwrap()) {
270+
Ok(bp) => bp,
271+
Err(e) => {
272+
log_trace!(self.logger, "Failed to compute next blinding point: {}", e);
273+
return
274+
}
275+
}
276+
},
277+
},
278+
onion_routing_packet: outgoing_packet,
279+
};
258280

259281
let mut pending_per_peer_msgs = self.pending_messages.lock().unwrap();
260282

@@ -267,30 +289,7 @@ impl<Signer: Sign, K: Deref, L: Deref> OnionMessageHandler for OnionMessenger<Si
267289
return
268290
},
269291
hash_map::Entry::Occupied(mut e) => {
270-
e.get_mut().push_back(
271-
msgs::OnionMessage {
272-
blinding_point: match next_blinding_override {
273-
Some(blinding_point) => blinding_point,
274-
None => {
275-
let blinding_factor = {
276-
let mut sha = Sha256::engine();
277-
sha.input(&msg.blinding_point.serialize()[..]);
278-
sha.input(control_tlvs_ss.as_ref());
279-
Sha256::from_engine(sha).into_inner()
280-
};
281-
let next_blinding_point = msg.blinding_point;
282-
match next_blinding_point.mul_tweak(&self.secp_ctx, &Scalar::from_be_bytes(blinding_factor).unwrap()) {
283-
Ok(bp) => bp,
284-
Err(e) => {
285-
log_trace!(self.logger, "Failed to compute next blinding point: {}", e);
286-
return
287-
}
288-
}
289-
},
290-
},
291-
onion_routing_packet: outgoing_packet,
292-
},
293-
);
292+
e.get_mut().push_back(onion_message);
294293
log_trace!(self.logger, "Forwarding an onion message to peer {}", next_node_id);
295294
}
296295
};

0 commit comments

Comments
 (0)