Skip to content

Commit 89a67e5

Browse files
committed
Rename and expose message-specific NextHop
`onion::message::messenger::PeeledOnion` is a public enum which included the private enum `NextHop`, which is not acceptable. Thus, we here expose `NextHop` but rename it `NextMessageHop` to make clear that it is specific to messages.
1 parent b403411 commit 89a67e5

File tree

4 files changed

+29
-27
lines changed

4 files changed

+29
-27
lines changed

lightning/src/blinded_path/message.rs

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use bitcoin::secp256k1::{self, PublicKey, Secp256k1, SecretKey};
33
#[allow(unused_imports)]
44
use crate::prelude::*;
55

6-
use crate::blinded_path::{BlindedHop, BlindedPath, IntroductionNode, NodeIdLookUp};
6+
use crate::blinded_path::{BlindedHop, BlindedPath, IntroductionNode, NextMessageHop, NodeIdLookUp};
77
use crate::blinded_path::utils;
88
use crate::io;
99
use crate::io::Cursor;
@@ -20,7 +20,7 @@ use core::ops::Deref;
2020
/// route, they are encoded into [`BlindedHop::encrypted_payload`].
2121
pub(crate) struct ForwardTlvs {
2222
/// The next hop in the onion message's path.
23-
pub(crate) next_hop: NextHop,
23+
pub(crate) next_hop: NextMessageHop,
2424
/// Senders to a blinded path use this value to concatenate the route they find to the
2525
/// introduction node with the blinded path.
2626
pub(crate) next_blinding_override: Option<PublicKey>,
@@ -34,20 +34,11 @@ pub(crate) struct ReceiveTlvs {
3434
pub(crate) path_id: Option<[u8; 32]>,
3535
}
3636

37-
/// The next hop to forward the onion message along its path.
38-
#[derive(Debug)]
39-
pub enum NextHop {
40-
/// The node id of the next hop.
41-
NodeId(PublicKey),
42-
/// The short channel id leading to the next hop.
43-
ShortChannelId(u64),
44-
}
45-
4637
impl Writeable for ForwardTlvs {
4738
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), io::Error> {
4839
let (next_node_id, short_channel_id) = match self.next_hop {
49-
NextHop::NodeId(pubkey) => (Some(pubkey), None),
50-
NextHop::ShortChannelId(scid) => (None, Some(scid)),
40+
NextMessageHop::NodeId(pubkey) => (Some(pubkey), None),
41+
NextMessageHop::ShortChannelId(scid) => (None, Some(scid)),
5142
};
5243
// TODO: write padding
5344
encode_tlv_stream!(writer, {
@@ -75,7 +66,7 @@ pub(super) fn blinded_hops<T: secp256k1::Signing + secp256k1::Verification>(
7566
) -> Result<Vec<BlindedHop>, secp256k1::Error> {
7667
let blinded_tlvs = unblinded_path.iter()
7768
.skip(1) // The first node's TLVs contains the next node's pubkey
78-
.map(|pk| ForwardTlvs { next_hop: NextHop::NodeId(*pk), next_blinding_override: None })
69+
.map(|pk| ForwardTlvs { next_hop: NextMessageHop::NodeId(*pk), next_blinding_override: None })
7970
.map(|tlvs| ControlTlvs::Forward(tlvs))
8071
.chain(core::iter::once(ControlTlvs::Receive(ReceiveTlvs { path_id: None })));
8172

@@ -102,8 +93,8 @@ where
10293
readable: ControlTlvs::Forward(ForwardTlvs { next_hop, next_blinding_override })
10394
}) => {
10495
let next_node_id = match next_hop {
105-
NextHop::NodeId(pubkey) => pubkey,
106-
NextHop::ShortChannelId(scid) => match node_id_lookup.next_node_id(scid) {
96+
NextMessageHop::NodeId(pubkey) => pubkey,
97+
NextMessageHop::ShortChannelId(scid) => match node_id_lookup.next_node_id(scid) {
10798
Some(pubkey) => pubkey,
10899
None => return Err(()),
109100
},

lightning/src/blinded_path/mod.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,17 @@ use crate::util::ser::{Readable, Writeable, Writer};
2424
use crate::io;
2525
use crate::prelude::*;
2626

27+
/// The next hop to forward an onion message along its path.
28+
///
29+
/// Note that payment blinded paths always specify their next hop using an explicit node id.
30+
#[derive(Debug)]
31+
pub enum NextMessageHop {
32+
/// The node id of the next hop.
33+
NodeId(PublicKey),
34+
/// The short channel id leading to the next hop.
35+
ShortChannelId(u64),
36+
}
37+
2738
/// Onion messages and payments can be sent and received to blinded paths, which serve to hide the
2839
/// identity of the recipient.
2940
#[derive(Clone, Debug, Hash, PartialEq, Eq)]

lightning/src/onion_message/messenger.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ use bitcoin::hashes::hmac::{Hmac, HmacEngine};
1515
use bitcoin::hashes::sha256::Hash as Sha256;
1616
use bitcoin::secp256k1::{self, PublicKey, Scalar, Secp256k1, SecretKey};
1717

18-
use crate::blinded_path::{BlindedPath, IntroductionNode, NodeIdLookUp};
19-
use crate::blinded_path::message::{advance_path_by_one, ForwardTlvs, NextHop, ReceiveTlvs};
18+
use crate::blinded_path::{BlindedPath, IntroductionNode, NextMessageHop, NodeIdLookUp};
19+
use crate::blinded_path::message::{advance_path_by_one, ForwardTlvs, ReceiveTlvs};
2020
use crate::blinded_path::utils;
2121
use crate::events::{Event, EventHandler, EventsProvider};
2222
use crate::sign::{EntropySource, NodeSigner, Recipient};
@@ -572,7 +572,7 @@ pub trait CustomOnionMessageHandler {
572572
#[derive(Debug)]
573573
pub enum PeeledOnion<T: OnionMessageContents> {
574574
/// Forwarded onion, with the next node id and a new onion
575-
Forward(NextHop, OnionMessage),
575+
Forward(NextMessageHop, OnionMessage),
576576
/// Received onion message, with decrypted contents, path_id, and reply path
577577
Receive(ParsedOnionMessageContents<T>, Option<[u8; 32]>, Option<BlindedPath>)
578578
}
@@ -1050,8 +1050,8 @@ where
10501050
},
10511051
Ok(PeeledOnion::Forward(next_hop, onion_message)) => {
10521052
let next_node_id = match next_hop {
1053-
NextHop::NodeId(pubkey) => pubkey,
1054-
NextHop::ShortChannelId(scid) => match self.node_id_lookup.next_node_id(scid) {
1053+
NextMessageHop::NodeId(pubkey) => pubkey,
1054+
NextMessageHop::ShortChannelId(scid) => match self.node_id_lookup.next_node_id(scid) {
10551055
Some(pubkey) => pubkey,
10561056
None => {
10571057
log_trace!(self.logger, "Dropping forwarded onion messager: unable to resolve next hop using SCID {}", scid);
@@ -1255,7 +1255,7 @@ fn packet_payloads_and_keys<T: OnionMessageContents, S: secp256k1::Signing + sec
12551255
if let Some(ss) = prev_control_tlvs_ss.take() {
12561256
payloads.push((Payload::Forward(ForwardControlTlvs::Unblinded(
12571257
ForwardTlvs {
1258-
next_hop: NextHop::NodeId(unblinded_pk_opt.unwrap()),
1258+
next_hop: NextMessageHop::NodeId(unblinded_pk_opt.unwrap()),
12591259
next_blinding_override: None,
12601260
}
12611261
)), ss));
@@ -1265,7 +1265,7 @@ fn packet_payloads_and_keys<T: OnionMessageContents, S: secp256k1::Signing + sec
12651265
} else if let Some((intro_node_id, blinding_pt)) = intro_node_id_blinding_pt.take() {
12661266
if let Some(control_tlvs_ss) = prev_control_tlvs_ss.take() {
12671267
payloads.push((Payload::Forward(ForwardControlTlvs::Unblinded(ForwardTlvs {
1268-
next_hop: NextHop::NodeId(intro_node_id),
1268+
next_hop: NextMessageHop::NodeId(intro_node_id),
12691269
next_blinding_override: Some(blinding_pt),
12701270
})), control_tlvs_ss));
12711271
}

lightning/src/onion_message/packet.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
use bitcoin::secp256k1::PublicKey;
1313
use bitcoin::secp256k1::ecdh::SharedSecret;
1414

15-
use crate::blinded_path::BlindedPath;
16-
use crate::blinded_path::message::{ForwardTlvs, NextHop, ReceiveTlvs};
15+
use crate::blinded_path::{BlindedPath, NextMessageHop};
16+
use crate::blinded_path::message::{ForwardTlvs, ReceiveTlvs};
1717
use crate::blinded_path::utils::Padding;
1818
use crate::ln::msgs::DecodeError;
1919
use crate::ln::onion_utils;
@@ -293,8 +293,8 @@ impl Readable for ControlTlvs {
293293

294294
let next_hop = match (short_channel_id, next_node_id) {
295295
(Some(_), Some(_)) => return Err(DecodeError::InvalidValue),
296-
(Some(scid), None) => Some(NextHop::ShortChannelId(scid)),
297-
(None, Some(pubkey)) => Some(NextHop::NodeId(pubkey)),
296+
(Some(scid), None) => Some(NextMessageHop::ShortChannelId(scid)),
297+
(None, Some(pubkey)) => Some(NextMessageHop::NodeId(pubkey)),
298298
(None, None) => None,
299299
};
300300

0 commit comments

Comments
 (0)