Skip to content

Commit 1102bc3

Browse files
committed
Pass ForwardNode when creating BlindedPath
Instead of passing Vec<PublicKey> to MessageRouter::crate_blinded_path, pass Vec<ForwardNode>. This way callers can include a short_channel_id for a more compact BlindedPath encoding.
1 parent 9984660 commit 1102bc3

File tree

8 files changed

+34
-23
lines changed

8 files changed

+34
-23
lines changed

fuzz/src/chanmon_consistency.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ use bitcoin::hashes::sha256d::Hash as Sha256dHash;
3131
use bitcoin::hash_types::{BlockHash, WPubkeyHash};
3232

3333
use lightning::blinded_path::BlindedPath;
34+
use lightning::blinded_path::message::ForwardNode;
3435
use lightning::blinded_path::payment::ReceiveTlvs;
3536
use lightning::chain;
3637
use lightning::chain::{BestBlock, ChannelMonitorUpdateStatus, chainmonitor, channelmonitor, Confirm, Watch};
@@ -119,7 +120,7 @@ impl MessageRouter for FuzzRouter {
119120
}
120121

121122
fn create_blinded_paths<T: secp256k1::Signing + secp256k1::Verification>(
122-
&self, _recipient: PublicKey, _peers: Vec<PublicKey>, _secp_ctx: &Secp256k1<T>,
123+
&self, _recipient: PublicKey, _peers: Vec<ForwardNode>, _secp_ctx: &Secp256k1<T>,
123124
) -> Result<Vec<BlindedPath>, ()> {
124125
unreachable!()
125126
}

fuzz/src/full_stack.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ use bitcoin::hashes::sha256d::Hash as Sha256dHash;
2828
use bitcoin::hash_types::{Txid, BlockHash, WPubkeyHash};
2929

3030
use lightning::blinded_path::BlindedPath;
31+
use lightning::blinded_path::message::ForwardNode;
3132
use lightning::blinded_path::payment::ReceiveTlvs;
3233
use lightning::chain;
3334
use lightning::chain::{BestBlock, ChannelMonitorUpdateStatus, Confirm, Listen};
@@ -157,7 +158,7 @@ impl MessageRouter for FuzzRouter {
157158
}
158159

159160
fn create_blinded_paths<T: secp256k1::Signing + secp256k1::Verification>(
160-
&self, _recipient: PublicKey, _peers: Vec<PublicKey>, _secp_ctx: &Secp256k1<T>,
161+
&self, _recipient: PublicKey, _peers: Vec<ForwardNode>, _secp_ctx: &Secp256k1<T>,
161162
) -> Result<Vec<BlindedPath>, ()> {
162163
unreachable!()
163164
}

fuzz/src/onion_message.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use bitcoin::secp256k1::ecdsa::RecoverableSignature;
77
use bitcoin::secp256k1::schnorr;
88

99
use lightning::blinded_path::{BlindedPath, EmptyNodeIdLookUp};
10+
use lightning::blinded_path::message::ForwardNode;
1011
use lightning::ln::features::InitFeatures;
1112
use lightning::ln::msgs::{self, DecodeError, OnionMessageHandler};
1213
use lightning::ln::script::ShutdownScript;
@@ -88,7 +89,7 @@ impl MessageRouter for TestMessageRouter {
8889
}
8990

9091
fn create_blinded_paths<T: secp256k1::Signing + secp256k1::Verification>(
91-
&self, _recipient: PublicKey, _peers: Vec<PublicKey>, _secp_ctx: &Secp256k1<T>,
92+
&self, _recipient: PublicKey, _peers: Vec<ForwardNode>, _secp_ctx: &Secp256k1<T>,
9293
) -> Result<Vec<BlindedPath>, ()> {
9394
unreachable!()
9495
}

lightning/src/ln/channel.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1403,7 +1403,7 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
14031403
/// Either the height at which this channel was created or the height at which it was last
14041404
/// serialized if it was serialized by versions prior to 0.0.103.
14051405
/// We use this to close if funding is never broadcasted.
1406-
channel_creation_height: u32,
1406+
pub(super) channel_creation_height: u32,
14071407

14081408
counterparty_dust_limit_satoshis: u64,
14091409

lightning/src/ln/channelmanager.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ use bitcoin::secp256k1::Secp256k1;
3232
use bitcoin::{secp256k1, Sequence};
3333

