From e8c85bd82bb16c4990be6d1b8006b0021894f677 Mon Sep 17 00:00:00 2001 From: Valentine Wallace Date: Sun, 24 Dec 2023 16:47:49 -0500 Subject: [PATCH] Use correct min/max htlc in test util for constructing blinded pay params. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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. --- lightning/src/ln/blinded_payment_tests.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/lightning/src/ln/blinded_payment_tests.rs b/lightning/src/ln/blinded_payment_tests.rs index 816e01707..2a93cadd7 100644 --- a/lightning/src/ln/blinded_payment_tests.rs +++ b/lightning/src/ln/blinded_payment_tests.rs @@ -33,7 +33,9 @@ fn blinded_payment_path( keys_manager: &test_utils::TestKeysInterface ) -> (BlindedPayInfo, BlindedPath) { let mut intermediate_nodes = Vec::new(); - for (node_id, chan_upd) in node_ids.iter().zip(channel_upds) { + let mut intro_node_min_htlc_opt = Some(intro_node_min_htlc); + let mut intro_node_max_htlc_opt = Some(intro_node_max_htlc); + for (idx, (node_id, chan_upd)) in node_ids.iter().zip(channel_upds).enumerate() { intermediate_nodes.push(ForwardNode { node_id: *node_id, tlvs: ForwardTlvs { @@ -45,24 +47,28 @@ fn blinded_payment_path( }, payment_constraints: PaymentConstraints { max_cltv_expiry: u32::max_value(), - htlc_minimum_msat: chan_upd.htlc_minimum_msat, + htlc_minimum_msat: intro_node_min_htlc_opt.take() + .unwrap_or_else(|| channel_upds[idx - 1].htlc_minimum_msat), }, features: BlindedHopFeatures::empty(), }, - htlc_maximum_msat: chan_upd.htlc_maximum_msat, + htlc_maximum_msat: intro_node_max_htlc_opt.take() + .unwrap_or_else(|| channel_upds[idx - 1].htlc_maximum_msat), }); } let payee_tlvs = ReceiveTlvs { payment_secret, payment_constraints: PaymentConstraints { max_cltv_expiry: u32::max_value(), - htlc_minimum_msat: channel_upds.last().unwrap().htlc_minimum_msat, + htlc_minimum_msat: + intro_node_min_htlc_opt.unwrap_or_else(|| channel_upds.last().unwrap().htlc_minimum_msat), }, }; let mut secp_ctx = Secp256k1::new(); BlindedPath::new_for_payment( &intermediate_nodes[..], *node_ids.last().unwrap(), payee_tlvs, - channel_upds.last().unwrap().htlc_maximum_msat, TEST_FINAL_CLTV as u16, keys_manager, &secp_ctx + intro_node_max_htlc_opt.unwrap_or_else(|| channel_upds.last().unwrap().htlc_maximum_msat), + TEST_FINAL_CLTV as u16, keys_manager, &secp_ctx ).unwrap() } -- 2.39.5