Skip to content

Commit d00942b

Browse files
Reduce visibility of BlindedPaymentPath inner path.
Works towards making the inner BlindedPath struct pub(super). Also exposes accessors for inner blinded path fields to BlindedPaymentPath.
1 parent 863eb54 commit d00942b

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) -> &Vec<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
@@ -572,7 +572,7 @@ fn creates_and_pays_for_offer_using_two_hop_blinded_path() {
572572
assert_ne!(invoice.signing_pubkey(), alice_id);
573573
assert!(!invoice.payment_paths().is_empty());
574574
for (_, path) in invoice.payment_paths() {
575-
assert_eq!(path.0.introduction_node, IntroductionNode::NodeId(bob_id));
575+
assert_eq!(path.introduction_node(), &IntroductionNode::NodeId(bob_id));
576576
}
577577

578578
route_bolt12_payment(david, &[charlie, bob, alice], &invoice);
@@ -653,7 +653,7 @@ fn creates_and_pays_for_refund_using_two_hop_blinded_path() {
653653
assert_ne!(invoice.signing_pubkey(), alice_id);
654654
assert!(!invoice.payment_paths().is_empty());
655655
for (_, path) in invoice.payment_paths() {
656-
assert_eq!(path.0.introduction_node, IntroductionNode::NodeId(bob_id));
656+
assert_eq!(path.introduction_node(), &IntroductionNode::NodeId(bob_id));
657657
}
658658

659659
route_bolt12_payment(david, &[charlie, bob, alice], &invoice);
@@ -718,7 +718,7 @@ fn creates_and_pays_for_offer_using_one_hop_blinded_path() {
718718
assert_ne!(invoice.signing_pubkey(), alice_id);
719719
assert!(!invoice.payment_paths().is_empty());
720720
for (_, path) in invoice.payment_paths() {
721-
assert_eq!(path.0.introduction_node, IntroductionNode::NodeId(alice_id));
721+
assert_eq!(path.introduction_node(), &IntroductionNode::NodeId(alice_id));
722722
}
723723

724724
route_bolt12_payment(bob, &[alice], &invoice);
@@ -773,7 +773,7 @@ fn creates_and_pays_for_refund_using_one_hop_blinded_path() {
773773
assert_ne!(invoice.signing_pubkey(), alice_id);
774774
assert!(!invoice.payment_paths().is_empty());
775775
for (_, path) in invoice.payment_paths() {
776-
assert_eq!(path.0.introduction_node, IntroductionNode::NodeId(alice_id));
776+
assert_eq!(path.introduction_node(), &IntroductionNode::NodeId(alice_id));
777777
}
778778

779779
route_bolt12_payment(bob, &[alice], &invoice);
@@ -1097,7 +1097,7 @@ fn pays_bolt12_invoice_asynchronously() {
10971097
assert_ne!(invoice.signing_pubkey(), alice_id);
10981098
assert!(!invoice.payment_paths().is_empty());
10991099
for (_, path) in invoice.payment_paths() {
1100-
assert_eq!(path.0.introduction_node, IntroductionNode::NodeId(alice_id));
1100+
assert_eq!(path.introduction_node(), &IntroductionNode::NodeId(alice_id));
11011101
}
11021102

11031103
assert!(bob.node.send_payment_for_bolt12_invoice(&invoice, context.as_ref()).is_ok());
@@ -1181,7 +1181,7 @@ fn creates_offer_with_blinded_path_using_unannounced_introduction_node() {
11811181
assert_ne!(invoice.signing_pubkey(), alice_id);
11821182
assert!(!invoice.payment_paths().is_empty());
11831183
for (_, path) in invoice.payment_paths() {
1184-
assert_eq!(path.0.introduction_node, IntroductionNode::NodeId(bob_id));
1184+
assert_eq!(path.introduction_node(), &IntroductionNode::NodeId(bob_id));
11851185
}
11861186

11871187
route_bolt12_payment(bob, &[alice], &invoice);
@@ -1231,7 +1231,7 @@ fn creates_refund_with_blinded_path_using_unannounced_introduction_node() {
12311231
assert_ne!(invoice.signing_pubkey(), alice_id);
12321232
assert!(!invoice.payment_paths().is_empty());
12331233
for (_, path) in invoice.payment_paths() {
1234-
assert_eq!(path.0.introduction_node, IntroductionNode::NodeId(bob_id));
1234+
assert_eq!(path.introduction_node(), &IntroductionNode::NodeId(bob_id));
12351235
}
12361236
}
12371237

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
@@ -824,10 +824,10 @@ impl OutboundPayments {
824824
// Advance any blinded path where the introduction node is our node.
825825
if let Ok(our_node_id) = node_signer.get_node_id(Recipient::Node) {
826826
for (_, path) in payment_params.payee.blinded_route_hints_mut().iter_mut() {
827-
let introduction_node_id = match path.0.introduction_node {
828-
IntroductionNode::NodeId(pubkey) => pubkey,
827+
let introduction_node_id = match path.introduction_node() {
828+
IntroductionNode::NodeId(pubkey) => *pubkey,
829829
IntroductionNode::DirectedShortChannelId(direction, scid) => {
830-
match node_id_lookup.next_node_id(scid) {
830+
match node_id_lookup.next_node_id(*scid) {
831831
Some(next_node_id) => *direction.select_pubkey(&our_node_id, &next_node_id),
832832
None => continue,
833833
}

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)