Skip to content

Commit 6f0190d

Browse files
Reduce visibility of BlindedPaymentPath inner path.
Works towards making the inner BlindedPath struct private to the module.
1 parent c563c15 commit 6f0190d

File tree

8 files changed

+115
-171
lines changed

8 files changed

+115
-171
lines changed

fuzz/src/router.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use bitcoin::script::Builder;
1313
use bitcoin::transaction::TxOut;
1414

1515
use lightning::blinded_path::payment::BlindedPaymentPath;
16-
use lightning::blinded_path::{BlindedHop, BlindedPath, IntroductionNode};
16+
use lightning::blinded_path::BlindedHop;
1717
use lightning::chain::transaction::OutPoint;
1818
use lightning::ln::channel_state::{ChannelCounterparty, ChannelDetails, ChannelShutdownState};
1919
use lightning::ln::channelmanager;
@@ -403,11 +403,7 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
403403
}
404404
(
405405
payinfo,
406-
BlindedPaymentPath(BlindedPath {
407-
introduction_node: IntroductionNode::NodeId(hop.src_node_id),
408-
blinding_point: dummy_pk,
409-
blinded_hops,
410-
}),
406+
BlindedPaymentPath::from_raw(hop.src_node_id, dummy_pk, blinded_hops),
411407
)
412408
})
413409
.collect();

lightning/src/blinded_path/payment.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use crate::prelude::*;
3737
/// A [`BlindedPath`] to be used for sending or receiving a payment, hiding the identity of the
3838
/// recipient.
3939
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
40-
pub struct BlindedPaymentPath(pub BlindedPath);
40+
pub struct BlindedPaymentPath(pub(super) BlindedPath);
4141

4242
impl Writeable for BlindedPaymentPath {
4343
fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
@@ -120,6 +120,22 @@ impl BlindedPaymentPath {
120120
pub fn blinded_hops(&self) -> &[BlindedHop] {
121121
&self.0.blinded_hops
122122
}
123+
124+
#[cfg(any(test, fuzzing))]
125+
pub fn from_raw(
126+
introduction_node_id: PublicKey, blinding_point: PublicKey, blinded_hops: Vec<BlindedHop>
127+
) -> Self {
128+
Self(BlindedPath {
129+
introduction_node: IntroductionNode::NodeId(introduction_node_id),
130+
blinding_point,
131+
blinded_hops,
132+
})
133+
}
134+
135+
#[cfg(test)]
136+
pub fn clear_blinded_hops(&mut self) {
137+
self.0.blinded_hops.clear()
138+
}
123139
}
124140

125141
/// An intermediate node, its outbound channel, and relay parameters.

lightning/src/ln/max_payment_path_len_tests.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
//! and/or blinded paths present.
1212
1313
use bitcoin::secp256k1::{Secp256k1, PublicKey};
14-
use crate::blinded_path::{BlindedHop, BlindedPath, IntroductionNode};
14+
use crate::blinded_path::BlindedHop;
1515
use crate::blinded_path::payment::{BlindedPaymentPath, PaymentConstraints, PaymentContext, ReceiveTlvs};
1616
use crate::events::{Event, MessageSendEventsProvider};
1717
use crate::ln::PaymentSecret;
@@ -182,8 +182,8 @@ fn one_hop_blinded_path_with_custom_tlv() {
182182
sender_intended_htlc_amt_msat: MIN_FINAL_VALUE_ESTIMATE_WITH_OVERPAY,
183183
total_msat: MIN_FINAL_VALUE_ESTIMATE_WITH_OVERPAY,
184184
cltv_expiry_height: nodes[0].best_block_info().1 + DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA,
185-
encrypted_tlvs: &blinded_path.1.0.blinded_hops[0].encrypted_payload,
186-
intro_node_blinding_point: Some(blinded_path.1.0.blinding_point),
185+
encrypted_tlvs: &blinded_path.1.blinded_hops()[0].encrypted_payload,
186+
intro_node_blinding_point: Some(blinded_path.1.blinding_point()),
187187
keysend_preimage: None,
188188
custom_tlvs: &Vec::new()
189189
}.serialized_length();
@@ -363,10 +363,9 @@ fn bolt12_invoice_too_large_blinded_paths() {
363363
htlc_maximum_msat: 42_000_000,
364364
features: BlindedHopFeatures::empty(),
365365
},
366-
BlindedPaymentPath(BlindedPath {
367-
introduction_node: IntroductionNode::NodeId(PublicKey::from_slice(&[2; 33]).unwrap()),
368-
blinding_point: PublicKey::from_slice(&[2; 33]).unwrap(),
369-
blinded_hops: vec![
366+
BlindedPaymentPath::from_raw(
367+
PublicKey::from_slice(&[2; 33]).unwrap(), PublicKey::from_slice(&[2; 33]).unwrap(),
368+
vec![
370369
BlindedHop {
371370
blinded_node_id: PublicKey::from_slice(&[2; 33]).unwrap(),
372371
encrypted_payload: vec![42; 1300],
@@ -375,8 +374,8 @@ fn bolt12_invoice_too_large_blinded_paths() {
375374
blinded_node_id: PublicKey::from_slice(&[2; 33]).unwrap(),
376375
encrypted_payload: vec![42; 1300],
377376
},
378-
],
379-
})
377+
]
378+
)
380379
)]);
381380

