disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);
let tor = SocketAddress::OnionV2([255, 254, 253, 252, 251, 250, 249, 248, 247, 246, 38, 7]);
- announce_node_address(charlie, &[alice, bob, david, &nodes[4], &nodes[5]], tor);
+ announce_node_address(charlie, &[alice, bob, david, &nodes[4], &nodes[5]], tor.clone());
let offer = bob.node
.create_offer_builder("coffee".to_string()).unwrap()
assert_ne!(offer.signing_pubkey(), bob_id);
assert!(!offer.paths().is_empty());
for path in offer.paths() {
+ assert_ne!(path.introduction_node_id, bob_id);
assert_ne!(path.introduction_node_id, charlie_id);
}
+
+ // Use a one-hop blinded path when Bob is announced and all his peers are Tor-only.
+ announce_node_address(&nodes[4], &[alice, bob, charlie, david, &nodes[5]], tor.clone());
+ announce_node_address(&nodes[5], &[alice, bob, charlie, david, &nodes[4]], tor.clone());
+
+ let offer = bob.node
+ .create_offer_builder("coffee".to_string()).unwrap()
+ .amount_msats(10_000_000)
+ .build().unwrap();
+ assert_ne!(offer.signing_pubkey(), bob_id);
+ assert!(!offer.paths().is_empty());
+ for path in offer.paths() {
+ assert_eq!(path.introduction_node_id, bob_id);
+ }
}
/// Checks that blinded paths prefer an introduction node that is the most connected.
const MIN_PEER_CHANNELS: usize = 3;
let network_graph = self.network_graph.deref().read_only();
+ let is_recipient_announced =
+ network_graph.nodes().contains_key(&NodeId::from_pubkey(&recipient));
+
let mut peer_info = peers.iter()
// Limit to peers with announced channels
.filter_map(|pubkey|
.filter(|info| info.channels.len() >= MIN_PEER_CHANNELS)
.map(|info| (*pubkey, info.is_tor_only(), info.channels.len()))
)
+ // Exclude Tor-only nodes when the recipient is announced.
+ .filter(|(_, is_tor_only, _)| !(*is_tor_only && is_recipient_announced))
.collect::<Vec<_>>();
// Prefer using non-Tor nodes with the most channels as the introduction node.
match paths {
Ok(paths) if !paths.is_empty() => Ok(paths),
_ => {
- if network_graph.nodes().contains_key(&NodeId::from_pubkey(&recipient)) {
+ if is_recipient_announced {
BlindedPath::one_hop_for_message(recipient, &*self.entropy_source, secp_ctx)
.map(|path| vec![path])
} else {