From: Valentine Wallace Date: Sun, 24 Dec 2023 21:47:49 +0000 (-0500) Subject: Use correct min/max htlc in test util for constructing blinded pay params. X-Git-Tag: v0.0.123-beta~45^2~5 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=e8c85bd82bb16c4990be6d1b8006b0021894f677;p=rust-lightning 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. --- 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() }