Skip to content

Commit e8c85bd

Browse files
Use correct min/max htlc in test util for constructing blinded pay params.
In testing, we use channel updates to construct blinded paths and the {Forward,Receive}Tlvs encoded within. Given a blinded path from node A > B > C, we currently use channel_update_A->B to construct the payment constraints for A’s blinded payload. This is incorrect for setting A's PaymentConstraints::htlc_minimum_msat, because channel_update_A->B contains the minimum value that *B* will accept, and we want the constraints to contain the min value that *A* will accept. This never caused test failures before because min/max htlc values were always identical in both channel directions. Therefore, set A’s htlc min/max values to the min/max that A will accept.
1 parent bde5a65 commit e8c85bd

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

lightning/src/ln/blinded_payment_tests.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ fn blinded_payment_path(
3333
keys_manager: &test_utils::TestKeysInterface
3434
) -> (BlindedPayInfo, BlindedPath) {
3535
let mut intermediate_nodes = Vec::new();
36-
for (node_id, chan_upd) in node_ids.iter().zip(channel_upds) {
36+
let mut intro_node_min_htlc_opt = Some(intro_node_min_htlc);
37+
let mut intro_node_max_htlc_opt = Some(intro_node_max_htlc);
38+
for (idx, (node_id, chan_upd)) in node_ids.iter().zip(channel_upds).enumerate() {
3739
intermediate_nodes.push(ForwardNode {
3840
node_id: *node_id,
3941
tlvs: ForwardTlvs {
@@ -45,24 +47,28 @@ fn blinded_payment_path(
4547
},
4648
payment_constraints: PaymentConstraints {
4749
max_cltv_expiry: u32::max_value(),
48-
htlc_minimum_msat: chan_upd.htlc_minimum_msat,
50+
htlc_minimum_msat: intro_node_min_htlc_opt.take()
51+
.unwrap_or_else(|| channel_upds[idx - 1].htlc_minimum_msat),
4952
},
5053
features: BlindedHopFeatures::empty(),
5154
},
52-
htlc_maximum_msat: chan_upd.htlc_maximum_msat,
55+
htlc_maximum_msat: intro_node_max_htlc_opt.take()
56+
.unwrap_or_else(|| channel_upds[idx - 1].htlc_maximum_msat),
5357
});
5458
}
5559
let payee_tlvs = ReceiveTlvs {
5660
payment_secret,
5761
payment_constraints: PaymentConstraints {
5862
max_cltv_expiry: u32::max_value(),
59-
htlc_minimum_msat: channel_upds.last().unwrap().htlc_minimum_msat,
63+
htlc_minimum_msat:
64+
intro_node_min_htlc_opt.unwrap_or_else(|| channel_upds.last().unwrap().htlc_minimum_msat),
6065
},
6166
};
6267
let mut secp_ctx = Secp256k1::new();
6368
BlindedPath::new_for_payment(
6469
&intermediate_nodes[..], *node_ids.last().unwrap(), payee_tlvs,
65-
channel_upds.last().unwrap().htlc_maximum_msat, TEST_FINAL_CLTV as u16, keys_manager, &secp_ctx
70+
intro_node_max_htlc_opt.unwrap_or_else(|| channel_upds.last().unwrap().htlc_maximum_msat),
71+
TEST_FINAL_CLTV as u16, keys_manager, &secp_ctx
6672
).unwrap()
6773
}
6874

0 commit comments

Comments
 (0)