Skip to content

Commit 69a7bb2

Browse files
committed
Add BlindedPath::introduction_node_id method
Blinded paths use a pubkey to identify the introduction node, but it will soon allow using a directed short channel id instead. Add an introduction_node_id method to BlindedPath to facilitate lookup in the latter case.
1 parent ff65f5d commit 69a7bb2

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

lightning/src/blinded_path/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use bitcoin::secp256k1::{self, PublicKey, Secp256k1, SecretKey};
1717

1818
use crate::ln::msgs::DecodeError;
1919
use crate::offers::invoice::BlindedPayInfo;
20+
use crate::routing::gossip::{NodeId, ReadOnlyNetworkGraph};
2021
use crate::sign::EntropySource;
2122
use crate::util::ser::{Readable, Writeable, Writer};
2223

@@ -125,6 +126,14 @@ impl BlindedPath {
125126
).map_err(|_| ())?,
126127
}))
127128
}
129+
130+
/// Returns the introduction [`NodeId`] of the blinded path.
131+
pub fn introduction_node_id<'a>(
132+
&self, network_graph: &'a ReadOnlyNetworkGraph
133+
) -> Option<&'a NodeId> {
134+
let node_id = NodeId::from_pubkey(&self.introduction_node_id);
135+
network_graph.nodes().get_key_value(&node_id).map(|(key, _)| key)
136+
}
128137
}
129138

130139
impl Writeable for BlindedPath {

lightning/src/routing/router.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1863,17 +1863,17 @@ where L::Target: Logger {
18631863
}
18641864
},
18651865
Payee::Blinded { route_hints, .. } => {
1866-
if route_hints.iter().all(|(_, path)| &path.introduction_node_id == our_node_pubkey) {
1866+
if route_hints.iter().all(|(_, path)| path.introduction_node_id(network_graph) == Some(&our_node_id)) {
18671867
return Err(LightningError{err: "Cannot generate a route to blinded paths if we are the introduction node to all of them".to_owned(), action: ErrorAction::IgnoreError});
18681868
}
18691869
for (_, blinded_path) in route_hints.iter() {
18701870
if blinded_path.blinded_hops.len() == 0 {
18711871
return Err(LightningError{err: "0-hop blinded path provided".to_owned(), action: ErrorAction::IgnoreError});
1872-
} else if &blinded_path.introduction_node_id == our_node_pubkey {
1872+
} else if blinded_path.introduction_node_id(network_graph) == Some(&our_node_id) {
18731873
log_info!(logger, "Got blinded path with ourselves as the introduction node, ignoring");
18741874
} else if blinded_path.blinded_hops.len() == 1 &&
18751875
route_hints.iter().any( |(_, p)| p.blinded_hops.len() == 1
1876-
&& p.introduction_node_id != blinded_path.introduction_node_id)
1876+
&& p.introduction_node_id(network_graph) != blinded_path.introduction_node_id(network_graph))
18771877
{
18781878
return Err(LightningError{err: format!("1-hop blinded paths must all have matching introduction node ids"), action: ErrorAction::IgnoreError});
18791879
}
@@ -5303,10 +5303,15 @@ mod tests {
53035303
if let Some(bt) = &path.blinded_tail {
53045304
assert_eq!(path.hops.len() + if bt.hops.len() == 1 { 0 } else { 1 }, 2);
53055305
if bt.hops.len() > 1 {
5306-
assert_eq!(path.hops.last().unwrap().pubkey,
5306+
let network_graph = network_graph.read_only();
5307+
assert_eq!(
5308+
NodeId::from_pubkey(&path.hops.last().unwrap().pubkey),
53075309
payment_params.payee.blinded_route_hints().iter()
53085310
.find(|(p, _)| p.htlc_maximum_msat == path.final_value_msat())
5309-
.map(|(_, p)| p.introduction_node_id).unwrap());
5311+
.and_then(|(_, p)| p.introduction_node_id(&network_graph))
5312+
.copied()
5313+
.unwrap()
5314+
);
53105315
} else {
53115316
assert_eq!(path.hops.last().unwrap().pubkey, nodes[2]);
53125317
}
@@ -7434,7 +7439,10 @@ mod tests {
74347439
assert_eq!(tail.final_value_msat, 1001);
74357440

74367441
let final_hop = route.paths[0].hops.last().unwrap();
7437-
assert_eq!(final_hop.pubkey, blinded_path.introduction_node_id);
7442+
assert_eq!(
7443+
NodeId::from_pubkey(&final_hop.pubkey),
7444+
*blinded_path.introduction_node_id(&network_graph).unwrap()
7445+
);
74387446
if tail.hops.len() > 1 {
74397447
assert_eq!(final_hop.fee_msat,
74407448
blinded_payinfo.fee_base_msat as u64 + blinded_payinfo.fee_proportional_millionths as u64 * tail.final_value_msat / 1000000);

0 commit comments

Comments
 (0)