382381
let offer = nodes[1].node.create_offer_builder(None).unwrap().build().unwrap();

lightning/src/ln/offers_tests.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@ fn creates_and_pays_for_offer_using_two_hop_blinded_path() {
585585
assert_ne!(invoice.signing_pubkey(), alice_id);
586586
assert!(!invoice.payment_paths().is_empty());
587587
for (_, path) in invoice.payment_paths() {
588-
assert_eq!(path.0.introduction_node, IntroductionNode::NodeId(bob_id));
588+
assert_eq!(path.introduction_node(), &IntroductionNode::NodeId(bob_id));
589589
}
590590

591591
route_bolt12_payment(david, &[charlie, bob, alice], &invoice);
@@ -666,7 +666,7 @@ fn creates_and_pays_for_refund_using_two_hop_blinded_path() {
666666
assert_ne!(invoice.signing_pubkey(), alice_id);
667667
assert!(!invoice.payment_paths().is_empty());
668668
for (_, path) in invoice.payment_paths() {
669-
assert_eq!(path.0.introduction_node, IntroductionNode::NodeId(bob_id));
669+
assert_eq!(path.introduction_node(), &IntroductionNode::NodeId(bob_id));
670670
}
671671

672672
route_bolt12_payment(david, &[charlie, bob, alice], &invoice);
@@ -731,7 +731,7 @@ fn creates_and_pays_for_offer_using_one_hop_blinded_path() {
731731
assert_ne!(invoice.signing_pubkey(), alice_id);
732732
assert!(!invoice.payment_paths().is_empty());
733733
for (_, path) in invoice.payment_paths() {
734-
assert_eq!(path.0.introduction_node, IntroductionNode::NodeId(alice_id));
734+
assert_eq!(path.introduction_node(), &IntroductionNode::NodeId(alice_id));
735735
}
736736

737737
route_bolt12_payment(bob, &[alice], &invoice);
@@ -786,7 +786,7 @@ fn creates_and_pays_for_refund_using_one_hop_blinded_path() {
786786
assert_ne!(invoice.signing_pubkey(), alice_id);
787787
assert!(!invoice.payment_paths().is_empty());
788788
for (_, path) in invoice.payment_paths() {
789-
assert_eq!(path.0.introduction_node, IntroductionNode::NodeId(alice_id));
789+
assert_eq!(path.introduction_node(), &IntroductionNode::NodeId(alice_id));
790790
}
791791

792792
route_bolt12_payment(bob, &[alice], &invoice);
@@ -1110,7 +1110,7 @@ fn pays_bolt12_invoice_asynchronously() {
11101110
assert_ne!(invoice.signing_pubkey(), alice_id);
11111111
assert!(!invoice.payment_paths().is_empty());
11121112
for (_, path) in invoice.payment_paths() {
1113-
assert_eq!(path.0.introduction_node, IntroductionNode::NodeId(alice_id));
1113+
assert_eq!(path.introduction_node(), &IntroductionNode::NodeId(alice_id));
11141114
}
11151115

11161116
assert!(bob.node.send_payment_for_bolt12_invoice(&invoice, context.as_ref()).is_ok());
@@ -1194,7 +1194,7 @@ fn creates_offer_with_blinded_path_using_unannounced_introduction_node() {
11941194
assert_ne!(invoice.signing_pubkey(), alice_id);
11951195
assert!(!invoice.payment_paths().is_empty());
11961196
for (_, path) in invoice.payment_paths() {
1197-
assert_eq!(path.0.introduction_node, IntroductionNode::NodeId(bob_id));
1197+
assert_eq!(path.introduction_node(), &IntroductionNode::NodeId(bob_id));
11981198
}
11991199

12001200
route_bolt12_payment(bob, &[alice], &invoice);
@@ -1244,7 +1244,7 @@ fn creates_refund_with_blinded_path_using_unannounced_introduction_node() {
12441244
assert_ne!(invoice.signing_pubkey(), alice_id);
12451245
assert!(!invoice.payment_paths().is_empty());
12461246
for (_, path) in invoice.payment_paths() {
1247-
assert_eq!(path.0.introduction_node, IntroductionNode::NodeId(bob_id));
1247+
assert_eq!(path.introduction_node(), &IntroductionNode::NodeId(bob_id));
12481248
}
12491249
}
12501250

lightning/src/ln/onion_utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,8 +340,8 @@ pub(crate) fn set_max_path_length(
340340
.map(|(_, path)| path)
341341
.max_by_key(|path| path.serialized_length())
342342
.map(|largest_path| BlindedTailHopIter {
343-
hops: largest_path.0.blinded_hops.iter(),
344-
blinding_point: largest_path.0.blinding_point,
343+
hops: largest_path.blinded_hops().iter(),
344+
blinding_point: largest_path.blinding_point(),
345345
final_value_msat: final_value_msat_with_overpay_buffer,
346346
excess_final_cltv_expiry_delta: 0,
347347
});

lightning/src/ln/outbound_payment.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -835,10 +835,10 @@ impl OutboundPayments {
835835
// Advance any blinded path where the introduction node is our node.
836836
if let Ok(our_node_id) = node_signer.get_node_id(Recipient::Node) {
837837
for (_, path) in payment_params.payee.blinded_route_hints_mut().iter_mut() {
838-
let introduction_node_id = match path.0.introduction_node {
839-
IntroductionNode::NodeId(pubkey) => pubkey,
838+
let introduction_node_id = match path.introduction_node() {
839+
IntroductionNode::NodeId(pubkey) => *pubkey,
840840
IntroductionNode::DirectedShortChannelId(direction, scid) => {
841-
match node_id_lookup.next_node_id(scid) {
841+
match node_id_lookup.next_node_id(*scid) {
842842
Some(next_node_id) => *direction.select_pubkey(&our_node_id, &next_node_id),
843843
None => continue,
844844
}

lightning/src/offers/test_utils.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use bitcoin::secp256k1::{Keypair, PublicKey, Secp256k1, SecretKey};
1313
use bitcoin::secp256k1::schnorr::Signature;
1414

1515
use core::time::Duration;
16-
use crate::blinded_path::{BlindedHop, BlindedPath, IntroductionNode};
16+
use crate::blinded_path::BlindedHop;
1717
use crate::blinded_path::payment::BlindedPaymentPath;
1818
use crate::sign::EntropySource;
1919
use crate::ln::types::PaymentHash;
@@ -69,22 +69,20 @@ pub(super) fn privkey(byte: u8) -> SecretKey {
6969

7070
pub(crate) fn payment_paths() -> Vec<(BlindedPayInfo, BlindedPaymentPath)> {
7171
let paths = vec![
72-
BlindedPaymentPath(BlindedPath {
73-
introduction_node: IntroductionNode::NodeId(pubkey(40)),
74-
blinding_point: pubkey(41),
75-
blinded_hops: vec![
72+
BlindedPaymentPath::from_raw(
73+
pubkey(40), pubkey(41),
74+
vec![
7675
BlindedHop { blinded_node_id: pubkey(43), encrypted_payload: vec![0; 43] },
7776
BlindedHop { blinded_node_id: pubkey(44), encrypted_payload: vec![0; 44] },
78-
],
79-
}),
80-
BlindedPaymentPath(BlindedPath {
81-
introduction_node: IntroductionNode::NodeId(pubkey(40)),
82-
blinding_point: pubkey(41),
83-
blinded_hops: vec![
77+
]
78+
),
79+
BlindedPaymentPath::from_raw(
80+
pubkey(40), pubkey(41),
81+
vec![
8482
BlindedHop { blinded_node_id: pubkey(45), encrypted_payload: vec![0; 45] },
8583
BlindedHop { blinded_node_id: pubkey(46), encrypted_payload: vec![0; 46] },
86-
],
87-
}),
84+
]
85+
),
8886
];
8987

9088
let payinfo = vec![

0 commit comments

Comments
 (0)