Skip to content

Commit a899e9a

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 78c4d59 commit a899e9a

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
@@ -32,7 +32,9 @@ pub fn get_blinded_route_parameters(
3232
keys_manager: &test_utils::TestKeysInterface
3333
) -> RouteParameters {
3434
let mut intermediate_nodes = Vec::new();
35-
for (node_id, chan_upd) in node_ids.iter().zip(channel_upds) {
35+
let mut intro_node_min_htlc_opt = Some(intro_node_min_htlc);
36+
let mut intro_node_max_htlc_opt = Some(intro_node_max_htlc);
37+
for (idx, (node_id, chan_upd)) in node_ids.iter().zip(channel_upds).enumerate() {
3638
intermediate_nodes.push(ForwardNode {
3739
node_id: *node_id,
3840
tlvs: ForwardTlvs {
@@ -44,24 +46,28 @@ pub fn get_blinded_route_parameters(
4446
},
4547
payment_constraints: PaymentConstraints {
4648
max_cltv_expiry: u32::max_value(),
47-
htlc_minimum_msat: chan_upd.htlc_minimum_msat,
49+
htlc_minimum_msat: intro_node_min_htlc_opt.take()
50+
.unwrap_or_else(|| channel_upds[idx - 1].htlc_minimum_msat),
4851
},
4952
features: BlindedHopFeatures::empty(),
5053
},
51-
htlc_maximum_msat: chan_upd.htlc_maximum_msat,
54+
htlc_maximum_msat: intro_node_max_htlc_opt.take()
55+
.unwrap_or_else(|| channel_upds[idx - 1].htlc_maximum_msat),
5256
});
5357
}
5458
let payee_tlvs = ReceiveTlvs {
5559
payment_secret,
5660
payment_constraints: PaymentConstraints {
5761
max_cltv_expiry: u32::max_value(),
58-
htlc_minimum_msat: channel_upds.last().unwrap().htlc_minimum_msat,
62+
htlc_minimum_msat:
63+
intro_node_min_htlc_opt.unwrap_or_else(|| channel_upds.last().unwrap().htlc_minimum_msat),
5964
},
6065
};
6166
let mut secp_ctx = Secp256k1::new();
6267
let blinded_path = BlindedPath::new_for_payment(
6368
&intermediate_nodes[..], *node_ids.last().unwrap(), payee_tlvs,
64-
channel_upds.last().unwrap().htlc_maximum_msat, keys_manager, &secp_ctx
69+
intro_node_max_htlc_opt.unwrap_or_else(|| channel_upds.last().unwrap().htlc_maximum_msat),
70+
keys_manager, &secp_ctx
6571
).unwrap();
6672

6773
RouteParameters::from_payment_params_and_value(

0 commit comments

Comments
 (0)