3434
use crate::blinded_path::{BlindedPath, NodeIdLookUp};
35+
use crate::blinded_path::message::ForwardNode;
3536
use crate::blinded_path::payment::{Bolt12OfferContext, Bolt12RefundContext, PaymentConstraints, PaymentContext, ReceiveTlvs};
3637
use crate::chain;
3738
use crate::chain::{Confirm, ChannelMonitorUpdateStatus, Watch, BestBlock};
@@ -8996,8 +8997,16 @@ where
89968997

89978998
let peers = self.per_peer_state.read().unwrap()
89988999
.iter()
8999-
.filter(|(_, peer)| peer.lock().unwrap().latest_features.supports_onion_messages())
9000-
.map(|(node_id, _)| *node_id)
9000+
.map(|(node_id, peer_state)| (node_id, peer_state.lock().unwrap()))
9001+
.filter(|(_, peer)| peer.latest_features.supports_onion_messages())
9002+
.map(|(node_id, peer)| ForwardNode {
9003+
node_id: *node_id,
9004+
short_channel_id: peer.channel_by_id
9005+
.iter()
9006+
.filter(|(_, channel)| channel.context().is_usable())
9007+
.min_by_key(|(_, channel)| channel.context().channel_creation_height)
9008+
.and_then(|(_, channel)| channel.context().get_short_channel_id()),
9009+
})
90019010
.collect::<Vec<_>>();
90029011

90039012
self.router

lightning/src/onion_message/messenger.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ pub(super) const MAX_TIMER_TICKS: usize = 2;
9898
/// # })
9999
/// # }
100100
/// # fn create_blinded_paths<T: secp256k1::Signing + secp256k1::Verification>(
101-
/// # &self, _recipient: PublicKey, _peers: Vec<PublicKey>, _secp_ctx: &Secp256k1<T>
101+
/// # &self, _recipient: PublicKey, _peers: Vec<ForwardNode>, _secp_ctx: &Secp256k1<T>
102102
/// # ) -> Result<Vec<BlindedPath>, ()> {
103103
/// # unreachable!()
104104
/// # }
@@ -341,7 +341,7 @@ pub trait MessageRouter {
341341
fn create_blinded_paths<
342342
T: secp256k1::Signing + secp256k1::Verification
343343
>(
344-
&self, recipient: PublicKey, peers: Vec<PublicKey>, secp_ctx: &Secp256k1<T>,
344+
&self, recipient: PublicKey, peers: Vec<ForwardNode>, secp_ctx: &Secp256k1<T>,
345345
) -> Result<Vec<BlindedPath>, ()>;
346346
}
347347

@@ -408,7 +408,7 @@ where
408408
fn create_blinded_paths<
409409
T: secp256k1::Signing + secp256k1::Verification
410410
>(
411-
&self, recipient: PublicKey, peers: Vec<PublicKey>, secp_ctx: &Secp256k1<T>,
411+
&self, recipient: PublicKey, peers: Vec<ForwardNode>, secp_ctx: &Secp256k1<T>,
412412
) -> Result<Vec<BlindedPath>, ()> {
413413
// Limit the number of blinded paths that are computed.
414414
const MAX_PATHS: usize = 3;
@@ -421,13 +421,13 @@ where
421421
let is_recipient_announced =
422422
network_graph.nodes().contains_key(&NodeId::from_pubkey(&recipient));
423423

424-
let mut peer_info = peers.iter()
424+
let mut peer_info = peers.into_iter()
425425
// Limit to peers with announced channels
426-
.filter_map(|pubkey|
426+
.filter_map(|peer|
427427
network_graph
428-
.node(&NodeId::from_pubkey(pubkey))
428+
.node(&NodeId::from_pubkey(&peer.node_id))
429429
.filter(|info| info.channels.len() >= MIN_PEER_CHANNELS)
430-
.map(|info| (*pubkey, info.is_tor_only(), info.channels.len()))
430+
.map(|info| (peer, info.is_tor_only(), info.channels.len()))
431431
)
432432
// Exclude Tor-only nodes when the recipient is announced.
433433
.filter(|(_, is_tor_only, _)| !(*is_tor_only && is_recipient_announced))
@@ -439,11 +439,8 @@ where
439439
});
440440

