Skip to content

Commit fb10b10

Browse files
Error when attempting to send an OM to a blinded route with 0 hops
XXX test
1 parent cf43d54 commit fb10b10

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

lightning/src/onion_message.rs

+10
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,11 @@ impl Destination {
410410
pub enum SendError {
411411
/// Errored computing onion message packet keys.
412412
Secp256k1(secp256k1::Error),
413+
/// The provided [destination] was an invalid [blinded route], due to having 0 blinded hops.
414+
///
415+
/// [destination]: Destination
416+
/// [blinded route]: BlindedRoute
417+
MissingBlindedHops,
413418
/// Because implementations such as Eclair will drop onion messages where the message packet
414419
/// exceeds 32834 bytes, we refuse to send messages where the packet exceeds this size.
415420
TooBigPacket,
@@ -451,6 +456,11 @@ impl<Signer: Sign, K: Deref, L: Deref> OnionMessenger<Signer, K, L>
451456

452457
/// Send an empty onion message to `destination`, routing it through `intermediate_nodes`.
453458
pub fn send_onion_message(&self, intermediate_nodes: Vec<PublicKey>, destination: Destination) -> Result<(), SendError> {
459+
if let Destination::BlindedRoute(BlindedRoute { ref blinded_hops, .. }) = destination {
460+
if blinded_hops.len() == 0 {
461+
return Err(SendError::MissingBlindedHops);
462+
}
463+
}
454464
let blinding_secret_bytes = self.keys_manager.get_secure_random_bytes();
455465
let blinding_secret = SecretKey::from_slice(&blinding_secret_bytes[..]).expect("RNG is busted");
456466
let (introduction_node_id, blinding_point) = if intermediate_nodes.len() != 0 {

0 commit comments

Comments
 (0)