]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Send keysend preimage through OutboundPayment::send_payment_internal
authorAlec Chen <alecchendev@gmail.com>
Sat, 5 Aug 2023 00:20:46 +0000 (19:20 -0500)
committerAlec Chen <alecchendev@gmail.com>
Sat, 5 Aug 2023 03:05:13 +0000 (22:05 -0500)
Fixes a bug where we wouldn't use the provided keysend preimage when
piping through OutboundPayment::pay_route_internal.

Also simplifies and refactors existing keysend tests to make sure this
gets hit.

lightning/src/ln/outbound_payment.rs
lightning/src/ln/payment_tests.rs

index 50dcdd546083a326e6f4b14340e0d815a621af88..24d683e5fdc687563a7b1a84064777239e3a6fbd 100644 (file)
@@ -684,7 +684,7 @@ impl OutboundPayments {
                        Some(route_params.payment_params.clone()), entropy_source, best_block_height)
                        .map_err(|_| RetryableSendFailure::DuplicatePayment)?;
 
-               let res = self.pay_route_internal(&route, payment_hash, recipient_onion, None, payment_id, None,
+               let res = self.pay_route_internal(&route, payment_hash, recipient_onion, keysend_preimage, payment_id, None,
                        onion_session_privs, node_signer, best_block_height, &send_payment_along_path);
                log_info!(logger, "Result sending payment with id {}: {:?}", log_bytes!(payment_id.0), res);
                if let Err(e) = res {
index e686a480e0bc71905779031ab40bdfaea9cc482e..7d639611df2873950af4f2bd0b5dfa7b7f7123c8 100644 (file)
@@ -237,63 +237,52 @@ fn mpp_receive_timeout() {
 }
 
 #[test]
-fn test_keysend_payments_to_public_node() {
-       let chanmon_cfgs = create_chanmon_cfgs(2);
-       let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
-       let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
-       let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
-
-       let _chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 100000, 10001);
-       let network_graph = nodes[0].network_graph.clone();
-       let payer_pubkey = nodes[0].node.get_our_node_id();
-       let payee_pubkey = nodes[1].node.get_our_node_id();
-       let route_params = RouteParameters {
-               payment_params: PaymentParameters::for_keysend(payee_pubkey, 40, false),
-               final_value_msat: 10000,
-       };
-       let scorer = test_utils::TestScorer::new();
-       let random_seed_bytes = chanmon_cfgs[1].keys_manager.get_secure_random_bytes();
-       let route = find_route(&payer_pubkey, &route_params, &network_graph, None, nodes[0].logger, &scorer, &(), &random_seed_bytes).unwrap();
-
-       let test_preimage = PaymentPreimage([42; 32]);
-       let payment_hash = nodes[0].node.send_spontaneous_payment(&route, Some(test_preimage),
-               RecipientOnionFields::spontaneous_empty(), PaymentId(test_preimage.0)).unwrap();
-       check_added_monitors!(nodes[0], 1);
-       let mut events = nodes[0].node.get_and_clear_pending_msg_events();
-       assert_eq!(events.len(), 1);
-       let event = events.pop().unwrap();
-       let path = vec![&nodes[1]];
-       pass_along_path(&nodes[0], &path, 10000, payment_hash, None, event, true, Some(test_preimage));
-       claim_payment(&nodes[0], &path, test_preimage);
+fn test_keysend_payments() {
+       do_test_keysend_payments(false, false);
+       do_test_keysend_payments(false, true);
+       do_test_keysend_payments(true, false);
+       do_test_keysend_payments(true, true);
 }
 
-#[test]
-fn test_keysend_payments_to_private_node() {
+fn do_test_keysend_payments(public_node: bool, with_retry: bool) {
        let chanmon_cfgs = create_chanmon_cfgs(2);
        let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
        let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
        let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
 
+       if public_node {
+               create_announced_chan_between_nodes(&nodes, 0, 1);
+       } else {
+               create_chan_between_nodes(&nodes[0], &nodes[1]);
+       }
        let payer_pubkey = nodes[0].node.get_our_node_id();
        let payee_pubkey = nodes[1].node.get_our_node_id();
-
-       let _chan = create_chan_between_nodes(&nodes[0], &nodes[1]);
        let route_params = RouteParameters {
                payment_params: PaymentParameters::for_keysend(payee_pubkey, 40, false),
                final_value_msat: 10000,
        };
+
        let network_graph = nodes[0].network_graph.clone();
-       let first_hops = nodes[0].node.list_usable_channels();
+       let channels = nodes[0].node.list_usable_channels();
+       let first_hops = channels.iter().collect::<Vec<_>>();
+       let first_hops = if public_node { None } else { Some(first_hops.as_slice()) };
+
        let scorer = test_utils::TestScorer::new();
        let random_seed_bytes = chanmon_cfgs[1].keys_manager.get_secure_random_bytes();
        let route = find_route(
-               &payer_pubkey, &route_params, &network_graph, Some(&first_hops.iter().collect::<Vec<_>>()),
+               &payer_pubkey, &route_params, &network_graph, first_hops,
                nodes[0].logger, &scorer, &(), &random_seed_bytes
        ).unwrap();
 
        let test_preimage = PaymentPreimage([42; 32]);
-       let payment_hash = nodes[0].node.send_spontaneous_payment(&route, Some(test_preimage),
-               RecipientOnionFields::spontaneous_empty(), PaymentId(test_preimage.0)).unwrap();
+       let payment_hash = if with_retry {
+               nodes[0].node.send_spontaneous_payment_with_retry(Some(test_preimage),
+                       RecipientOnionFields::spontaneous_empty(), PaymentId(test_preimage.0),
+                       route_params, Retry::Attempts(1)).unwrap()
+       } else {
+               nodes[0].node.send_spontaneous_payment(&route, Some(test_preimage),
+                       RecipientOnionFields::spontaneous_empty(), PaymentId(test_preimage.0)).unwrap()
+       };
        check_added_monitors!(nodes[0], 1);
        let mut events = nodes[0].node.get_and_clear_pending_msg_events();
        assert_eq!(events.len(), 1);