441441
let paths = peer_info.into_iter()
442-
.map(|(node_id, _, _)| vec![ForwardNode { node_id, short_channel_id: None }])
443-
.map(|intermediate_nodes| {
444-
BlindedPath::new_for_message(
445-
&intermediate_nodes, recipient, &*self.entropy_source, secp_ctx
446-
)
442+
.map(|(peer, _, _)| {
443+
BlindedPath::new_for_message(&[peer], recipient, &*self.entropy_source, secp_ctx)
447444
})
448445
.take(MAX_PATHS)
449446
.collect::<Result<Vec<_>, _>>();

lightning/src/routing/router.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
use bitcoin::secp256k1::{PublicKey, Secp256k1, self};
1313

1414
use crate::blinded_path::{BlindedHop, BlindedPath, Direction, IntroductionNode};
15-
use crate::blinded_path::payment::{ForwardNode, ForwardTlvs, PaymentConstraints, PaymentRelay, ReceiveTlvs};
15+
use crate::blinded_path::message;
16+
use crate::blinded_path::payment::{ForwardTlvs, PaymentConstraints, PaymentRelay, ReceiveTlvs, self};
1617
use crate::ln::{PaymentHash, PaymentPreimage};
1718
use crate::ln::channelmanager::{ChannelDetails, PaymentId, MIN_FINAL_CLTV_EXPIRY_DELTA, RecipientOnionFields};
1819
use crate::ln::features::{BlindedHopFeatures, Bolt11InvoiceFeatures, Bolt12InvoiceFeatures, ChannelFeatures, NodeFeatures};
@@ -122,7 +123,7 @@ impl<G: Deref<Target = NetworkGraph<L>> + Clone, L: Deref, ES: Deref, S: Deref,
122123
max_cltv_expiry: tlvs.payment_constraints.max_cltv_expiry + cltv_expiry_delta,
123124
htlc_minimum_msat: details.inbound_htlc_minimum_msat.unwrap_or(0),
124125
};
125-
Some(ForwardNode {
126+
Some(payment::ForwardNode {
126127
tlvs: ForwardTlvs {
127128
short_channel_id,
128129
payment_relay,
@@ -171,7 +172,7 @@ impl< G: Deref<Target = NetworkGraph<L>> + Clone, L: Deref, ES: Deref, S: Deref,
171172
fn create_blinded_paths<
172173
T: secp256k1::Signing + secp256k1::Verification
173174
> (
174-
&self, recipient: PublicKey, peers: Vec<PublicKey>, secp_ctx: &Secp256k1<T>,
175+
&self, recipient: PublicKey, peers: Vec<message::ForwardNode>, secp_ctx: &Secp256k1<T>,
175176
) -> Result<Vec<BlindedPath>, ()> {
176177
self.message_router.create_blinded_paths(recipient, peers, secp_ctx)
177178
}

lightning/src/util/test_utils.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// licenses.
99

1010
use crate::blinded_path::BlindedPath;
11+
use crate::blinded_path::message::ForwardNode;
1112
use crate::blinded_path::payment::ReceiveTlvs;
1213
use crate::chain;
1314
use crate::chain::WatchedOutput;
@@ -246,7 +247,7 @@ impl<'a> MessageRouter for TestRouter<'a> {
246247
fn create_blinded_paths<
247248
T: secp256k1::Signing + secp256k1::Verification
248249
>(
249-
&self, recipient: PublicKey, peers: Vec<PublicKey>, secp_ctx: &Secp256k1<T>,
250+
&self, recipient: PublicKey, peers: Vec<ForwardNode>, secp_ctx: &Secp256k1<T>,
250251
) -> Result<Vec<BlindedPath>, ()> {
251252
self.router.create_blinded_paths(recipient, peers, secp_ctx)
252253
}
@@ -281,7 +282,7 @@ impl<'a> MessageRouter for TestMessageRouter<'a> {
281282
}
282283

283284
fn create_blinded_paths<T: secp256k1::Signing + secp256k1::Verification>(
284-
&self, recipient: PublicKey, peers: Vec<PublicKey>, secp_ctx: &Secp256k1<T>,
285+
&self, recipient: PublicKey, peers: Vec<ForwardNode>, secp_ctx: &Secp256k1<T>,
285286
) -> Result<Vec<BlindedPath>, ()> {
286287
self.inner.create_blinded_paths(recipient, peers, secp_ctx)
287288
}

0 commit comments

Comments
 (0)