Skip to content

Commit bfa9434

Browse files
committed
Allow the introduction_node to be set for the BlindedPaymentPath
1 parent 16307f6 commit bfa9434

File tree

4 files changed

+14
-13
lines changed

4 files changed

+14
-13
lines changed

lightning/src/blinded_path/payment.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ impl BlindedPaymentPath {
104104
let htlc_maximum_msat = u64::max_value();
105105
Self::new(
106106
&[],
107+
None,
107108
payee_node_id,
108109
payee_tlvs,
109110
htlc_maximum_msat,
@@ -121,16 +122,16 @@ impl BlindedPaymentPath {
121122
/// * any unknown features are required in the provided [`ForwardTlvs`]
122123
// TODO: make all payloads the same size with padding + add dummy hops
123124
pub fn new<ES: Deref, T: secp256k1::Signing + secp256k1::Verification>(
124-
intermediate_nodes: &[PaymentForwardNode], payee_node_id: PublicKey,
125+
intermediate_nodes: &[PaymentForwardNode], introduction_node: Option<IntroductionNode>, payee_node_id: PublicKey,
125126
payee_tlvs: ReceiveTlvs, htlc_maximum_msat: u64, min_final_cltv_expiry_delta: u16,
126127
entropy_source: ES, secp_ctx: &Secp256k1<T>,
127128
) -> Result<Self, ()>
128129
where
129130
ES::Target: EntropySource,
130131
{
131-
let introduction_node = IntroductionNode::NodeId(
132-
intermediate_nodes.first().map_or(payee_node_id, |n| n.node_id),
133-
);
132+
let introduction_node = introduction_node.unwrap_or_else(|| IntroductionNode::NodeId(
133+
intermediate_nodes.first().map_or(payee_node_id, |n| n.node_id)
134+
));
134135
let blinding_secret_bytes = entropy_source.get_secure_random_bytes();
135136
let blinding_secret =
136137
SecretKey::from_slice(&blinding_secret_bytes[..]).expect("RNG is busted");

lightning/src/ln/blinded_payment_tests.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ pub fn blinded_payment_path(
8888

8989
let mut secp_ctx = Secp256k1::new();
9090
BlindedPaymentPath::new(
91-
&intermediate_nodes[..], *node_ids.last().unwrap(), payee_tlvs,
91+
&intermediate_nodes[..], None, *node_ids.last().unwrap(), payee_tlvs,
9292
intro_node_max_htlc_opt.unwrap_or_else(|| channel_upds.last().unwrap().htlc_maximum_msat),
9393
TEST_FINAL_CLTV as u16, keys_manager, &secp_ctx
9494
).unwrap()
@@ -173,7 +173,7 @@ fn do_one_hop_blinded_path(success: bool) {
173173

174174
let mut secp_ctx = Secp256k1::new();
175175
let blinded_path = BlindedPaymentPath::new(
176-
&[], nodes[1].node.get_our_node_id(), payee_tlvs, u64::MAX, TEST_FINAL_CLTV as u16,
176+
&[], None, nodes[1].node.get_our_node_id(), payee_tlvs, u64::MAX, TEST_FINAL_CLTV as u16,
177177
&chanmon_cfgs[1].keys_manager, &secp_ctx
178178
).unwrap();
179179

@@ -225,7 +225,7 @@ fn mpp_to_one_hop_blinded_path() {
225225
let expanded_key = chanmon_cfgs[3].keys_manager.get_inbound_payment_key();
226226
let payee_tlvs = payee_tlvs.authenticate(nonce, &expanded_key);
227227
let blinded_path = BlindedPaymentPath::new(
228-
&[], nodes[3].node.get_our_node_id(), payee_tlvs, u64::MAX, TEST_FINAL_CLTV as u16,
228+
&[], None, nodes[3].node.get_our_node_id(), payee_tlvs, u64::MAX, TEST_FINAL_CLTV as u16,
229229
&chanmon_cfgs[3].keys_manager, &secp_ctx
230230
).unwrap();
231231

@@ -1328,7 +1328,7 @@ fn custom_tlvs_to_blinded_path() {
13281328
let payee_tlvs = payee_tlvs.authenticate(nonce, &expanded_key);
13291329
let mut secp_ctx = Secp256k1::new();
13301330
let blinded_path = BlindedPaymentPath::new(
1331-
&[], nodes[1].node.get_our_node_id(), payee_tlvs, u64::MAX, TEST_FINAL_CLTV as u16,
1331+
&[], None, nodes[1].node.get_our_node_id(), payee_tlvs, u64::MAX, TEST_FINAL_CLTV as u16,
13321332
&chanmon_cfgs[1].keys_manager, &secp_ctx
13331333
).unwrap();
13341334

@@ -1383,7 +1383,7 @@ fn fails_receive_tlvs_authentication() {
13831383

13841384
let mut secp_ctx = Secp256k1::new();
13851385
let blinded_path = BlindedPaymentPath::new(
1386-
&[], nodes[1].node.get_our_node_id(), payee_tlvs, u64::MAX, TEST_FINAL_CLTV as u16,
1386+
&[], None, nodes[1].node.get_our_node_id(), payee_tlvs, u64::MAX, TEST_FINAL_CLTV as u16,
13871387
&chanmon_cfgs[1].keys_manager, &secp_ctx
13881388
).unwrap();
13891389

@@ -1414,7 +1414,7 @@ fn fails_receive_tlvs_authentication() {
14141414

14151415
let mut secp_ctx = Secp256k1::new();
14161416
let blinded_path = BlindedPaymentPath::new(
1417-
&[], nodes[1].node.get_our_node_id(), payee_tlvs, u64::MAX, TEST_FINAL_CLTV as u16,
1417+
&[], None, nodes[1].node.get_our_node_id(), payee_tlvs, u64::MAX, TEST_FINAL_CLTV as u16,
14181418
&chanmon_cfgs[1].keys_manager, &secp_ctx
14191419
).unwrap();
14201420

lightning/src/ln/max_payment_path_len_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ fn one_hop_blinded_path_with_custom_tlv() {
177177
let payee_tlvs = payee_tlvs.authenticate(nonce, &expanded_key);
178178
let mut secp_ctx = Secp256k1::new();
179179
let blinded_path = BlindedPaymentPath::new(
180-
&[], nodes[2].node.get_our_node_id(), payee_tlvs, u64::MAX, TEST_FINAL_CLTV as u16,
180+
&[], None, nodes[2].node.get_our_node_id(), payee_tlvs, u64::MAX, TEST_FINAL_CLTV as u16,
181181
&chanmon_cfgs[2].keys_manager, &secp_ctx
182182
).unwrap();
183183
let route_params = RouteParameters::from_payment_params_and_value(

lightning/src/routing/router.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ impl<G: Deref<Target = NetworkGraph<L>>, L: Deref, ES: Deref, S: Deref, SP: Size
164164
})
165165
.map(|forward_node| {
166166
BlindedPaymentPath::new(
167-
&[forward_node], recipient, tlvs.clone(), u64::MAX, MIN_FINAL_CLTV_EXPIRY_DELTA,
167+
&[forward_node], None, recipient, tlvs.clone(), u64::MAX, MIN_FINAL_CLTV_EXPIRY_DELTA,
168168
&*self.entropy_source, secp_ctx
169169
)
170170
})
@@ -176,7 +176,7 @@ impl<G: Deref<Target = NetworkGraph<L>>, L: Deref, ES: Deref, S: Deref, SP: Size
176176
_ => {
177177
if network_graph.nodes().contains_key(&NodeId::from_pubkey(&recipient)) {
178178
BlindedPaymentPath::new(
179-
&[], recipient, tlvs, u64::MAX, MIN_FINAL_CLTV_EXPIRY_DELTA, &*self.entropy_source,
179+
&[], None, recipient, tlvs, u64::MAX, MIN_FINAL_CLTV_EXPIRY_DELTA, &*self.entropy_source,
180180
secp_ctx
181181
).map(|path| vec![path])
182182
} else {

0 commit comments

Comments
 (0)